0
Follow
2
View

Customize Rotation Behavior For Specific Widgets In Flutter

frrsterdl1 注册会员
6 days ago

I've been having the same issue, the camera preview rotation works weird. What I ended up doing is using this package native orientation which provides the following API: Stream onOrientationChanged(useSensor: false) which will trigger orientation changes even if you lock the screen using: SystemChrome.setPreferredOrientations()

Basically in the init of your component: _orientation = NativeDeviceOrientationCommunicator() .onOrientationChanged(useSensor: true) .listen((event) { switch (event) { case NativeDeviceOrientation.portraitUp: case NativeDeviceOrientation.unknown: _actualOrientation = DeviceOrientation.portraitUp; break; case NativeDeviceOrientation.portraitDown: _actualOrientation = DeviceOrientation.portraitDown; break; case NativeDeviceOrientation.landscapeLeft: _actualOrientation = DeviceOrientation.landscapeLeft; break; case NativeDeviceOrientation.landscapeRight: _actualOrientation = DeviceOrientation.landscapeRight; break; } }); and then use the actual orientation to animate the icons or know the actual orientation of the captured image.

Remember to close the subscription on dispose _orientation.cancel();

About the Author

Question Info

Publish Time
6 days ago
Update Time
6 days ago