Trying to achieve YouTube-like full-screen video handling with Flutter - flutter

I'm trying to achieve something similar to this post, but here I'm also gonna talk about my attempt.
In short, I just wanna achieve the same full-screen functionality as YouTube.
When the user tapped on the full-screen icon, the video becomes full screen in landscape and it stays like that even though the user keeps holding the device vertically. The video will be automatically minimized if the device is rotated to portrait after the device had been rotated to landscape.
If the user does not lock the device rotation, the video will be put in full screen when the device is tilted to landscape and will be minimized when tilted back to portrait.
If the video is being played on full screen, tapping the full-screen icon will minimize the video and also put the app orientation to portrait regardless of the way user holds the device.
Here is my attempt at achieving the above behaviors with Flutter:
App's preferred orientation is not set (allows both landscape and portrait)
Watch for orientation change. Programmatically put the video on full screen if the current orientation is landscape and minimize the video in portrait.
Set the app's preferred orientation to landscape when the full-screen icon is tapped. (The video will be on full screen)
To allow users to physically rotate the device back to portrait set preferred orientations to both portrait and landscape after 1 second.
// Tapped on full-screen icon
SystemChrome.setPreferredOrientations(
<DeviceOrientation>[
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
],
);
await Future.delayed(
const Duration(milliseconds: 1000),
);
// Allow rotating physically back to portrait
SystemChrome.setPreferredOrientations(
<DeviceOrientation>[
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
DeviceOrientation.portraitDown,
DeviceOrientation.portraitUp,
],
);
The code above works as expected on an iOS device as iPhone does not immediately change its orientation back to portrait when the preferred orientation is set back to both landscape and portrait while the device is being held vertically.
The problem here is with Android devices.
After 1 second, if the device is still being held vertically, the app orientation will change to portrait which is not the desired behavior.
Is there any practical way to achieve my desired behaviors? I strongly believe that what I have done is not even close to how YouTube does it.

Related

Half black screen is visible when device orientation changes from portrait to landscape

I'm using InfiniteCollectionView class, Once I change the device Orientation from portrait to landscape, half the screen looks black for a second
I have also tried the viewWillTransition function by doing the same but I didn't get success

Swift How to get orientation when orientation is locked

the orientation in the app is locked. However, on the news detail page, I need to start the video full screen while in landscape. How can I find out the landscape status?

App is confusing between application orientation

I applied SystemChrome.setPreferredOrientations([DeviceOrientation.portraitDown]); to my second page of application when I click on button to go new screen where I set portrait orientation my application firstly show in portrait orientation and change its orientation for 1 second to landscape and after 1 second it set back to portrait. I am calling SystemChrome.setPreferredOrientations([DeviceOrientation.portraitDown]); in build function for each class.
Do not change orientation on different screen. where you need to change the orientation just put your screen into rotated box and rotate it to change orientation by quarterTurns: 2,. Rotatedbox

How to switch the live screen camera icons from portrait to landscape mode in iPhone?

I created a custom camera overlay for the live screen camera view and have imported my own custom icons for the camera, flash and flip buttons. Everything looks good in portrait mode, but when I switch the live camera screen to landscape mode, the orientation of the camera stays in portrait mode and shows this in console,
"Error: CGAffineTransformInvert: singular matrix"
I tried using the auto resizing mask, also have tried setting two different frames for the icons in both portrait and landscape mode in didRotateFromInterfaceOrientation method. But none of these are working.
My question is, will the landscape orientation support only the default iPhone camera overlay view or will it also support the custom overlayview.
Here are the screenshots indicating the behaviour of the icons repositioning each other when switched from portrait to landscape mode. I want exactly like this in my custom overlay view.
Edit:
I've made the live screen of my custom camera overlay to change by using the UIDevice Orientation method. But right now, the frame is not resizing when i try to switch from the portrait to landscape mode. So, i just want the entire frame to resize in landscape mode. Also, in this piece of code, if i try to change the value of CAMERA_TRANSFORM_Y,
#define CAMERA_TRANSFORM_X 1
#define CAMERA_TRANSFORM_Y 1.234
self.picker.cameraViewTransform = CGAffineTransformScale(self.picker.cameraViewTransform, CAMERA_TRANSFORM_X, CAMERA_TRANSFORM_Y);
the size of the overlay view reduces both from the top and bottom margin. But, more size gets reduced from the bottom than from the top margin. I want the overlay size to change uniformly both from the top and from the bottom margin.
This is my sample code,
Sample project

Portrait Orientation is losing touch input

I'm making a universal apps with auto rotation, and I'm only using landscape left and right. When I rotate the iPhone to the portrait down position, I can see what looks like a window underneath the app rotating and I no longer get touch events.
In all the shouldAutoRotate functions I'm making sure only return true for landscape, and the info.plist only allows landscape left and right.
Sounds like your view is not correctly resizing after an orientation change. Easy way to check this is to set the background color to something non-white.