Flutter 如何防止设备仅在颤振的特定类别下旋转?

Flutter 如何防止设备仅在颤振的特定类别下旋转?,flutter,dart,orientation,flutter-layout,screen-orientation,Flutter,Dart,Orientation,Flutter Layout,Screen Orientation,我正在开发一个颤振应用程序,我只需要在某些类中防止设备旋转,而在其他类中保持它工作。我现在知道如何在应用程序中全局禁用旋转,但如何仅在某些类中禁用旋转?您可以尝试在小部件中使用类似的功能: //锁定横向视图的步骤 @凌驾 void initState(){ super.initState(); SystemChrome.setPreferredOrientations([ 设备定向,景观权, DeviceOrientation.landscapeLeft, ]); } @凌驾 处置{ Syste

我正在开发一个颤振应用程序,我只需要在某些类中防止设备旋转,而在其他类中保持它工作。我现在知道如何在应用程序中全局禁用旋转,但如何仅在某些类中禁用旋转?

您可以尝试在小部件中使用类似的功能:

//锁定横向视图的步骤
@凌驾
void initState(){
super.initState();
SystemChrome.setPreferredOrientations([
设备定向,景观权,
DeviceOrientation.landscapeLeft,
]);
}
@凌驾
处置{
SystemChrome.setPreferredOrientations([
设备定向,景观权,
DeviceOrientation.landscapeLeft,
DeviceOrientation.Up,
DeviceOrientation.down,
]);
super.dispose();
}

使用
initState()
dispose()
这一事实意味着您必须使用
StatefulWidget
,如果不是这样的话。

这是否回答了您的问题?