Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions lib/src/chewie_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,26 @@ class ChewieState extends State<Chewie> {
) {
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,
),
);
}

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -394,6 +411,8 @@ class ChewieController extends ChangeNotifier {
)?
routePageBuilder,
bool? pauseOnBackgroundTap,
bool? swipeToExitFullscreen,
double? swipeThreshold,
}) {
return ChewieController(
draggableProgressBar: draggableProgressBar ?? this.draggableProgressBar,
Expand Down Expand Up @@ -458,6 +477,9 @@ class ChewieController extends ChangeNotifier {
progressIndicatorDelay:
progressIndicatorDelay ?? this.progressIndicatorDelay,
pauseOnBackgroundTap: pauseOnBackgroundTap ?? this.pauseOnBackgroundTap,
swipeToExitFullscreen:
swipeToExitFullscreen ?? this.swipeToExitFullscreen,
swipeThreshold: swipeThreshold ?? this.swipeThreshold,
);
}

Expand Down Expand Up @@ -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<ChewieControllerProvider>()!;
Expand Down