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 createState() => _MyAppState(); } class _MyAppState extends State { List _locations = []; @override void initState() { _locations = UserPreferences.getSavedLocations(); super.initState(); } void refresh() { setState(() { _locations = UserPreferences.getSavedLocations(); }); } 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: NavBar( refreshPageFrom: refresh, ), 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()); } }