show more days of forecast, enable reload of forecasts
This commit is contained in:
+36
-20
@@ -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();
|
||||
},
|
||||
),
|
||||
),
|
||||
))),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user