@@ -104,20 +104,26 @@ class ChewieState extends State<Chewie> {
104
104
) {
105
105
return Scaffold (
106
106
resizeToAvoidBottomInset: false ,
107
- body: GestureDetector (
108
- onVerticalDragEnd: (DragEndDetails details) {
109
- // A positive dy indicates a downward swipe. Use a threshold to avoid accidental triggers.
110
- final double dy = details.primaryVelocity ?? 0 ;
111
- if (dy > 300 ) {
112
- widget.controller.exitFullScreen ();
113
- }
114
- },
115
- child: Container (
116
- alignment: Alignment .center,
117
- color: Colors .black,
118
- child: controllerProvider,
119
- ),
120
- ),
107
+ body: widget.controller.swipeToExitFullscreen
108
+ ? GestureDetector (
109
+ onVerticalDragEnd: (DragEndDetails details) {
110
+ // A positive dy indicates a downward swipe. Use a threshold to avoid accidental triggers.
111
+ final double dy = details.primaryVelocity ?? 0 ;
112
+ if (dy > widget.controller.swipeThreshold) {
113
+ widget.controller.exitFullScreen ();
114
+ }
115
+ },
116
+ child: Container (
117
+ alignment: Alignment .center,
118
+ color: Colors .black,
119
+ child: controllerProvider,
120
+ ),
121
+ )
122
+ : Container (
123
+ alignment: Alignment .center,
124
+ color: Colors .black,
125
+ child: controllerProvider,
126
+ ),
121
127
);
122
128
}
123
129
@@ -344,6 +350,8 @@ class ChewieController extends ChangeNotifier {
344
350
this .hideControlsTimer = defaultHideControlsTimer,
345
351
this .controlsSafeAreaMinimum = EdgeInsets .zero,
346
352
this .pauseOnBackgroundTap = false ,
353
+ this .swipeToExitFullscreen = true ,
354
+ this .swipeThreshold = 300 ,
347
355
}) : assert (
348
356
playbackSpeeds.every ((speed) => speed > 0 ),
349
357
'The playbackSpeeds values must all be greater than 0' ,
@@ -403,6 +411,8 @@ class ChewieController extends ChangeNotifier {
403
411
)?
404
412
routePageBuilder,
405
413
bool ? pauseOnBackgroundTap,
414
+ bool ? swipeToExitFullscreen,
415
+ double ? swipeThreshold,
406
416
}) {
407
417
return ChewieController (
408
418
draggableProgressBar: draggableProgressBar ?? this .draggableProgressBar,
@@ -467,6 +477,9 @@ class ChewieController extends ChangeNotifier {
467
477
progressIndicatorDelay:
468
478
progressIndicatorDelay ?? this .progressIndicatorDelay,
469
479
pauseOnBackgroundTap: pauseOnBackgroundTap ?? this .pauseOnBackgroundTap,
480
+ swipeToExitFullscreen:
481
+ swipeToExitFullscreen ?? this .swipeToExitFullscreen,
482
+ swipeThreshold: swipeThreshold ?? this .swipeThreshold,
470
483
);
471
484
}
472
485
@@ -639,6 +652,13 @@ class ChewieController extends ChangeNotifier {
639
652
/// Defines if the player should pause when the background is tapped
640
653
final bool pauseOnBackgroundTap;
641
654
655
+ /// Defines if the player allows swipe to exit fullscreen
656
+ final bool swipeToExitFullscreen;
657
+
658
+ /// Defines the minimum velocity threshold for swipe to exit fullscreen gesture
659
+ /// The velocity is measured in pixels per second
660
+ final double swipeThreshold;
661
+
642
662
static ChewieController of (BuildContext context) {
643
663
final chewieControllerProvider = context
644
664
.dependOnInheritedWidgetOfExactType <ChewieControllerProvider >()! ;
0 commit comments