首先导入服务包:
import 'package:flutter/services.dart';
这将使您可以访问
SystemChrome课程
"Controls specific aspects of the operating system'sgraphical interface and how it interacts with the application."
加载小部件时,请执行以下操作:
@overridevoid initState(){ super.initState(); SystemChrome.setPreferredOrientations([ DeviceOrientation.landscapeRight, DeviceOrientation.landscapeLeft, ]);}然后当我离开页面时,将其恢复为正常状态,如下所示:
@overridedispose(){ SystemChrome.setPreferredOrientations([ DeviceOrientation.landscapeRight, DeviceOrientation.landscapeLeft, DeviceOrientation.portraitUp, DeviceOrientation.portraitDown, ]); super.dispose();}


