我正在开发Flutter应用,我需要仅在某些类中阻止设备旋转,而在其他类中保持设备运行。我现在如何在应用程序中全局禁用旋转,但是如何仅在某些类中禁用旋转?
您可以尝试在小部件中使用类似的东西:
@override
void initState() {
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
]);
}
@override
dispose() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
super.dispose();
}