void main() {
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);
OrientationSingleton.left = true;
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft])
.then((_) {
runApp(new MyApp());
});
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
这是我的应用程序。我找到了一些有关如何删除它的教程:flutter删除appbar上的后退按钮,但这是针对AppBar的。我尝试在上运行我的应用程序,AppBar
但得到了
MediaQuery.of() called with a context that does not contain a MediaQuery.
因为我依靠MediaQuery.of()
我的应用程序内部。
那么,如何删除Flutter上的Android后退,首页和方形按钮MaterialApp
?
如错误消息中所述,SystemChrome
require-context
可以使用以下initState()
方法来调用它Widget
:
class MyApp extends StatefulWidget {
const MyApp({ Key key }) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);
OrientationSingleton.left = true;
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft]);
}
@override
Widget build(BuildContext context) {
return MaterialApp(); // your MaterialApp class
}
}
要在Android上隐藏系统底栏,一种选择是setEnabledSystemUIOverlays()
使用一个空列表调用该函数:
SystemChrome.setEnabledSystemUIOverlays([]);
但是,并非所有Android设备都全面支持此功能。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句