From 9de8e319c3d1168cee81785cafbe2d6c1ffc1fa1 Mon Sep 17 00:00:00 2001 From: Konstantin Kollar Date: Mon, 5 Sep 2022 13:08:41 +0200 Subject: [PATCH] refresh Homepage on return from menu item --- lib/components/main_menu.dart | 7 ++++++- lib/main.dart | 10 +++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/components/main_menu.dart b/lib/components/main_menu.dart index bb86692..4d54faf 100644 --- a/lib/components/main_menu.dart +++ b/lib/components/main_menu.dart @@ -3,7 +3,8 @@ import 'package:wetter/screens/locations.dart'; import 'package:wetter/screens/settings.dart'; class NavBar extends StatelessWidget { - const NavBar({Key? key}) : super(key: key); + final Function refreshPageFrom; + const NavBar({Key? key, required this.refreshPageFrom}) : super(key: key); @override Widget build(BuildContext context) { @@ -31,6 +32,10 @@ class NavBar extends StatelessWidget { Navigator.push( context, MaterialPageRoute(builder: (context) => const Locations()), + ).then( + (value) { + refreshPageFrom(); + }, ); }), ) diff --git a/lib/main.dart b/lib/main.dart index 17f245d..87492b2 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -25,6 +25,12 @@ class _MyAppState extends State { super.initState(); } + void refresh() { + setState(() { + _locations = UserPreferences.getSavedLocations(); + }); + } + Widget buildContent() { return DefaultTabController( length: _locations.length, @@ -37,7 +43,9 @@ class _MyAppState extends State { tabs: [for (String name in _locations) Tab(icon: Text(name))], ), ), - drawer: const NavBar(), + drawer: NavBar( + refreshPageFrom: refresh, + ), body: (_locations.isEmpty) ? const Text("No locations") : TabBarView(