[英]How to make Scaffold body fill the screen from the top of the AppBar to the bottom of the screen in Flutter
I have a transparent AppBar
and I want the body
of the Scaffold
to start from the top of the AppBar
and end at the bottom.我有一个透明的AppBar
,我希望Scaffold
的body
从AppBar
的顶部开始并在底部结束。 My code is as follows:我的代码如下:
Scaffold(
appBar: AppBar(
foregroundColor: Colors.black,
backgroundColor: Colors.transparent,
elevation: 0,
title: const Text('Test Page'),
),
body: Container(color: Colors.teal),
)
The result is:结果是:
And after adding extendBodyBehindAppBar: true
as in the following code:在添加extendBodyBehindAppBar: true
之后,如下代码所示:
Scaffold(
extendBodyBehindAppBar: true,
appBar: AppBar(
foregroundColor: Colors.black,
backgroundColor: Colors.transparent,
elevation: 0,
title: const Text('Test Page'),
),
body: Container(color: Colors.teal),
)
The result is:结果是:
But I want it to start from the top of the AppBar
as:但我希望它从AppBar
的顶部开始,如下所示:
How can this be achieved?!这怎么可能实现?! Thanks in advance!提前致谢!
Try to wrap Scaffold
inside SafeArea
尝试将Scaffold
包裹在SafeArea
Code Structure代码结构
SafeArea 👈 Add Parent SafeArea widget
|_ Scaffold
|_ extendBodyBehindAppBar : true
|_ appBar
Wrap the Scaffold
in a SafeArea
widget:将Scaffold
包装在SafeArea
小部件中:
SafeArea(
child: Scaffold(
extendBodyBehindAppBar: true,
appBar: AppBar(
foregroundColor: Colors.black,
backgroundColor: Colors.transparent,
elevation: 0,
title: const Text('Test Page'),
),
body: Container(color: Colors.teal),
),
)
The SafeArea
is "a widget that insets its child by sufficient padding to avoid intrusions by the operating system." SafeArea
是“一个小部件,它通过足够的填充来插入其子项以避免操作系统的入侵。”
More information in: https://api.flutter.dev/flutter/widgets/SafeArea-class.html更多信息见: https://api.flutter.dev/flutter/widgets/SafeArea-class.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.