refresh Homepage on return from menu item

This commit is contained in:
Konstantin Kollar
2022-09-05 13:08:41 +02:00
parent e96a33f0a3
commit 9de8e319c3
2 changed files with 15 additions and 2 deletions
+6 -1
View File
@@ -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();
},
);
}),
)
+9 -1
View File
@@ -25,6 +25,12 @@ class _MyAppState extends State<MyApp> {
super.initState();
}
void refresh() {
setState(() {
_locations = UserPreferences.getSavedLocations();
});
}
Widget buildContent() {
return DefaultTabController(
length: _locations.length,
@@ -37,7 +43,9 @@ class _MyAppState extends State<MyApp> {
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(