text
stringlengths
1
372
);
// initialize the controller and store the future for later use.
_initializeVideoPlayerFuture = _controller.initialize();
// use the controller to loop the video.
_controller.setLooping(true);
}
@override
void dispose() {
// ensure disposing of the VideoPlayerController to free up resources.
_controller.dispose();
super.dispose();
}
@override
widget build(BuildContext context) {
return scaffold(
appBar: AppBar(
title: const Text('Butterfly video'),
),
// use a FutureBuilder to display a loading spinner while waiting for the
// VideoPlayerController to finish initializing.
body: FutureBuilder(
future: _initializeVideoPlayerFuture,
builder: (context, snapshot) {
if (snapshot.connectionstate == ConnectionState.done) {
// if the VideoPlayerController has finished initialization, use
// the data it provides to limit the aspect ratio of the video.
return AspectRatio(
aspectRatio: _controller.value.aspectRatio,
// use the VideoPlayer widget to display the video.
child: VideoPlayer(_controller),
);
} else {
// if the VideoPlayerController is still initializing, show a
// loading spinner.
return const center(
child: CircularProgressIndicator(),
);
}
},
),
floatingActionButton: FloatingActionButton(
onPressed: () {
// wrap the play or pause in a call to `setstate`. this ensures the
// correct icon is shown.
setState(() {
// if the video is playing, pause it.
if (_controller.value.isplaying) {
_controller.pause();
} else {
// if the video is paused, play it.
_controller.play();
}
});
},
// display the correct icon depending on the state of the player.
child: icon(
_controller.value.isPlaying ? icons.pause : icons.play_arrow,
),
),
);
}
}
<code_end>
<topic_end>
<topic_start>
navigation and routing
flutter provides a complete system for navigating between screens and handling
deep links. small applications without complex deep linking can use
navigator, while apps with specific deep linking and navigation
requirements should also use the router to correctly handle deep links on
android and iOS, and to stay in sync with the address bar when the app is
running on the web.
to configure your android or iOS application to handle deep links, see
deep linking.
<topic_end>
<topic_start>
using the navigator
the navigator widget displays screens as a stack using the correct transition
animations for the target platform. to navigate to a new screen, access the
navigator through the route’s BuildContext and call imperative methods such
as push() or pop():
because navigator keeps a stack of route objects (representing the history
stack), the push() method also takes a route object. the MaterialPageRoute
object is a subclass of route that specifies the transition animations for
material design. for more examples of how to use the navigator, follow the
navigation recipes from the flutter cookbook or visit the navigator API
documentation.
<topic_end>
<topic_start>
using named routes
info note
we don’t recommend using named routes for most applications.
for more information, see the limitations section below.
applications with simple navigation and deep linking requirements can use the
navigator for navigation and the MaterialApp.routes parameter for deep
links:
routes specified here are called named routes. for a complete example, follow
the navigate with named routes recipe from the flutter cookbook.
<topic_end>
<topic_start>