Files
wetterApp/lib/main.dart
T
2022-09-05 11:59:52 +02:00

69 lines
1.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:wetter/components/main_menu.dart';
import 'package:wetter/screens/main_weather_view.dart';
import 'package:wetter/services/user_preferences.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await UserPreferences.init();
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
List<String> _locations = [];
@override
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());
}
}