2

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.

Chillie
  • 1,030
  • 10
  • 28
mousaa
  • 21
  • 2
  • 4

1 Answers1

0

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,
);
Artyom Sokolov
  • 2,385
  • 3
  • 23
  • 34