Add locations and save them, remove locations and delete them

This commit is contained in:
Konstantin Kollar
2022-09-05 11:59:52 +02:00
parent 730634bdb2
commit e96a33f0a3
6 changed files with 75 additions and 48 deletions
+43 -32
View File
@@ -17,41 +17,52 @@ class MyApp extends StatefulWidget {
}
class _MyAppState extends State<MyApp> {
List<String> _locations = [];
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Wetter',
theme: ThemeData(
primarySwatch: Colors.blue,
textTheme: const TextTheme(
headline1: TextStyle(fontSize: 72.0, fontWeight: FontWeight.bold),
headline6: TextStyle(fontSize: 36.0, fontStyle: FontStyle.italic),
bodyText2: TextStyle(fontSize: 14.0, fontFamily: 'Hind'),
),
),
home: DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
title: const Text('Wetter'),
bottom: const TabBar(
tabs: [
Tab(icon: Text("Hamburg")),
Tab(icon: Text("Frankfurt")),
Tab(icon: Text("Freiburg")),
],
),
),
drawer: const NavBar(),
body: const TabBarView(
children: [
MainWeatherView(53.46, 9.98),
MainWeatherView(50.15, 8.70),
MainWeatherView(47.99, 7.85)
],
),
void initState() {
_locations = UserPreferences.getSavedLocations();
super.initState();
}
Widget buildContent() {
return DefaultTabController(
length: _locations.length,
child: Scaffold(
appBar: AppBar(
title: const Text('Wetter'),
bottom: (_locations.isEmpty)
? null
: TabBar(
tabs: [for (String name in _locations) Tab(icon: Text(name))],
),
),
drawer: const NavBar(),
body: (_locations.isEmpty)
? const Text("No locations")
: TabBarView(
children: [
for (String name in _locations)
MainWeatherView(UserPreferences.getLat(name),
UserPreferences.getLon(name))
],
),
),
);
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Wetter',
theme: ThemeData(
primarySwatch: Colors.blue,
textTheme: const TextTheme(
headline1: TextStyle(fontSize: 72.0, fontWeight: FontWeight.bold),
headline6: TextStyle(fontSize: 36.0, fontStyle: FontStyle.italic),
bodyText2: TextStyle(fontSize: 14.0, fontFamily: 'Hind'),
),
),
home: buildContent());
}
}