如何仅针对Flutter中的某些类防止设备旋转?

问题描述 投票:0回答:1

我正在开发Flutter应用,我需要仅在某些类中阻止设备旋转,而在其他类中保持设备运行。我现在如何在应用程序中全局禁用旋转,但是如何仅在某些类中禁用旋转?

flutter dart orientation flutter-layout screen-orientation
1个回答
0
投票

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

@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();
}
© www.soinside.com 2019 - 2024. All rights reserved.