简体   繁体   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

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 ,我希望ScaffoldbodyAppBar的顶部开始并在底部结束。 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.

相关问题 如何使整个屏幕可滚动包括 flutter 中的 appbar 脚手架 - How to make whole screen scrollable include appbar scaffold in flutter flutter中如何在屏幕顶部的脚手架中制作抽屉并且BottomNavigationBar在抽屉后面 - How to make the drawer in the scaffold at the top of the screen and the BottomNavigationBar is behind on the drawer in flutter Flutter 中的从底页到全屏脚手架 - From Bottom Sheet to full screen Scaffold in Flutter Flutter - 如何使 SvgPicture.asset() 在没有 Appbar 的主父 Scaffold 的情况下在 Slack 内全屏显示 - Flutter - How to make SvgPicture.asset() take full screen inside of Slack with main parent Scaffold without Appbar Flutter中如何使渐变背景色全屏并在appbar和body之间混合 - How to make a gradient background color full screen and blend between the appbar and body in Flutter 如何将 AppBar 保持在屏幕顶部 - How to keep AppBar at the top of the screen 如何使AppBar从顶部滑动并覆盖屏幕内容,就像短裤应用程序栏一样 - How do I make the AppBar slide from top and overlay the screen content, just like inshorts app bar 如何在 Flutter 中制作带有图像的弧形底部 appBar? - How to make curved bottom appBar with image in Flutter? 如何在切换屏幕时更改底部导航屏幕中的 AppBar Title? - How to change AppBar Title in a bottom navigation screen while switching the screen? 如何在没有 Flutter 中上一个屏幕的应用栏的情况下推送到 Flutter 中的新屏幕? - How to push to a new screen in Flutter without the appbar from the previous screen in Flutter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM