简体   繁体   English

想要用 flutter 中的其他小部件更改应用栏?

[英]Want to change app bar with other widgets in flutter?

Want to make blank app bar for one screen instead of app bar with logo title depending on the situation (mainly when using bottom navigation).希望根据情况(主要是使用底部导航时)为一屏制作空白应用栏而不是带有徽标标题的应用栏。 But appBar() can't be replace with container() widget.但是appBar()不能用container()小部件替换。 How should I do?我应该怎么做?

Eg.. If bottom navigation bar Index become 0, app bar will disappear although for other Index app bar will appear.例如.. 如果底部导航栏索引变为 0,应用栏将消失,但其他索引应用栏会出现。

Below is the code snippet with logo appbar下面是带有徽标 appbar 的代码片段

appBar: AppBar(
        centerTitle: true,
        title: Image.asset(
          'assets/fblogosmall300.png',
          fit: BoxFit.contain,
          height: 45,
        ),
        flexibleSpace: Container(
          decoration: BoxDecoration(
              gradient: LinearGradient(
                  begin: Alignment.centerLeft,
                  end: Alignment.centerRight,
                  colors: <Color>[secondColor, mainColor])),
        ),
      ),

What I expected is, but completely get error.我所期望的是,但完全得到错误。

appBar: currentIndex == 4? Container():AppBar(
        centerTitle: true,
        title: Image.asset(
          'assets/fblogosmall300.png',
          fit: BoxFit.contain,
          height: 45,
        ),
        flexibleSpace: Container(
          decoration: BoxDecoration(
              gradient: LinearGradient(
                  begin: Alignment.centerLeft,
                  end: Alignment.centerRight,
                  colors: <Color>[secondColor, mainColor])),
        ),
      ),

If you want to remove the app bar just set the value at null.如果要删除应用栏,只需将值设置为 null。

appBar: currentIndex == 4 ? null : AppBar(
        centerTitle: true,
        title: Image.asset(
          'assets/fblogosmall300.png',
          fit: BoxFit.contain,
          height: 45,
        ),
        flexibleSpace: Container(
          decoration: BoxDecoration(
              gradient: LinearGradient(
                  begin: Alignment.centerLeft,
                  end: Alignment.centerRight,
                  colors: <Color>[secondColor, mainColor])),
        ),
      ),

Or you can used PreferredSize widget like this或者您可以像这样使用 PreferredSize 小部件

appBar: PreferredSize(
        preferredSize: Size.fromHeight(50.0),
        child: currentIndex == 4 ? Container() : AppBar(),
    ),
    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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