繁体   English   中英

Flutter中如何让Scaffold body从AppBar顶部到屏幕底部填满屏幕

[英]How to make Scaffold body fill the screen from the top of the AppBar to the bottom of the screen in Flutter

我有一个透明的AppBar ,我希望ScaffoldbodyAppBar的顶部开始并在底部结束。 我的代码如下:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM