I create the video screen, and when the device rotates, the video player also rotates. I have used the youtube player flutter library with auto-rotation enabled. When the device rotates from portrait to landscape, the video player rotates accordingly. However, when the device rotates from landscape to portrait, the rotation does not occur automatically, although it works manually. The code below is used in the build widget.
// Auto rotation Setup
if (isAutoRotation) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
} else {
if (isFullScreenClick) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
]);
} else {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
}
}
isFullScreenClick Boolean variable value get from the library fullscreen on that time true and then false.
void _onPlayerStateChange() {
setState(() {
//Value update from the library. isFullScreen or not.
isFullScreenClick = _controller.value.isFullScreen;
});
}
Below code default library method I handle the isAutoRotation flag.
child: YoutubePlayerBuilder(
onEnterFullScreen: () {
setState(() {
isAutoRotation = false;
});
},
onExitFullScreen: () {
setState(() {
// Click on the full screen is AutorotationFlag on.
isAutoRotation = true;
});
//Navigator.pop(context, true);
},