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';
|
import 'package:wetter/screens/settings.dart';
|
||||||
|
|
||||||
class NavBar extends StatelessWidget {
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -31,6 +32,10 @@ class NavBar extends StatelessWidget {
|
|||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(builder: (context) => const Locations()),
|
MaterialPageRoute(builder: (context) => const Locations()),
|
||||||
|
).then(
|
||||||
|
(value) {
|
||||||
|
refreshPageFrom();
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|||||||
+9
-1
@@ -25,6 +25,12 @@ class _MyAppState extends State<MyApp> {
|
|||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void refresh() {
|
||||||
|
setState(() {
|
||||||
|
_locations = UserPreferences.getSavedLocations();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Widget buildContent() {
|
Widget buildContent() {
|
||||||
return DefaultTabController(
|
return DefaultTabController(
|
||||||
length: _locations.length,
|
length: _locations.length,
|
||||||
@@ -37,7 +43,9 @@ class _MyAppState extends State<MyApp> {
|
|||||||
tabs: [for (String name in _locations) Tab(icon: Text(name))],
|
tabs: [for (String name in _locations) Tab(icon: Text(name))],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
drawer: const NavBar(),
|
drawer: NavBar(
|
||||||
|
refreshPageFrom: refresh,
|
||||||
|
),
|
||||||
body: (_locations.isEmpty)
|
body: (_locations.isEmpty)
|
||||||
? const Text("No locations")
|
? const Text("No locations")
|
||||||
: TabBarView(
|
: TabBarView(
|
||||||
|
|||||||
Reference in New Issue
Block a user