-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed orientation issue when exiting full screen mode #813
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,48 +40,41 @@ class Chewie extends StatefulWidget { | |
|
||
class ChewieState extends State<Chewie> { | ||
bool _isFullScreen = false; | ||
|
||
bool get isControllerFullScreen => widget.controller.isFullScreen; | ||
late PlayerNotifier notifier; | ||
late PlayerNotifier notifier; // Define the notifier here | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
widget.controller.addListener(listener); | ||
notifier = PlayerNotifier.init(); | ||
notifier = PlayerNotifier.init(); // Initialize the notifier here | ||
} | ||
|
||
@override | ||
void dispose() { | ||
widget.controller.removeListener(listener); | ||
notifier.dispose(); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
void didUpdateWidget(Chewie oldWidget) { | ||
if (oldWidget.controller != widget.controller) { | ||
widget.controller.addListener(listener); | ||
} | ||
super.didUpdateWidget(oldWidget); | ||
if (_isFullScreen != isControllerFullScreen) { | ||
widget.controller._isFullScreen = _isFullScreen; | ||
} | ||
} | ||
|
||
Future<void> listener() async { | ||
if (isControllerFullScreen && !_isFullScreen) { | ||
_isFullScreen = isControllerFullScreen; | ||
if (widget.controller.isFullScreen && !_isFullScreen) { | ||
_isFullScreen = true; | ||
await _pushFullScreenWidget(context); | ||
} else if (_isFullScreen) { | ||
} else if (!widget.controller.isFullScreen && _isFullScreen) { | ||
_isFullScreen = false; | ||
Navigator.of( | ||
context, | ||
rootNavigator: widget.controller.useRootNavigator, | ||
).pop(); | ||
_isFullScreen = false; | ||
} | ||
} | ||
|
||
// Method to update _isFullScreen when toggling full screen mode | ||
void toggleFullScreen() { | ||
setState(() { | ||
_isFullScreen = !_isFullScreen; | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ChewieControllerProvider( | ||
|
@@ -172,62 +165,32 @@ class ChewieState extends State<Chewie> { | |
if (!widget.controller.allowedScreenSleep) { | ||
WakelockPlus.disable(); | ||
} | ||
|
||
SystemChrome.setEnabledSystemUIMode( | ||
SystemUiMode.manual, | ||
overlays: widget.controller.systemOverlaysAfterFullScreen, | ||
); | ||
SystemChrome.setPreferredOrientations( | ||
widget.controller.deviceOrientationsAfterFullScreen, | ||
); | ||
Comment on lines
-176
to
-182
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Restore these lines. |
||
} | ||
|
||
void onEnterFullScreen() { | ||
final videoWidth = widget.controller.videoPlayerController.value.size.width; | ||
final videoHeight = | ||
widget.controller.videoPlayerController.value.size.height; | ||
|
||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []); | ||
|
||
// if (widget.controller.systemOverlaysOnEnterFullScreen != null) { | ||
// /// Optional user preferred settings | ||
// SystemChrome.setEnabledSystemUIMode( | ||
// SystemUiMode.manual, | ||
// overlays: widget.controller.systemOverlaysOnEnterFullScreen, | ||
// ); | ||
// } else { | ||
// /// Default behavior | ||
// SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: SystemUiOverlay.values); | ||
// } | ||
|
||
if (widget.controller.deviceOrientationsOnEnterFullScreen != null) { | ||
/// Optional user preferred settings | ||
SystemChrome.setPreferredOrientations( | ||
widget.controller.deviceOrientationsOnEnterFullScreen!, | ||
); | ||
} else { | ||
final isLandscapeVideo = videoWidth > videoHeight; | ||
final isPortraitVideo = videoWidth < videoHeight; | ||
|
||
/// Default behavior | ||
/// Video w > h means we force landscape | ||
if (isLandscapeVideo) { | ||
SystemChrome.setPreferredOrientations([ | ||
DeviceOrientation.landscapeLeft, | ||
DeviceOrientation.landscapeRight, | ||
]); | ||
} | ||
|
||
/// Video h > w means we force portrait | ||
else if (isPortraitVideo) { | ||
} else if (isPortraitVideo) { | ||
SystemChrome.setPreferredOrientations([ | ||
DeviceOrientation.portraitUp, | ||
DeviceOrientation.portraitDown, | ||
]); | ||
} | ||
|
||
/// Otherwise if h == w (square video) | ||
else { | ||
} else { | ||
SystemChrome.setPreferredOrientations(DeviceOrientation.values); | ||
} | ||
} | ||
|
@@ -590,6 +553,12 @@ class ChewieController extends ChangeNotifier { | |
void exitFullScreen() { | ||
_isFullScreen = false; | ||
notifyListeners(); | ||
|
||
// Reset preferred orientations to portrait mode | ||
SystemChrome.setPreferredOrientations([ | ||
DeviceOrientation.portraitUp, | ||
DeviceOrientation.portraitDown, | ||
]); | ||
Comment on lines
+558
to
+561
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The controller should not be responsible for setting This should be moved into Also, it should not assume that it will fall back to Portrait. Instead, there's an option in the |
||
} | ||
|
||
void toggleFullScreen() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to remove this, since if you refresh the widget with new properties, then removing this code won't update this
StatefulWidget
with them.