Please help navigate the bottomNavigationBar Scaffold property. I have a bottom navigation bar with four tabs. They work well, on every screen, but if inside a tab I open a new screen, then clicking on the same navbar tab does not close the child screen, but the state of the parent screen of the tab is updated. How do I close the child screen? Are there any ways? The bottom navigation implementation is simple:
final List<TabItem> tabs = [
TabItem(
label: '-',
icon: 'assets/bottom/search.svg',
maintainState: false,
root: 'search',
),
TabItem(
label: '-',
icon: 'assets/bottom/news.svg',
maintainState: false,
root: 'news',
),
TabItem(
label: '-',
icon: 'assets/bottom/messages.svg',
maintainState: false,
root: 'messagePage',
),
/*if (Platform.isAndroid)
TabItem(
label: '-',
icon: 'assets/bottom/anonim.svg',
maintainState: false,
root: 'dumbDate',
),*/
TabItem(
label: '-',
icon: 'assets/bottom/profile.svg',
maintainState: false,
root: 'myProfile',
),
];
void selectTab(int index, {Map arguments}) {
if (index == TabNavigator.currentTab.value ||
index != TabNavigator.currentTab.value) {
print('Экран обновился');
setState(() {
TabNavigator.currentTab.value = index;
});
//TabNavigator.changeValue(index);
//TabNavigator.changeValue(index);
}
}
@override
Widget build(BuildContext context) {
return WillPopScope(
key: childkey,
onWillPop: () => showDialog<bool>(
context: context,
builder: (c) => AlertDialog(
title: Text('Arbue'),
content: Text('Вы действительно хотите закрыть приложение?'),
actions: [
FlatButton(
child: Text('Да'),
onPressed: () => Navigator.pop(c, true),
),
FlatButton(
child: Text('Нет'),
onPressed: () => Navigator.pop(c, false),
),
],
),
),
child: ValueListenableBuilder(
valueListenable: TabNavigator.currentTab,
builder: (BuildContext context, int value, Widget _) {
return Scaffold(
backgroundColor: Colors.white,
body: IndexedStack(
index: value,
children: tabs.map((e) => e.page).toList(),
),
bottomNavigationBar:
BlocBuilder<ButtomCubit, bool>(builder: (context, value) {
if (value == true) {
return BottomNavigation(
onSelectTab: selectTab,
tabs: tabs,
);
}
if (value == false) {
return SizedBox();
} else {
return Container();
}
}),
);
},
));
}
}