How to display body under the AppBar of scaffold widget and not below?

后端 未结 7 1719
谎友^
谎友^ 2021-02-03 20:16

I\'m using a transparent AppBar and I would like to display body behind the transparent AppBar and not bellow. How to do that ?

7条回答
  •  佛祖请我去吃肉
    2021-02-03 20:33

    After some time I do not know if this will help anyone but...there it goes..

    Problem: I wanted to have gradient background on the body of my Scaffold, and in Android the AppBar was messing things up.

    My solution:

    Scaffold(
          extendBodyBehindAppBar: true,
          appBar: AppBar(
            backgroundColor: Colors.transparent,
            elevation: 0,
            title:  Text("AppBar text"),
          ),
          body: Container(
            decoration: BoxDecoration(
              gradient: LinearGradient(
                  begin: Alignment.topCenter,
                  end: Alignment.bottomCenter,
                  colors: [
                    HexColor.hexToColor("D76984"),
                    HexColor.hexToColor("2369C0")
                  ]),
            ),
          )
        );
    

    Other solutions using Stack also might work but then the entire design of this screen is forced to use Stack which for me is less responsive than using other widgets...but that is just me.

提交回复
热议问题