繁体   English   中英

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

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

希望根据情况(主要是使用底部导航时)为一屏制作空白应用栏而不是带有徽标标题的应用栏。 但是appBar()不能用container()小部件替换。 我应该怎么做?

例如.. 如果底部导航栏索引变为 0,应用栏将消失,但其他索引应用栏会出现。

下面是带有徽标 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])),
        ),
      ),

我所期望的是,但完全得到错误。

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])),
        ),
      ),

如果要删除应用栏,只需将值设置为 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])),
        ),
      ),

或者您可以像这样使用 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