Flutter Camera Preview不会随着手机方向旋转 [英] Flutter Camera Preview not rotating with phone orientation
问题描述
我是Dart / Flutter的新手,目前正在使用Flutter 相机插件,但是当手机转为横向模式时,我遇到了CameraPreview的问题。图像保持垂直,并且不会随着手机旋转90度。
I'm new to Dart/Flutter and currently using the Flutter Camera Plugin but I am running into a problem with the CameraPreview for when the phone turns to landscape mode. The images stay vertical and don't rotate the 90degrees with the phone.
我尝试了无数次尝试,包括Transform.rotate(),但我似乎无法将图像同时填充到屏幕上并旋转90度。
I have tried countless things including Transform.rotate(), but I can't seem to get the image to both, fill the screen and rotate 90degrees.
当我侧向查看手机时,手机横向拍摄的照片仍保存在正确的方向,但是使用_cameraPreviewWidget。
The pictures that were taken while the phone was sideways still saved in the correct orientation when I view them, but using the _cameraPreviewWidget.
推荐答案
将 SystemChrome.setPreferredOrientations()添加到我的initState()中; disp()函数为我解决了这个问题。
Adding SystemChrome.setPreferredOrientations() to my initState() & dispose() functions solved this problem for me.
import 'package:flutter/services.dart';
...
@override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
}
@override
void dispose() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
}
这篇关于Flutter Camera Preview不会随着手机方向旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!