Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Flutter TabBar bottom border

Tags:

flutter

dart

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?

like image 967
Riven Avatar asked Jun 05 '19 17:06

Riven


People also ask

How do you get rid of the underline on a tab in flutter?

By default, a TextField is decorated with an underline. You can add a label, icon, inline hint text, and error text by supplying an InputDecoration as the decoration property of the TextField . To remove the decoration entirely (including the underline and the space reserved for the label), set the decoration to null.

How do I turn off TabBar click in flutter?

Just wrap the TabBar in an IgnorePointer. This should be the correct and easiest answer.

How do I change the TabBar background in flutter?

To change tab bar background color in Flutter, first, create a getter to return the TabBar widget and then wrap the TabBar widget inside the PreferredSize -> Material widget. Inside the Material add the color property and set the color of your choice.


2 Answers

Add indicator color to tabBar and color to transparent.

indicatorColor: Colors.transparent

like image 105
Martin Seydo Avatar answered Sep 19 '22 07:09

Martin Seydo


indicator:BoxDecoration() or indicatorColor:Colors.transparent

like image 36
YuHaHa Avatar answered Sep 22 '22 07:09

YuHaHa