[英]How to make whole screen scrollable include appbar scaffold in flutter
[英]How to make Scaffold body fill the screen from the top of the AppBar to the bottom of the screen in Flutter
我有一个透明的AppBar
,我希望Scaffold
的body
从AppBar
的顶部开始并在底部结束。 我的代码如下:
Scaffold(
appBar: AppBar(
foregroundColor: Colors.black,
backgroundColor: Colors.transparent,
elevation: 0,
title: const Text('Test Page'),
),
body: Container(color: Colors.teal),
)
结果是:
在添加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),
)
结果是:
但我希望它从AppBar
的顶部开始,如下所示:
这怎么可能实现?! 提前致谢!
尝试将Scaffold
包裹在SafeArea
代码结构
SafeArea 👈 Add Parent SafeArea widget
|_ Scaffold
|_ extendBodyBehindAppBar : true
|_ appBar
将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),
),
)
SafeArea
是“一个小部件,它通过足够的填充来插入其子项以避免操作系统的入侵。”
更多信息见: https://api.flutter.dev/flutter/widgets/SafeArea-class.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.