show more days of forecast, enable reload of forecasts

This commit is contained in:
Konstantin Kollar
2022-08-31 14:56:00 +02:00
parent bc3dcf575c
commit 7c4320f4b6
4 changed files with 76 additions and 22 deletions
+36 -20
View File
@@ -13,12 +13,13 @@ class MyApp extends StatefulWidget {
}
class _MyAppState extends State<MyApp> {
late Future<DailyWeatherModel> futureAlbum;
late Future<List<DailyWeatherModel>> dailyWeather;
@override
void initState() {
super.initState();
futureAlbum = BrightSkyAPI.fetchForecast(DateTime.now());
dailyWeather = BrightSkyAPI.fetchForecastForTimeRange(
DateTime.now(), DateTime.now().add(const Duration(days: 7)));
}
@override
@@ -34,25 +35,40 @@ class _MyAppState extends State<MyApp> {
),
),
home: Scaffold(
appBar: AppBar(
title: const Text('Wetter heute in Harburg'),
),
body: Center(
child: FutureBuilder<DailyWeatherModel>(
future: futureAlbum,
builder: (context, snapshot) {
if (snapshot.hasData) {
return CompactWeatherData(snapshot.data!);
} else if (snapshot.hasError) {
return Text('${snapshot.error}');
}
// By default, show a loading spinner.
return const CircularProgressIndicator();
},
appBar: AppBar(
title: const Text('Wetter in Harburg'),
),
),
),
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();
},
),
),
))),
);
}
}