@@ -13,13 +13,12 @@ import 'package:provider/provider.dart';
13
13
import 'package:video_player/video_player.dart' ;
14
14
import 'package:wakelock_plus/wakelock_plus.dart' ;
15
15
16
- typedef ChewieRoutePageBuilder =
17
- Widget Function (
18
- BuildContext context,
19
- Animation <double > animation,
20
- Animation <double > secondaryAnimation,
21
- ChewieControllerProvider controllerProvider,
22
- );
16
+ typedef ChewieRoutePageBuilder = Widget Function (
17
+ BuildContext context,
18
+ Animation <double > animation,
19
+ Animation <double > secondaryAnimation,
20
+ ChewieControllerProvider controllerProvider,
21
+ );
23
22
24
23
/// A Video Player with Material and Cupertino skins.
25
24
///
@@ -72,8 +71,7 @@ class ChewieState extends State<Chewie> {
72
71
73
72
Future <void > listener () async {
74
73
if (isControllerFullScreen && ! _isFullScreen) {
75
- _wasPlayingBeforeFullScreen =
76
- widget.controller.videoPlayerController.value.isPlaying;
74
+ _wasPlayingBeforeFullScreen = widget.controller.videoPlayerController.value.isPlaying;
77
75
_resumeAppliedInFullScreen = false ;
78
76
_isFullScreen = isControllerFullScreen;
79
77
await _pushFullScreenWidget (context);
@@ -104,20 +102,26 @@ class ChewieState extends State<Chewie> {
104
102
) {
105
103
return Scaffold (
106
104
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
- ),
105
+ body: widget.controller.swipeToExitFullscreen
106
+ ? GestureDetector (
107
+ onVerticalDragEnd: (DragEndDetails details) {
108
+ // A positive dy indicates a downward swipe. Use a threshold to avoid accidental triggers.
109
+ final double dy = details.primaryVelocity ?? 0 ;
110
+ if (dy > widget.controller.swipeThreshold) {
111
+ widget.controller.exitFullScreen ();
112
+ }
113
+ },
114
+ child: Container (
115
+ alignment: Alignment .center,
116
+ color: Colors .black,
117
+ child: controllerProvider,
118
+ ),
119
+ )
120
+ : Container (
121
+ alignment: Alignment .center,
122
+ color: Colors .black,
123
+ child: controllerProvider,
124
+ ),
121
125
);
122
126
}
123
127
@@ -220,8 +224,7 @@ class ChewieState extends State<Chewie> {
220
224
221
225
void onEnterFullScreen () {
222
226
final videoWidth = widget.controller.videoPlayerController.value.size.width;
223
- final videoHeight =
224
- widget.controller.videoPlayerController.value.size.height;
227
+ final videoHeight = widget.controller.videoPlayerController.value.size.height;
225
228
226
229
SystemChrome .setEnabledSystemUIMode (SystemUiMode .manual, overlays: []);
227
230
@@ -253,13 +256,15 @@ class ChewieState extends State<Chewie> {
253
256
DeviceOrientation .landscapeRight,
254
257
]);
255
258
}
259
+
256
260
/// Video h > w means we force portrait
257
261
else if (isPortraitVideo) {
258
262
SystemChrome .setPreferredOrientations ([
259
263
DeviceOrientation .portraitUp,
260
264
DeviceOrientation .portraitDown,
261
265
]);
262
266
}
267
+
263
268
/// Otherwise if h == w (square video)
264
269
else {
265
270
SystemChrome .setPreferredOrientations (DeviceOrientation .values);
@@ -344,10 +349,12 @@ class ChewieController extends ChangeNotifier {
344
349
this .hideControlsTimer = defaultHideControlsTimer,
345
350
this .controlsSafeAreaMinimum = EdgeInsets .zero,
346
351
this .pauseOnBackgroundTap = false ,
352
+ this .swipeToExitFullscreen = true ,
353
+ this .swipeThreshold = 300 ,
347
354
}) : assert (
348
- playbackSpeeds.every ((speed) => speed > 0 ),
349
- 'The playbackSpeeds values must all be greater than 0' ,
350
- ) {
355
+ playbackSpeeds.every ((speed) => speed > 0 ),
356
+ 'The playbackSpeeds values must all be greater than 0' ,
357
+ ) {
351
358
_initialize ();
352
359
}
353
360
@@ -400,39 +407,32 @@ class ChewieController extends ChangeNotifier {
400
407
Animation <double >,
401
408
Animation <double >,
402
409
ChewieControllerProvider ,
403
- )?
404
- routePageBuilder,
410
+ )? routePageBuilder,
405
411
bool ? pauseOnBackgroundTap,
412
+ bool ? swipeToExitFullscreen,
413
+ double ? swipeThreshold,
406
414
}) {
407
415
return ChewieController (
408
416
draggableProgressBar: draggableProgressBar ?? this .draggableProgressBar,
409
- videoPlayerController:
410
- videoPlayerController ?? this .videoPlayerController,
417
+ videoPlayerController: videoPlayerController ?? this .videoPlayerController,
411
418
optionsTranslation: optionsTranslation ?? this .optionsTranslation,
412
419
aspectRatio: aspectRatio ?? this .aspectRatio,
413
420
autoInitialize: autoInitialize ?? this .autoInitialize,
414
421
autoPlay: autoPlay ?? this .autoPlay,
415
422
startAt: startAt ?? this .startAt,
416
423
looping: looping ?? this .looping,
417
424
fullScreenByDefault: fullScreenByDefault ?? this .fullScreenByDefault,
418
- cupertinoProgressColors:
419
- cupertinoProgressColors ?? this .cupertinoProgressColors,
420
- materialProgressColors:
421
- materialProgressColors ?? this .materialProgressColors,
425
+ cupertinoProgressColors: cupertinoProgressColors ?? this .cupertinoProgressColors,
426
+ materialProgressColors: materialProgressColors ?? this .materialProgressColors,
422
427
zoomAndPan: zoomAndPan ?? this .zoomAndPan,
423
428
maxScale: maxScale ?? this .maxScale,
424
- controlsSafeAreaMinimum:
425
- controlsSafeAreaMinimum ?? this .controlsSafeAreaMinimum,
426
- transformationController:
427
- transformationController ?? this .transformationController,
428
- materialSeekButtonFadeDuration:
429
- materialSeekButtonFadeDuration ?? this .materialSeekButtonFadeDuration,
430
- materialSeekButtonSize:
431
- materialSeekButtonSize ?? this .materialSeekButtonSize,
429
+ controlsSafeAreaMinimum: controlsSafeAreaMinimum ?? this .controlsSafeAreaMinimum,
430
+ transformationController: transformationController ?? this .transformationController,
431
+ materialSeekButtonFadeDuration: materialSeekButtonFadeDuration ?? this .materialSeekButtonFadeDuration,
432
+ materialSeekButtonSize: materialSeekButtonSize ?? this .materialSeekButtonSize,
432
433
placeholder: placeholder ?? this .placeholder,
433
434
overlay: overlay ?? this .overlay,
434
- showControlsOnInitialize:
435
- showControlsOnInitialize ?? this .showControlsOnInitialize,
435
+ showControlsOnInitialize: showControlsOnInitialize ?? this .showControlsOnInitialize,
436
436
showOptions: showOptions ?? this .showOptions,
437
437
optionsBuilder: optionsBuilder ?? this .optionsBuilder,
438
438
additionalOptions: additionalOptions ?? this .additionalOptions,
@@ -447,26 +447,20 @@ class ChewieController extends ChangeNotifier {
447
447
isLive: isLive ?? this .isLive,
448
448
allowFullScreen: allowFullScreen ?? this .allowFullScreen,
449
449
allowMuting: allowMuting ?? this .allowMuting,
450
- allowPlaybackSpeedChanging:
451
- allowPlaybackSpeedChanging ?? this .allowPlaybackSpeedChanging,
450
+ allowPlaybackSpeedChanging: allowPlaybackSpeedChanging ?? this .allowPlaybackSpeedChanging,
452
451
useRootNavigator: useRootNavigator ?? this .useRootNavigator,
453
452
playbackSpeeds: playbackSpeeds ?? this .playbackSpeeds,
454
- systemOverlaysOnEnterFullScreen:
455
- systemOverlaysOnEnterFullScreen ??
456
- this .systemOverlaysOnEnterFullScreen,
453
+ systemOverlaysOnEnterFullScreen: systemOverlaysOnEnterFullScreen ?? this .systemOverlaysOnEnterFullScreen,
457
454
deviceOrientationsOnEnterFullScreen:
458
- deviceOrientationsOnEnterFullScreen ??
459
- this .deviceOrientationsOnEnterFullScreen,
460
- systemOverlaysAfterFullScreen:
461
- systemOverlaysAfterFullScreen ?? this .systemOverlaysAfterFullScreen,
462
- deviceOrientationsAfterFullScreen:
463
- deviceOrientationsAfterFullScreen ??
464
- this .deviceOrientationsAfterFullScreen,
455
+ deviceOrientationsOnEnterFullScreen ?? this .deviceOrientationsOnEnterFullScreen,
456
+ systemOverlaysAfterFullScreen: systemOverlaysAfterFullScreen ?? this .systemOverlaysAfterFullScreen,
457
+ deviceOrientationsAfterFullScreen: deviceOrientationsAfterFullScreen ?? this .deviceOrientationsAfterFullScreen,
465
458
routePageBuilder: routePageBuilder ?? this .routePageBuilder,
466
459
hideControlsTimer: hideControlsTimer ?? this .hideControlsTimer,
467
- progressIndicatorDelay:
468
- progressIndicatorDelay ?? this .progressIndicatorDelay,
460
+ progressIndicatorDelay: progressIndicatorDelay ?? this .progressIndicatorDelay,
469
461
pauseOnBackgroundTap: pauseOnBackgroundTap ?? this .pauseOnBackgroundTap,
462
+ swipeToExitFullscreen: swipeToExitFullscreen ?? this .swipeToExitFullscreen,
463
+ swipeThreshold: swipeThreshold ?? this .swipeThreshold,
470
464
);
471
465
}
472
466
@@ -493,8 +487,7 @@ class ChewieController extends ChangeNotifier {
493
487
final Future <void > Function (
494
488
BuildContext context,
495
489
List <OptionItem > chewieOptions,
496
- )?
497
- optionsBuilder;
490
+ )? optionsBuilder;
498
491
499
492
/// Add your own additional options on top of chewie options
500
493
final List <OptionItem > Function (BuildContext context)? additionalOptions;
@@ -554,8 +547,7 @@ class ChewieController extends ChangeNotifier {
554
547
555
548
/// When the video playback runs into an error, you can build a custom
556
549
/// error message.
557
- final Widget Function (BuildContext context, String errorMessage)?
558
- errorBuilder;
550
+ final Widget Function (BuildContext context, String errorMessage)? errorBuilder;
559
551
560
552
/// When the video is buffering, you can build a custom widget.
561
553
final WidgetBuilder ? bufferingBuilder;
@@ -639,9 +631,15 @@ class ChewieController extends ChangeNotifier {
639
631
/// Defines if the player should pause when the background is tapped
640
632
final bool pauseOnBackgroundTap;
641
633
634
+ /// Defines if the player allows swipe to exit fullscreen
635
+ final bool swipeToExitFullscreen;
636
+
637
+ /// Defines the minimum velocity threshold for swipe to exit fullscreen gesture
638
+ /// The velocity is measured in pixels per second
639
+ final double swipeThreshold;
640
+
642
641
static ChewieController of (BuildContext context) {
643
- final chewieControllerProvider = context
644
- .dependOnInheritedWidgetOfExactType <ChewieControllerProvider >()! ;
642
+ final chewieControllerProvider = context.dependOnInheritedWidgetOfExactType <ChewieControllerProvider >()! ;
645
643
646
644
return chewieControllerProvider.controller;
647
645
}
@@ -655,8 +653,7 @@ class ChewieController extends ChangeNotifier {
655
653
Future <dynamic > _initialize () async {
656
654
await videoPlayerController.setLooping (looping);
657
655
658
- if ((autoInitialize || autoPlay) &&
659
- ! videoPlayerController.value.isInitialized) {
656
+ if ((autoInitialize || autoPlay) && ! videoPlayerController.value.isInitialized) {
660
657
await videoPlayerController.initialize ();
661
658
}
662
659
@@ -739,6 +736,5 @@ class ChewieControllerProvider extends InheritedWidget {
739
736
final ChewieController controller;
740
737
741
738
@override
742
- bool updateShouldNotify (ChewieControllerProvider oldWidget) =>
743
- controller != oldWidget.controller;
739
+ bool updateShouldNotify (ChewieControllerProvider oldWidget) => controller != oldWidget.controller;
744
740
}
0 commit comments