Flutter disable tab bar items

2.7k views Asked by At

I want to be able to programmatically disable/enable tab bar items in Flutter and was wondering how to go about doing that?

In IOS for example, it would be along the lines of tabBarItem1.isEnabled = false.

I want to disable user interaction with the tab bar until they go through a process first for example pressing a button.

Any help/pointers would be much appreciated.

1

There are 1 answers

0
Artyom Sokolov On

I am using this as a workaround.

Regular tab:

Widget regularTab = Tab(
  icon: Icon(Icons.widgets),
  text: AppLocalizations.of(context).regularTab,
);

Tab that won't change index on tap (or will perform any other action of your own):

Widget disabledTab = Material(
  child: InkWell(
    child: Container(
      child: regularTab,
      width: double.infinity,
    ),
    onTap: () {
      print('${DateTime.now()} tapped');
    },
  ),
  color: Colors.transparent,
  textStyle: Theme.of(context).primaryTextTheme.body2,
);