Flutter SystemChrome.setPreferredOrientations使屏幕旋转,但随后返回
我有一个fluuter小部件,可以显示全屏画廊。因此,我想使用Flutter SystemChrome.setPreferredOrientations使屏幕旋转,但随后返回,flutter,Flutter,我有一个fluuter小部件,可以显示全屏画廊。因此,我想使用SystemChrome.setPreferredOrientations强制旋转到landscapeRight,并在onDispose中恢复此状态。这是可行的,但当我从某些不同的小部件导航到此小部件时,屏幕只会旋转一小段时间,然后返回到纵向。奇怪的是,当我从其他一些小部件导航到它时,它就工作了 class _FullscreenGalleryState extends State<FullscreenGallery> {
SystemChrome.setPreferredOrientations
强制旋转到landscapeRight,并在onDispose
中恢复此状态。这是可行的,但当我从某些不同的小部件导航到此小部件时,屏幕只会旋转一小段时间,然后返回到纵向。奇怪的是,当我从其他一些小部件导航到它时,它就工作了
class _FullscreenGalleryState extends State<FullscreenGallery> {
@override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeRight]);
}
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeRight]);
return new Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(
0.0), // app bar is needed for iOS status bar color settings...
child: AppBar(
elevation: 0,
brightness: Brightness.dark,
)),
body: new Swiper(...);
}
@override
void dispose() {
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
super.dispose();
}
class\u FullscreenGalleryState扩展状态{
@凌驾
void initState(){
super.initState();
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeRight]);
}
@凌驾
小部件构建(构建上下文){
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeRight]);
归还新脚手架(
appBar:首选大小(
首选大小:Size.fromHeight(
0.0),//iOS状态栏颜色设置需要应用程序栏。。。
孩子:AppBar(
海拔:0,
亮度:亮度。暗,
)),
车身:新泳衣(…);
}
@凌驾
无效处置(){
SystemChrome.setPreferredOrientations(
[设备定向。肖像向上,设备定向。肖像向下];
super.dispose();
}
有人知道凶手是什么吗