Load user preferences at start of app. Manage locations: user is able to add locations by lat and lon to shared preferences
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:wetter/services/user_preferences.dart';
|
||||
|
||||
class SettingsForm extends StatefulWidget {
|
||||
const SettingsForm({Key? key}) : super(key: key);
|
||||
@@ -9,20 +9,13 @@ class SettingsForm extends StatefulWidget {
|
||||
}
|
||||
|
||||
class SettingsFormState extends State<SettingsForm> {
|
||||
SharedPreferences? prefs;
|
||||
int _daysToLoad = 7;
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_daysToLoad = UserPreferences.preferences!.getInt("daysToLoad") ?? 7;
|
||||
super.initState();
|
||||
initializePreferences().whenComplete(() => setState(() {
|
||||
_daysToLoad = prefs?.getInt("daysToLoad") ?? 7;
|
||||
}));
|
||||
}
|
||||
|
||||
Future<void> initializePreferences() async {
|
||||
prefs = await SharedPreferences.getInstance();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -35,12 +28,13 @@ class SettingsFormState extends State<SettingsForm> {
|
||||
value: _daysToLoad.toDouble(),
|
||||
min: 1.0,
|
||||
max: 14.0,
|
||||
divisions: 14,
|
||||
divisions: 13,
|
||||
label: _daysToLoad.round().toString(),
|
||||
onChanged: (double value) {
|
||||
setState(() {
|
||||
_daysToLoad = value.round();
|
||||
prefs?.setInt("daysToLoad", _daysToLoad);
|
||||
UserPreferences.preferences!
|
||||
.setInt("daysToLoad", _daysToLoad);
|
||||
});
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user