77 lines
2.5 KiB
Dart
77 lines
2.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:wetter/components/compact_weather_data.dart';
|
|
import 'package:wetter/components/main_menu.dart';
|
|
import 'package:wetter/models/daily_weather_model.dart';
|
|
import 'package:wetter/services/brightsky_api_service.dart';
|
|
|
|
void main() => runApp(const MyApp());
|
|
|
|
class MyApp extends StatefulWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
State<MyApp> createState() => _MyAppState();
|
|
}
|
|
|
|
class _MyAppState extends State<MyApp> {
|
|
late Future<List<DailyWeatherModel>> dailyWeather;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
dailyWeather = BrightSkyAPI.fetchForecastForTimeRange(
|
|
DateTime.now(), DateTime.now().add(const Duration(days: 7)));
|
|
}
|
|
|
|
@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: Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Wetter in Harburg'),
|
|
),
|
|
drawer: const NavBar(),
|
|
body: RefreshIndicator(
|
|
onRefresh: () {
|
|
return Future(() {
|
|
setState(() {
|
|
dailyWeather = BrightSkyAPI.fetchForecastForTimeRange(
|
|
DateTime.now(),
|
|
DateTime.now().add(const Duration(days: 7)));
|
|
});
|
|
});
|
|
},
|
|
child: SingleChildScrollView(
|
|
physics: const AlwaysScrollableScrollPhysics(),
|
|
child: Center(
|
|
child: FutureBuilder<List<DailyWeatherModel>>(
|
|
future: dailyWeather,
|
|
builder: (context, snapshot) {
|
|
if (snapshot.hasData) {
|
|
return Column(
|
|
children: snapshot.data!
|
|
.map((e) => CompactWeatherData(e))
|
|
.toList());
|
|
} else if (snapshot.hasError) {
|
|
return Text('${snapshot.error}');
|
|
}
|
|
|
|
// By default, show a loading spinner.
|
|
return const CircularProgressIndicator();
|
|
},
|
|
),
|
|
),
|
|
))),
|
|
);
|
|
}
|
|
}
|