我希望我的 body 占据整个屏幕。我已经尝试过使用extendBody: true
,但它似乎什么也没做。这是示例代码以及屏幕截图-
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
extendBody: true,
body: Container(
color: Colors.orange,
height: double.infinity,
width: double.infinity,
),
floatingActionButton:
FloatingActionButton(), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
屏幕截图:我正在使用Android R运行像素3xl avd
最佳答案
SystemChrome.setEnabledSystemUIOverlays([]);
添加到build
类的MyApp
中,使应用全屏运行:class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
SystemChrome.setEnabledSystemUIOverlays([]);
return MaterialApp(
...
resizeToAvoidBottomPadding: false
设置Scaffold
,以删除导航栏后面的多余空间:return Scaffold(
resizeToAvoidBottomPadding: false,
body: Container(
color: Colors.orange,
height: double.infinity,
width: double.infinity,
),
floatingActionButton: FloatingActionButton(
onPressed: () {},
),
);
结果: