From 305e44cff7b56e899c8885da10df0b1f1bdad632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Carvalho?= Date: Mon, 7 Mar 2022 15:21:58 +0000 Subject: [PATCH] Allow video zooming with InteractiveViewer widget. --- lib/src/chewie_player.dart | 10 +++++++++ lib/src/player_with_controls.dart | 34 +++++++++++++++++++------------ 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/lib/src/chewie_player.dart b/lib/src/chewie_player.dart index 1b5c83100..bffb4d2e9 100644 --- a/lib/src/chewie_player.dart +++ b/lib/src/chewie_player.dart @@ -262,6 +262,8 @@ class ChewieController extends ChangeNotifier { this.optionsBuilder, this.additionalOptions, this.showControls = true, + this.zoomAndPan = false, + this.maxScale = 2.5, this.subtitle, this.subtitleBuilder, this.customControls, @@ -303,6 +305,8 @@ class ChewieController extends ChangeNotifier { Future Function(BuildContext, List)? optionsBuilder, List Function(BuildContext)? additionalOptions, bool? showControls, + bool? zoomAndPan, + double? maxScale, Subtitles? subtitle, Widget Function(BuildContext, dynamic)? subtitleBuilder, Widget? customControls, @@ -426,6 +430,12 @@ class ChewieController extends ChangeNotifier { /// Whether or not to show the controls at all final bool showControls; + /// Whether or not to allow zooming and panning + final bool zoomAndPan; + + /// Max scale when zooming + final double maxScale; + /// Defines customised controls. Check [MaterialControls] or /// [CupertinoControls] for reference. final Widget? customControls; diff --git a/lib/src/player_with_controls.dart b/lib/src/player_with_controls.dart index 5b683147d..f3c0120a7 100644 --- a/lib/src/player_with_controls.dart +++ b/lib/src/player_with_controls.dart @@ -37,11 +37,16 @@ class PlayerWithControls extends StatelessWidget { children: [ if (chewieController.placeholder != null) chewieController.placeholder!, - Center( - child: AspectRatio( - aspectRatio: chewieController.aspectRatio ?? - chewieController.videoPlayerController.value.aspectRatio, - child: VideoPlayer(chewieController.videoPlayerController), + InteractiveViewer( + maxScale: chewieController.maxScale, + panEnabled: chewieController.zoomAndPan, + scaleEnabled: chewieController.zoomAndPan, + child: Center( + child: AspectRatio( + aspectRatio: chewieController.aspectRatio ?? + chewieController.videoPlayerController.value.aspectRatio, + child: VideoPlayer(chewieController.videoPlayerController), + ), ), ), if (chewieController.overlay != null) chewieController.overlay!, @@ -52,14 +57,17 @@ class PlayerWithControls extends StatelessWidget { PlayerNotifier notifier, Widget? widget, ) => - AnimatedOpacity( - opacity: notifier.hideStuff ? 0.0 : 0.8, - duration: const Duration( - milliseconds: 250, - ), - child: Container( - decoration: const BoxDecoration(color: Colors.black54), - child: Container(), + Visibility( + visible: !notifier.hideStuff, + child: AnimatedOpacity( + opacity: notifier.hideStuff ? 0.0 : 0.8, + duration: const Duration( + milliseconds: 250, + ), + child: Container( + decoration: const BoxDecoration(color: Colors.black54), + child: Container(), + ), ), ), ),