假设我的应用程序有两个屏幕(屏幕A和B)。我的应用程序从屏幕A开始,在屏幕A中,我将设备方向设置为纵向向上。例如-
Future<void> main() async {
setUpLocator();
// debugPaintSizeEnabled=true;
WidgetsFlutterBinding.ensureInitialized();
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
MobileAds.instance.initialize();
await Firebase.initializeApp();
runApp(ChangeNotifierProvider<ThemeNotifier>(
create: (_) => ThemeNotifier(),
child: MyApp(),
));
}
正常情况下,它工作得很好,并且不会旋转屏幕,但问题出在屏幕B上,在那里我使用了youtube播放器插件(https://pub.dev/packages/youtube_player_flutter)。当我打开youtube播放器的全屏模式时,它会旋转屏幕,这不是问题,但如果我在全屏模式(youtube播放器)下从B返回到屏幕A,那么屏幕A也会以横向模式出现。但我根本不想让屏幕A处于横向模式。我该如何解决这个问题呢?
发布于 2021-08-22 09:04:50
您还可以像下面这样在init
中为特定屏幕设置,并确保它被调用,
@override
void initState(){
super.initState();
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
]);
}
https://stackoverflow.com/questions/68883002
复制相似问题