![](/img/trans.png)
[英]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.