How to create unselected indicator for tab bar in Flutter

别等时光非礼了梦想. 提交于 2019-12-05 05:42:40

Instead of using container in tabs, try this (wrapping the TabBar with container and providing bottom border

Container(
  //This is responsible for the background of the tabbar, does the magic
  decoration: BoxDecoration(
    //This is for background color
    color: Colors.white.withOpacity(0.0),
    //This is for bottom border that is needed
    border: Border(bottom: BorderSide(color: Colors.grey, width: 0.8))),
    child: TabBar(
    controller: _controller,
    tabs: [
      ...
    ]
  )

Will not look exactly as you want, but will give underlined indication to unselected tabs.

You can use Stack/Container and TabBar together to make the underline

Stack(
            fit: StackFit.passthrough,
            alignment: Alignment.bottomCenter,
            children: <Widget>[
              Container(
                decoration: BoxDecoration(
                  border: Border(
                    bottom: BorderSide(color: colorSecondary, width: 2.0),
                  ),
                ),
              ),
              TabBar(
                isScrollable: true,
                onTap: (index) => tabsModel.value = listTabsModel[index],
                tabs: listTabsModel
                    .map(
                      (value) => Tab(
                        child: value.tabComponent,
                      ),
                    )
                    .toList(),
              ),
            ],
          );

TabBar with an underline for unselected

Not exactly what you are looking for but it can give the underline for un-selected tab.

I think you can use below code with plugin.

TabBar(
      controller: tabController,
      tabs: [
        Tab(text: "ADCD"),
        Tab(text: "EFGH"),
        Tab(text: "IJKL"),
        Tab(text: "MNOP"),
        Tab(text: "QRST"),
      ],
      labelColor: Colors.white,
      labelStyle: TextStyle(
          fontSize: 12.0, fontWeight: FontWeight.w700, fontFamily: 'helvetica'),
      unselectedLabelColor: Colors.black,
      unselectedLabelStyle: TextStyle(
          fontSize: 12.0, fontWeight: FontWeight.w400, fontFamily: 'helvetica'),
      isScrollable: true,
      indicator: new BubbleTabIndicator(
        indicatorHeight: p_35,
        indicatorColor: const Color(0xFF58c8e3),
        tabBarIndicatorSize: TabBarIndicatorSize.tab,
      ),
    );

I have use this plugin for "BubbleTabIndicator" https://pub.dev/packages/bubble_tab_indicator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!