Search code examples
flutterdartflutter-layout

How to make vertical lines between tabs in tabBar?


I have a tapBar with tabs, these tabs are clickable and I want to add divider between tabs but I don't understand how to do this in Flutter!

This is my tabBar:

TabBar(
  indicatorPadding: EdgeInsets.symmetric(vertical: 10),
  indicator: ShapeDecoration(
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.all(Radius.circular(5)),
      side: BorderSide(color: Colors.white)),
    color: Color(0xFF1C1B20),
  ),
  labelColor: AppColors.whiteE3EAF6,
  labelStyle: TextStyle(color: Colors.white),
  tabs: [
    Tab(text: "1M",),
    Tab(text: "5M",),
    Tab(text: "15M",),
    Tab(text: "30M",),
    Tab(text: "1H",),
  ]
)

And I want to make it like this:

This is what I want

I tried to add Container between Tabs but this container moves all my tabs and became clickable and this is not what I really want.

Also this TabBar is inside Container and width of Container is 350


Solution

  • Wrap your tab inside container like this :

      Widget _tab(String text) {
        return Container(
          padding: const EdgeInsets.all(0),
          width: double.infinity,
          decoration: const BoxDecoration(
              border: Border(right: BorderSide(color: Colors.white, width: 1, style: BorderStyle.solid))),
          child: Tab(
            text: text,
          ),
        );
      }
    

    then create your tab :

    TabBar(
                    indicatorPadding: EdgeInsets.symmetric(vertical: 10),
                    indicator: ShapeDecoration(
                      shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.all(Radius.circular(5)),
                          side: BorderSide(color: Colors.white)),
                      color: Color(0xFF1C1B20),
                    ),
                    labelColor: AppColors.whiteE3EAF6,
                    labelStyle: TextStyle(color: Colors.white),
                    labelPadding: const EdgeInsets.all(0), // remember to add this line
                    tabs: [
                      _tab('1M'),
                      _tab('5M'),
                      _tab('15M'),
                      _tab('30M'),
                      _tab('1H'),
                    ]
                )