Skip to content

Commit 0974735

Browse files
committed
Make swipe down to exit fullscreen an option
1 parent a4d847b commit 0974735

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

lib/src/chewie_player.dart

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,26 @@ class ChewieState extends State<Chewie> {
104104
) {
105105
return Scaffold(
106106
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+
),
121127
);
122128
}
123129

@@ -344,6 +350,8 @@ class ChewieController extends ChangeNotifier {
344350
this.hideControlsTimer = defaultHideControlsTimer,
345351
this.controlsSafeAreaMinimum = EdgeInsets.zero,
346352
this.pauseOnBackgroundTap = false,
353+
this.swipeToExitFullscreen = true,
354+
this.swipeThreshold = 300,
347355
}) : assert(
348356
playbackSpeeds.every((speed) => speed > 0),
349357
'The playbackSpeeds values must all be greater than 0',
@@ -403,6 +411,8 @@ class ChewieController extends ChangeNotifier {
403411
)?
404412
routePageBuilder,
405413
bool? pauseOnBackgroundTap,
414+
bool? swipeToExitFullscreen,
415+
double? swipeThreshold,
406416
}) {
407417
return ChewieController(
408418
draggableProgressBar: draggableProgressBar ?? this.draggableProgressBar,
@@ -467,6 +477,9 @@ class ChewieController extends ChangeNotifier {
467477
progressIndicatorDelay:
468478
progressIndicatorDelay ?? this.progressIndicatorDelay,
469479
pauseOnBackgroundTap: pauseOnBackgroundTap ?? this.pauseOnBackgroundTap,
480+
swipeToExitFullscreen:
481+
swipeToExitFullscreen ?? this.swipeToExitFullscreen,
482+
swipeThreshold: swipeThreshold ?? this.swipeThreshold,
470483
);
471484
}
472485

@@ -639,6 +652,13 @@ class ChewieController extends ChangeNotifier {
639652
/// Defines if the player should pause when the background is tapped
640653
final bool pauseOnBackgroundTap;
641654

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+
642662
static ChewieController of(BuildContext context) {
643663
final chewieControllerProvider = context
644664
.dependOnInheritedWidgetOfExactType<ChewieControllerProvider>()!;

0 commit comments

Comments
 (0)