Unverified Commit b46d7904 authored by Sigurd Meldgaard's avatar Sigurd Meldgaard Committed by GitHub

Add spinner to loading video (#13330)

* Add spinner to loading video
parent ffb24eda
...@@ -30,7 +30,7 @@ class VideoCard extends StatelessWidget { ...@@ -30,7 +30,7 @@ class VideoCard extends StatelessWidget {
aspectRatio: 3 / 2, aspectRatio: 3 / 2,
child: new Hero( child: new Hero(
tag: controller, tag: controller,
child: new VideoPlayer(controller), child: new VideoPlayerLoading(controller),
), ),
), ),
), ),
...@@ -97,6 +97,50 @@ class VideoCard extends StatelessWidget { ...@@ -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<VideoPlayerLoading> {
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: <Widget>[
new VideoPlayer(widget.controller),
const Center(child: const CircularProgressIndicator()),
],
fit: StackFit.expand,
);
}
}
class VideoPlayPause extends StatefulWidget { class VideoPlayPause extends StatefulWidget {
final VideoPlayerController controller; final VideoPlayerController controller;
...@@ -132,9 +176,12 @@ class _VideoPlayPauseState extends State<VideoPlayPause> { ...@@ -132,9 +176,12 @@ class _VideoPlayPauseState extends State<VideoPlayPause> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final List<Widget> children = <Widget>[ return new Stack(
alignment: Alignment.bottomCenter,
fit: StackFit.expand,
children: <Widget>[
new GestureDetector( new GestureDetector(
child: new VideoPlayer(controller), child: new VideoPlayerLoading(controller),
onTap: () { onTap: () {
if (!controller.value.initialized) { if (!controller.value.initialized) {
return; return;
...@@ -153,16 +200,7 @@ class _VideoPlayPauseState extends State<VideoPlayPause> { ...@@ -153,16 +200,7 @@ class _VideoPlayPauseState extends State<VideoPlayPause> {
}, },
), ),
new Center(child: imageFadeAnimation), new Center(child: imageFadeAnimation),
]; ],
if (!controller.value.initialized) {
children.add(new Container());
}
return new Stack(
alignment: Alignment.bottomCenter,
fit: StackFit.passthrough,
children: children,
); );
} }
} }
......
...@@ -8,7 +8,7 @@ dependencies: ...@@ -8,7 +8,7 @@ dependencies:
string_scanner: 1.0.2 string_scanner: 1.0.2
url_launcher: 0.4.2+5 url_launcher: 0.4.2+5
cupertino_icons: 0.1.1 cupertino_icons: 0.1.1
video_player: 0.0.5 video_player: 0.0.6
# Also update dev/benchmarks/complex_layout/pubspec.yaml # Also update dev/benchmarks/complex_layout/pubspec.yaml
flutter_gallery_assets: flutter_gallery_assets:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment