【问题标题】:how to get rid of space between appbar & tabbar in flutter?如何摆脱颤动中的appbar和tabbar之间的空间?
【发布时间】:2020-11-29 21:41:57
【问题描述】:

我正在尝试,但我不知道该怎么做

我想摆脱绿盒空间。 我尝试使用 PreferedSize 小部件,但它不起作用我的代码是...

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: PreferredSize(
        preferredSize: Size.fromHeight(SizeConfig.heightMultiplier * 6.2),
// it's pretty narrow size but doesn't work in this screen but others
        child: Scaffold(
          appBar: AppBar(
            centerTitle: true,
            title: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text(
                  'hello',
                  style: TextStyle(fontWeight: FontWeight.bold),
                ),
                Text(
                  'world',
                ),
                Text(
                  '!',
                  style: TextStyle(fontWeight: FontWeight.bold),
                ),
              ],
            ),
            actions: <Widget>[
              Icon(
                Icons.add,
                color: Colors.transparent,
              ),
            ],
            backgroundColor: Theme.of(context).primaryColor,
            bottom: TabBar(
              controller: tabController,
              indicatorColor: Colors.white,
              tabs: myTabs,
            ),
          ),
...

我需要你的帮助☑

【问题讨论】:

    标签: flutter padding space tabbar appbar


    【解决方案1】:

    用高度为 0(或小高度)的 PreferredSize 小部件包裹 TabBar

    bottom: PreferredSize(
              preferredSize: Size.fromHeight(0),
              child: TabBar(
                controller: tabController,
                indicatorColor: Colors.white,
                tabs: myTabs,
              ),
            ),
    

    【讨论】: