Search code examples
flutterdart

How to disable highlight and splash behavior of TabBar item in Flutter


I just want disable or change highlightColor and splashColor behavior when tapping on tab item?

My code segment,

SliverAppBar(
    backgroundColor: MyColors.darkGreen,
    elevation: 0.0,
    automaticallyImplyLeading: false,
    bottom: TabBar(
      isScrollable: true,
      unselectedLabelColor: Colors.grey,
      labelColor: Colors.white,
      onTap: (int itemIndex) {},
      indicatorSize: TabBarIndicatorSize.tab,
      indicator: BubbleTabIndicator(
        indicatorHeight: 25.0,
        indicatorColor: Colors.white38,
        tabBarIndicatorSize: TabBarIndicatorSize.tab,
      ),
      tabs: tabs,
      controller: _tabController,
    ),
    pinned: true,
    floating: false,
    title: _titleWidget,
),

Guide me how to make it.


Solution

  • For anyone looking for a solution to this, the Flutter team merged in a PR to do just that. Here is how you do it:

    TabBar(
      splashFactory: NoSplash.splashFactory,
      overlayColor: MaterialStateProperty.resolveWith<Color?>(
        (Set<MaterialState> states) {
          // Use the default focused overlay color
          return states.contains(MaterialState.focused) ? null : Colors.transparent;
        }
      ),
      ...
    )
    

    Here is a link to the PR: https://github.com/flutter/flutter/pull/96252