diff --git a/app/lib/widget/video_viewer.dart b/app/lib/widget/video_viewer.dart index 59117d90..096732da 100644 --- a/app/lib/widget/video_viewer.dart +++ b/app/lib/widget/video_viewer.dart @@ -59,12 +59,14 @@ class VideoViewer extends StatefulWidget { class _VideoViewerState extends State with DisposableManagerMixin { @override - initState() { + void initState() { super.initState(); _getVideoUrl().then((url) { - setState(() { - _initController(url); - }); + if (mounted) { + setState(() { + _initController(url); + }); + } }).onError((e, stacktrace) { _log.shout("[initState] Failed while _getVideoUrl", e, stacktrace); SnackBarManager().showSnackBar(SnackBar( @@ -75,6 +77,12 @@ class _VideoViewerState extends State }); } + @override + void dispose() { + _controllerValue?.dispose(); + super.dispose(); + } + @override initDisposables() { return [ @@ -100,15 +108,9 @@ class _VideoViewerState extends State ); } - @override - dispose() { - super.dispose(); - _controller.dispose(); - } - Future _initController(String url) async { try { - _controller = VideoPlayerController.network( + _controllerValue = VideoPlayerController.network( url, httpHeaders: { "Authorization": AuthUtil.fromAccount(widget.account).toHeaderValue(), @@ -293,9 +295,11 @@ class _VideoViewerState extends State } } + VideoPlayerController get _controller => _controllerValue!; + final _key = GlobalKey(); bool _isControllerInitialized = false; - late VideoPlayerController _controller; + VideoPlayerController? _controllerValue; var _isFinished = false; }