切换标签页时AppBar中多余的空间

时间:2019-10-24 16:32:05

标签: flutter

在应用的初始加载中,我有一个看起来像这样的AppBar:

enter image description here

如果我通过点击BottomNavigationBar中的一个项目导航到另一个屏幕,则AppBar中的标题将被替换:

enter image description here

这是我的自定义AppBar的代码:

class CustomAppBar extends StatefulWidget with PreferredSizeWidget {
  String playerBalance;

  CustomAppBar(double balance) {
    playerBalance =
        FlutterMoneyFormatter(amount: balance).output.withoutFractionDigits;
  }

  @override
  Size get preferredSize => Size.fromHeight(kToolbarHeight);

  @override
  _CustomAppBarState createState() => _CustomAppBarState();
}

class _CustomAppBarState extends State<CustomAppBar> {
  @override
  Widget build(BuildContext context) {
    return AppBar(
      backgroundColor: Colors.white,
      primary: true,
      actions: <Widget>[
        Container(
            margin: EdgeInsets.only(right: 15),
            child: Row(children: [
              Icon(
                Icons.account_balance_wallet,
                color: Color(0xFF6078ea),
              ),
              SizedBox(width: 5),
              Text(
                "\$${widget.playerBalance}",
                style: TextStyle(
                  color: Colors.green,
                  fontSize: 20,
                ),
              )
            ]))
      ],
      title: RichText(
        text: TextSpan(
          children: <TextSpan>[
            TextSpan(
                text: 'MY',
                style: TextStyle(
                    fontFamily: 'Muli',
                    fontSize: 18,
                    color: Color(0xFF6078ea))),
            TextSpan(
                text: ' APP',
                style: TextStyle(
                    fontFamily: 'Muli', color: Colors.red, fontSize: 18)),
          ],
        ),
      ),
    );
  }
}

enter image description here

使用Flutter检查工具,看起来好像已经以某种方式添加了这个附加的RichText小部件。我不知道这是哪里来的。

1 个答案:

答案 0 :(得分:1)

leading设置为null,将automaticallyImplyLeading设置为false