refresh Homepage on return from menu item
This commit is contained in:
@@ -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
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user