Search code examples
flutterpaddingspacetabbarappbar

how to get rid of space between appbar & tabbar in flutter?


I'm trying to do it but I do not know how to do it

enter image description here

I wanna get rid of green box space. I've trying with PreferedSize widget but it doesn't work my code is ...

  @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,
            ),
          ),
...

I need your help ☑


Solution

  • Wrap the TabBar with a PreferredSize widget of height 0 (or a small height):

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