Search code examples
flutterdart

Remove Flutter TabBar bottom border


I'm trying to create a custom TabBar using PreferredSize, but I can't meld the color of the TabBar with my body, there seems to be a border between the TabBar and the body. The picture below will show you clearly what I'm trying to accomplish.

enter image description here

I have tried to create a border with the same color as the body with large width, but it doesn't seems to work. Here is my code:

  Widget _buildAppBar(context) {
return AppBar(
  title: Text(title),
  elevation: 0,
  flexibleSpace: Image.asset(
    'images/motif_batik_01.jpg',
    fit: BoxFit.cover,
    width: 1200,
  ),
  bottom: _buildTabBar(context)
);

}

  Widget _buildTabBar(context) {
return PreferredSize(
  preferredSize: Size.fromHeight(100.0),
  child: Container(
    decoration: BoxDecoration(
      color: Theme.of(context).backgroundColor,
      borderRadius: BorderRadius.only(
        topLeft: Radius.circular(50),
        topRight: Radius.circular(50),
      ),
    ),
    padding: EdgeInsets.only(
      top: 50,
      left: 20,
      right: 20,
    ),
    height: 100,
    child: TabBar(
      indicator: BoxDecoration(
        color: Colors.orange, borderRadius: BorderRadius.circular(20)
      ),
      labelStyle: TextStyle(color: Colors.white),
      unselectedLabelColor: Colors.orange,
      tabs: <Widget>[
        Tab(child: Text('A', style: TextStyle(fontSize: 18.0))),
        Tab(child: Text('B', style: TextStyle(fontSize: 18.0))),
      ],
    ),
  )
);

}

Edit Notes: I figured out that if my 'preferedSize' is a multiplication of 40.0 (40.0, 80.0) the line disappears, could it be a bug in the flutter itself?


Solution

  • Add indicator color to tabBar and color to transparent.

    indicatorColor: Colors.transparent