Tabs update themselves after settings view

This commit is contained in:
2025-11-19 21:39:01 +01:00
parent cf71b40718
commit a8d4e640cf

View File

@@ -17,12 +17,7 @@ class CustomNavigationBar extends StatefulWidget {
class _CustomNavigationBarState extends State<CustomNavigationBar> class _CustomNavigationBarState extends State<CustomNavigationBar>
with SingleTickerProviderStateMixin { with SingleTickerProviderStateMixin {
int currentIndex = 0; int currentIndex = 0;
final List<Widget> tabs = [ int tabKeyCount = 0;
const HomeView(),
const GameHistoryView(),
const GroupsView(),
const StatisticsView(),
];
@override @override
void initState() { void initState() {
@@ -31,6 +26,22 @@ class _CustomNavigationBarState extends State<CustomNavigationBar>
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// Pretty ugly but works
final List<Widget> tabs = [
KeyedSubtree(key: ValueKey('home_$tabKeyCount'), child: const HomeView()),
KeyedSubtree(
key: ValueKey('games_$tabKeyCount'),
child: const GameHistoryView(),
),
KeyedSubtree(
key: ValueKey('groups_$tabKeyCount'),
child: const GroupsView(),
),
KeyedSubtree(
key: ValueKey('stats_$tabKeyCount'),
child: const StatisticsView(),
),
];
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
centerTitle: true, centerTitle: true,
@@ -42,10 +53,15 @@ class _CustomNavigationBarState extends State<CustomNavigationBar>
scrolledUnderElevation: 0, scrolledUnderElevation: 0,
actions: [ actions: [
IconButton( IconButton(
onPressed: () => Navigator.push( onPressed: () async {
context, await Navigator.push(
MaterialPageRoute(builder: (_) => const SettingsView()), context,
), MaterialPageRoute(builder: (_) => const SettingsView()),
);
setState(() {
tabKeyCount++;
});
},
icon: const Icon(Icons.settings), icon: const Icon(Icons.settings),
), ),
], ],