diff --git a/lib/src/chewie_player.dart b/lib/src/chewie_player.dart index 7ffa295b2..084db79c4 100644 --- a/lib/src/chewie_player.dart +++ b/lib/src/chewie_player.dart @@ -104,11 +104,26 @@ class ChewieState extends State { ) { return Scaffold( resizeToAvoidBottomInset: false, - body: Container( - alignment: Alignment.center, - color: Colors.black, - child: controllerProvider, - ), + body: widget.controller.swipeToExitFullscreen + ? GestureDetector( + onVerticalDragEnd: (DragEndDetails details) { + // A positive dy indicates a downward swipe. Use a threshold to avoid accidental triggers. + final double dy = details.primaryVelocity ?? 0; + if (dy > widget.controller.swipeThreshold) { + widget.controller.exitFullScreen(); + } + }, + child: Container( + alignment: Alignment.center, + color: Colors.black, + child: controllerProvider, + ), + ) + : Container( + alignment: Alignment.center, + color: Colors.black, + child: controllerProvider, + ), ); } @@ -335,6 +350,8 @@ class ChewieController extends ChangeNotifier { this.hideControlsTimer = defaultHideControlsTimer, this.controlsSafeAreaMinimum = EdgeInsets.zero, this.pauseOnBackgroundTap = false, + this.swipeToExitFullscreen = true, + this.swipeThreshold = 300, }) : assert( playbackSpeeds.every((speed) => speed > 0), 'The playbackSpeeds values must all be greater than 0', @@ -394,6 +411,8 @@ class ChewieController extends ChangeNotifier { )? routePageBuilder, bool? pauseOnBackgroundTap, + bool? swipeToExitFullscreen, + double? swipeThreshold, }) { return ChewieController( draggableProgressBar: draggableProgressBar ?? this.draggableProgressBar, @@ -458,6 +477,9 @@ class ChewieController extends ChangeNotifier { progressIndicatorDelay: progressIndicatorDelay ?? this.progressIndicatorDelay, pauseOnBackgroundTap: pauseOnBackgroundTap ?? this.pauseOnBackgroundTap, + swipeToExitFullscreen: + swipeToExitFullscreen ?? this.swipeToExitFullscreen, + swipeThreshold: swipeThreshold ?? this.swipeThreshold, ); } @@ -630,6 +652,13 @@ class ChewieController extends ChangeNotifier { /// Defines if the player should pause when the background is tapped final bool pauseOnBackgroundTap; + /// Defines if the player allows swipe to exit fullscreen + final bool swipeToExitFullscreen; + + /// Defines the minimum velocity threshold for swipe to exit fullscreen gesture + /// The velocity is measured in pixels per second + final double swipeThreshold; + static ChewieController of(BuildContext context) { final chewieControllerProvider = context .dependOnInheritedWidgetOfExactType()!;