diff --git a/examples/flutter_gallery/lib/demo/video_demo.dart b/examples/flutter_gallery/lib/demo/video_demo.dart index d24e71a180..1fb5a01a1c 100644 --- a/examples/flutter_gallery/lib/demo/video_demo.dart +++ b/examples/flutter_gallery/lib/demo/video_demo.dart @@ -30,7 +30,7 @@ class VideoCard extends StatelessWidget { aspectRatio: 3 / 2, child: new Hero( tag: controller, - child: new VideoPlayer(controller), + child: new VideoPlayerLoading(controller), ), ), ), @@ -97,6 +97,50 @@ class VideoCard extends StatelessWidget { } } +class VideoPlayerLoading extends StatefulWidget { + final VideoPlayerController controller; + + const VideoPlayerLoading(this.controller); + + @override + _VideoPlayerLoadingState createState() => new _VideoPlayerLoadingState(); +} + +class _VideoPlayerLoadingState extends State { + bool _initialized; + + @override + void initState() { + super.initState(); + _initialized = widget.controller.value.initialized; + widget.controller.addListener(() { + if (!mounted) { + return; + } + final bool controllerInitialized = widget.controller.value.initialized; + if (_initialized != controllerInitialized) { + setState(() { + _initialized = controllerInitialized; + }); + } + }); + } + + @override + Widget build(BuildContext context) { + if (_initialized) { + return new VideoPlayer(widget.controller); + } + return new Stack( + children: [ + new VideoPlayer(widget.controller), + const Center(child: const CircularProgressIndicator()), + ], + fit: StackFit.expand, + ); + } +} + class VideoPlayPause extends StatefulWidget { final VideoPlayerController controller; @@ -132,37 +176,31 @@ class _VideoPlayPauseState extends State { @override Widget build(BuildContext context) { - final List children = [ - new GestureDetector( - child: new VideoPlayer(controller), - onTap: () { - if (!controller.value.initialized) { - return; - } - if (controller.value.isPlaying) { - imageFadeAnimation = new FadeAnimation( - child: new Icon(Icons.pause, size: 100.0), - ); - controller.pause(); - } else { - imageFadeAnimation = new FadeAnimation( - child: new Icon(Icons.play_arrow, size: 100.0), - ); - controller.play(); - } - }, - ), - new Center(child: imageFadeAnimation), - ]; - - if (!controller.value.initialized) { - children.add(new Container()); - } - return new Stack( alignment: Alignment.bottomCenter, - fit: StackFit.passthrough, - children: children, + fit: StackFit.expand, + children: [ + new GestureDetector( + child: new VideoPlayerLoading(controller), + onTap: () { + if (!controller.value.initialized) { + return; + } + if (controller.value.isPlaying) { + imageFadeAnimation = new FadeAnimation( + child: new Icon(Icons.pause, size: 100.0), + ); + controller.pause(); + } else { + imageFadeAnimation = new FadeAnimation( + child: new Icon(Icons.play_arrow, size: 100.0), + ); + controller.play(); + } + }, + ), + new Center(child: imageFadeAnimation), + ], ); } } diff --git a/examples/flutter_gallery/pubspec.yaml b/examples/flutter_gallery/pubspec.yaml index 588b13b0d5..ff22482173 100644 --- a/examples/flutter_gallery/pubspec.yaml +++ b/examples/flutter_gallery/pubspec.yaml @@ -8,7 +8,7 @@ dependencies: string_scanner: 1.0.2 url_launcher: 0.4.2+5 cupertino_icons: 0.1.1 - video_player: 0.0.5 + video_player: 0.0.6 # Also update dev/benchmarks/complex_layout/pubspec.yaml flutter_gallery_assets: