我有3个BottomNavigationBarItems的BottomNavigationBar。在单击第三个BottomNavigationBarItem时,显示的页面的标签栏的长度为3。如果我当前在第二个TabBarView上,则现在选择第一个BottomNavigationBarItem,然后再次选择第3个BottomNavigationBarItem,当前选择的TabBarView的索引即2丢失,并且TabBarView重置为第一索引。当用户选择另一个BottomNavigationBarItem时,如何维护索引TabBarView的状态?
为TabBar添加了代码
DefaultTabController(
length: 3,
child: Column(
children: <Widget>[
Container(
constraints: BoxConstraints.expand(height: 65),
child: TabBar(
tabs: [
Tab(
icon: Icon(
OMIcons.place,
),
iconMargin: EdgeInsets.only(bottom: 4),
text: "One"),
Tab(
icon: Icon(
OMIcons.peopleOutline,
),
iconMargin: EdgeInsets.only(bottom: 4),
text: "Two"),
Tab(
icon: Icon(
OMIcons.localActivity,
),
iconMargin: EdgeInsets.only(bottom: 4),
text: "Three"),
],
labelStyle: Theme.of(context).textTheme.subtitle1,
labelColor: Theme.of(context).colorScheme.secondary,
unselectedLabelColor:
Theme.of(context).colorScheme.primaryVariant,
),
),
Expanded(
child: Container(
child: TabBarView(children: [
SubmittedListView(
_model.visitedLocationsResponse
.ExistingLocationVisits
.toList(),
PageStorageKey('One')),
SubmittedListView(
_model
.visitedLocationsResponse.NewLocationVisits
.toList(),
PageStorageKey('Two')),
SubmittedListView(
_model.visitedLocationsResponse
.MarketingLocationVisits
.toList(),
PageStorageKey('Three')),
]),
),
),
],
),
),