Slider in settings to adjust days of forecast loaded. Settings are saved and loaded
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class SettingsForm extends StatefulWidget {
|
||||
const SettingsForm({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
SettingsFormState createState() => SettingsFormState();
|
||||
}
|
||||
|
||||
class SettingsFormState extends State<SettingsForm> {
|
||||
SharedPreferences? prefs;
|
||||
int _daysToLoad = 7;
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
initializePreferences().whenComplete(() => setState(() {
|
||||
_daysToLoad = prefs?.getInt("daysToLoad") ?? 7;
|
||||
}));
|
||||
}
|
||||
|
||||
Future<void> initializePreferences() async {
|
||||
prefs = await SharedPreferences.getInstance();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: [
|
||||
Slider(
|
||||
value: _daysToLoad.toDouble(),
|
||||
min: 1.0,
|
||||
max: 14.0,
|
||||
divisions: 14,
|
||||
label: _daysToLoad.round().toString(),
|
||||
onChanged: (double value) {
|
||||
setState(() {
|
||||
_daysToLoad = value.round();
|
||||
prefs?.setInt("daysToLoad", _daysToLoad);
|
||||
});
|
||||
},
|
||||
)
|
||||
],
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user