diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b190258..d6049b84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -85,3 +85,7 @@ Updated wakelock to wakelock_plus: ^1.1.4 Updated video_player to latest version video_player: ^2.8.6 Fix - Formatting + +## 0.9.0 + +Fix - Registering the context and initializes the FlickManager after the widget is built to ensure the context is available. diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 0eea6153..efad4db8 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -26,6 +26,7 @@ dependencies: flick_video_player: path: "../" video_player: ^2.8.6 + wakelock_web: ^0.4.0 provider: ^6.0.1 # The following adds the Cupertino Icons font to your application. diff --git a/lib/src/controls/flick_video_with_controls.dart b/lib/src/controls/flick_video_with_controls.dart index 15df5973..55952b09 100644 --- a/lib/src/controls/flick_video_with_controls.dart +++ b/lib/src/controls/flick_video_with_controls.dart @@ -1,5 +1,5 @@ -import 'package:flutter/material.dart'; import 'package:flick_video_player/flick_video_player.dart'; +import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:video_player/video_player.dart'; @@ -40,6 +40,7 @@ class FlickVideoWithControls extends StatefulWidget { color: Colors.white, fontSize: 12, ), + this.watermark, }) : super(key: key); /// Create custom controls or use any of these [FlickPortraitControls], [FlickLandscapeControls] @@ -84,6 +85,11 @@ class FlickVideoWithControls extends StatefulWidget { /// If false videoPlayerController will not be updated. final bool willVideoPlayerControllerChange; + /// A widget to always display over the video. + /// + /// Use [Positioned], [Align] or [Center] to position the watermark. + final Widget? watermark; + get videoPlayerController => null; @override @@ -120,17 +126,20 @@ class _FlickVideoWithControlsState extends State { child: Stack( children: [ Center( - child: FlickNativeVideoPlayer( - videoPlayerController: _videoPlayerController, - fit: widget.videoFit, - aspectRatioWhenLoading: widget.aspectRatioWhenLoading, - ), + child: _videoPlayerController != null + ? FlickNativeVideoPlayer( + videoPlayerController: _videoPlayerController!, + fit: widget.videoFit, + aspectRatioWhenLoading: widget.aspectRatioWhenLoading, + ) + : widget.playerLoadingFallback, ), + if (widget.watermark != null) widget.watermark!, Positioned.fill( child: Stack( alignment: Alignment.bottomCenter, children: [ - _videoPlayerController!.closedCaptionFile != null && + _videoPlayerController?.closedCaptionFile != null && _showVideoCaption ? Positioned( bottom: 5, @@ -148,7 +157,9 @@ class _FlickVideoWithControlsState extends State { widget.playerLoadingFallback, if (_videoPlayerController?.value.hasError == true) widget.playerErrorFallback, - widget.controls ?? Container(), + if (_videoPlayerController != null && + _videoPlayerController!.value.isInitialized) + widget.controls ?? Container(), ], ), ), diff --git a/lib/src/flick_video_player.dart b/lib/src/flick_video_player.dart index 94385c5b..55bbb973 100644 --- a/lib/src/flick_video_player.dart +++ b/lib/src/flick_video_player.dart @@ -78,9 +78,19 @@ class _FlickVideoPlayerState extends State @override void initState() { + super.initState(); + WidgetsBinding.instance.addObserver(this); flickManager = widget.flickManager; - flickManager.registerContext(context); + + // Register context and perform initialization in post-frame callback + WidgetsBinding.instance.addPostFrameCallback((_) { + flickManager.registerContext(context); + _initializeFlickManager(); + }); + } + + void _initializeFlickManager() { flickManager.flickControlManager!.addListener(listener); _setSystemUIOverlays(); _setPreferredOrientation(); @@ -94,8 +104,6 @@ class _FlickVideoPlayerState extends State .listen(_webFullscreenListener); document.documentElement?.onKeyDown.listen(_webKeyListener); } - - super.initState(); } @override diff --git a/lib/src/manager/video_manager.dart b/lib/src/manager/video_manager.dart index 7879c02d..c140809e 100644 --- a/lib/src/manager/video_manager.dart +++ b/lib/src/manager/video_manager.dart @@ -141,7 +141,9 @@ class FlickVideoManager extends ChangeNotifier { .seekTo(Duration(hours: 0, minutes: 0, seconds: 0, milliseconds: 0)); } - if (autoPlay && ModalRoute.of(_flickManager._context!)!.isCurrent) { + if (autoPlay && + _flickManager._context != null && + ModalRoute.of(_flickManager._context!)?.isCurrent == true) { //Chrome's autoplay policies are simple: //Muted autoplay is always allowed. if (kIsWeb) _flickManager.flickControlManager!.mute(); diff --git a/pubspec.yaml b/pubspec.yaml index b87c8249..bac7b7bd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: Flick Video Player is a video player for flutter. The video_player repository: https://github.com/GeekyAnts/flick-video-player homepage: https://github.com/GeekyAnts/flick-video-player -version: 0.8.0 +version: 0.9.0 environment: sdk: ">=3.2.3 <4.0.0"