Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

flutter

dart

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.

like image 967
Kavin-K Avatar asked Nov 23 '19 05:11

Kavin-K


People also ask

How do I get rid of splash color Flutter?

By setting both highlightColor and splashColor in your theme to Colors. transparent removed the ripple. You can hold some concerns that setting highlightColor might have some knock-on effects.

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 you remove tab padding Flutter?

Just by adding isScrollable: true parameter to TabBar() all tabs shrink to one side.


4 Answers

just put your AppBar inside Theme with transparent highlightColor and splashColor.
eg.

return Scaffold(
  appBar: PreferredSize(
    preferredSize: Size.fromHeight(70),
      child: Theme(
        data: ThemeData(
        highlightColor: Colors.transparent,
        splashColor: Colors.transparent,
      ),
      child: AppBar( ... )
like image 162
Anouar khaldi Avatar answered Nov 15 '22 10:11

Anouar khaldi


Add this in your ThemeData inside MaterialApp.

return MaterialApp(
      theme: ThemeData(
        highlightColor: Colors.transparent,
        splashColor: Colors.transparent,
      ),
      onGenerateRoute: _routes,
      initialRoute: '/',
    );

If you only want to disable the splashColor / highlightColor on that specific TabBar, you can wrap your widget in a Theme widget. That will override the global ThemeData

like image 41
alexandreohara Avatar answered Nov 15 '22 09:11

alexandreohara


You can only wrap the TabBar inside Theme() and set the splashColor

Theme(
  data: ThemeData().copyWith(
    splashColor: Colors.transparent),
  child: TabBar(
    ...)
)
like image 27
Tuan Dat Tran Avatar answered Nov 15 '22 09:11

Tuan Dat Tran


follow the process

inside MaterialApp follow this

return MaterialApp(
  theme: ThemeData(
        highlightColor: Colors.transparent,
        splashColor: Colors.transparent,
      ),
);

and inside TabBar follow this property

TabBar(
 overlayColor:MaterialStateProperty.all<Color>(Colors.transparent),
 // above property will remove splash color or it will provider whatever color you want
 tabs:<Widget>[
   Tab(),
 ],
),

hope this will help you!! thank you.

like image 24
sahil Avatar answered Nov 15 '22 09:11

sahil