Flutter, how to set TabBar height?

Viewed 1100

Note :I have tried other answers on stackoverflow but they didn't work.

I have a TabBar and want to set its height.

here is my code :

Widget getTabBar() {
    return TabBar(
      labelColor: LightTheme.TabIconColor,
      indicatorColor: LightTheme.TabIconColor,
      indicatorSize: TabBarIndicatorSize.tab,
      tabs: [
        Tab(
            text: "Collect",
            icon: Icon(
              Icons.add_location,
              size: 40,
            )),
        Tab(
            text: "Deliver",
            icon: Icon(
              Icons.tour,
              size: 40,
            )),
      ],
    );
  }

and here is the screenshot of my app. As you can see the titles were clipped (the phrase "bottom overflowed by 22 pixels"):

enter image description here

and this is the rest of screen's code :

Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text('Test'),
        backgroundColor: LightTheme.AppBarColor,
      ),
      body: DefaultTabController(
        length: 2,
        child: Scaffold(
          appBar: AppBar(
            backgroundColor: Colors.white,
            automaticallyImplyLeading: false,
            flexibleSpace: getTabBar(),
          ),
          body: getTabBarView(),
        ),
      ),
      drawer: getDrawer(),
      // Disable opening the drawer with a swipe gesture.
      drawerEnableOpenDragGesture: false,
    );
  }

Update : I get the following message in the console. I tried to set BoxConstraint but the problem still exists:

The specific RenderFlex in question is: RenderFlex#fe401 relayoutBoundary=up25 OVERFLOWING
...  parentData: offset=Offset(0.0, 0.0) (can use size)
...  constraints: BoxConstraints(0.0<=w<=173.7, 0.0<=h<=54.0)
...  size: Size(40.0, 54.0)
...  direction: vertical
...  mainAxisAlignment: start
...  mainAxisSize: max
...  crossAxisAlignment: center
...  verticalDirection: down
1 Answers

try wrap your Tab inside Container and set the height of the container. here is an example :

   Container(
      height: 100,
      child: Tab(
        child: Column(
          children: [
            Icon(
              Icons.add_location,
              size: 40,
            ),
            Text("Tab A"),
          ],
        ),
      ),
    ),

result: image

Related