I am creating an app that contains a tab bar on its homepage. I want to be able to navigate to one of the tabs using my FloatingActio
You can use TabController
:
TabController _controller = TabController(
vsync: this,
length: 3,
initialIndex: 0,
);
_controller.animateTo(_currentTabIndex);
return Scaffold(
appBar: AppBar(
bottom: TabBar(
controller: _controller,
tabs: [
...
],
),
),
body: TabBarView(
controller: _controller,
children: [
...
],
),
);
And than, setState
to update screen:
int _currentTabIndex = 0;
setState(() {
_currentTabIndex = 1;
});