6

I want to resize my TabBar because default height is too much, how can achieve it? Thanks.

DefaultTabController(
    length: 2,
    child: Scaffold(
      appBar: AppBar(
        title: Text('Flutter App'),
        bottom: TabBar(
          tabs: <Widget>[
            Text('Tab 1'),
            Text('Tab 2'),
          ],
        ),
      ),
      body: TabBarView(
        children: <Widget>[
          Icon(Icons.apps),
          Icon(Icons.apps),
        ],
      ),
    ),
  )
rafitajaen
  • 399
  • 6
  • 15
  • Does this answer your question? [How can I customize the TabBar indicator width and height?](https://stackoverflow.com/questions/44272440/how-can-i-customize-the-tabbar-indicator-width-and-height) – Ademir Villena Zevallos Jan 08 '20 at 15:23
  • Is it the TabBar or the TabBarView that you want to adjust the height of? – J. S. Jan 08 '20 at 15:23

3 Answers3

7

For TabBar widget you can do as @praveenb suggested

child: TabBar(
  ...
  tabs: [
    SizedBox(
      height: 100,
      child: Tab(
      ...
yehyatt
  • 2,295
  • 3
  • 28
  • 31
6

You can use PreferredSize:

DefaultTabController(
      length: 2,
      child: Scaffold(
        appBar: PreferredSize(
          preferredSize: Size.fromHeight(150.0),
          child: AppBar(
            bottom: TabBar(
              tabs: <Widget>[
                Text('Tab 1'),
                Text('Tab 2'),
              ],
            ),
          ),
        ),
        body: TabBarView(
          children: <Widget>[
            Icon(Icons.apps),
            Icon(Icons.apps),
          ],
        ),
      ),
    )

It will change overall height of the appbar but if you want to change the height of the tabbar only then apply the PreferredSize widget to the TabBar widget widget rather than applying it on the AppBar widget.

shubhgkr
  • 471
  • 2
  • 7
  • 2
    for TabBar widget PreferredSize not worked, but SizedBox(height: 58, child: //some widget ) worked for me. – praveenb Aug 24 '20 at 20:56
0

We can use height of Tab like this:

          TabBar(
            ...
            tabs: [
              Tab(
                text: '1',
                height: 32,
              ),
              Tab(
                text: '2',
                height: 32,
              ),
            ],
          )