Slider in settings to adjust days of forecast loaded. Settings are saved and loaded
This commit is contained in:
+17
-5
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:wetter/components/compact_weather_data.dart';
|
||||
import 'package:wetter/components/main_menu.dart';
|
||||
import 'package:wetter/models/daily_weather_model.dart';
|
||||
@@ -14,13 +15,23 @@ class MyApp extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MyAppState extends State<MyApp> {
|
||||
SharedPreferences? prefs;
|
||||
int _daysToLoad = 7;
|
||||
late Future<List<DailyWeatherModel>> dailyWeather;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
dailyWeather = BrightSkyAPI.fetchForecastForTimeRange(
|
||||
DateTime.now(), DateTime.now().add(const Duration(days: 7)));
|
||||
initializePreferences();
|
||||
dailyWeather =
|
||||
BrightSkyAPI.fetchForecastForTimeRange(DateTime.now(), _daysToLoad);
|
||||
}
|
||||
|
||||
Future<void> initializePreferences() async {
|
||||
prefs = await SharedPreferences.getInstance();
|
||||
setState(() {
|
||||
_daysToLoad = prefs!.getInt("daysToLoad") ?? 7;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -44,9 +55,9 @@ class _MyAppState extends State<MyApp> {
|
||||
onRefresh: () {
|
||||
return Future(() {
|
||||
setState(() {
|
||||
_daysToLoad = prefs?.getInt("daysToLoad") ?? 7;
|
||||
dailyWeather = BrightSkyAPI.fetchForecastForTimeRange(
|
||||
DateTime.now(),
|
||||
DateTime.now().add(const Duration(days: 7)));
|
||||
DateTime.now(), _daysToLoad);
|
||||
});
|
||||
});
|
||||
},
|
||||
@@ -54,7 +65,8 @@ class _MyAppState extends State<MyApp> {
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
child: Center(
|
||||
child: FutureBuilder<List<DailyWeatherModel>>(
|
||||
future: dailyWeather,
|
||||
future: BrightSkyAPI.fetchForecastForTimeRange(
|
||||
DateTime.now(), _daysToLoad),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return Column(
|
||||
|
||||
Reference in New Issue
Block a user