save stop type to sharedPrefs

This commit is contained in:
Vadim 2023-06-23 10:41:12 +02:00
parent 0c58134733
commit 80fe288bd0
2 changed files with 17 additions and 7 deletions

View file

@ -14,6 +14,7 @@ class UserPreferencesService {
static const ndFilterKey = "ndFilter";
static const evSourceTypeKey = "evSourceType";
static const stopTypeKey = "stopType";
static const cameraEvCalibrationKey = "cameraEvCalibration";
static const lightSensorEvCalibrationKey = "lightSensorEvCalibration";
static const meteringScreenLayoutKey = "meteringScreenLayout";
@ -84,6 +85,9 @@ class UserPreferencesService {
bool get caffeine => _sharedPreferences.getBool(caffeineKey) ?? false;
set caffeine(bool value) => _sharedPreferences.setBool(caffeineKey, value);
StopType get stopType => StopType.values[_sharedPreferences.getInt(stopTypeKey) ?? 2];
set stopType(StopType value) => _sharedPreferences.setInt(stopTypeKey, value.index);
MeteringScreenLayoutConfig get meteringScreenLayout {
final configJson = _sharedPreferences.getString(meteringScreenLayoutKey);
if (configJson != null) {

View file

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:lightmeter/data/shared_prefs_service.dart';
import 'package:lightmeter/utils/inherited_generics.dart';
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
@ -16,14 +17,12 @@ class StopTypeProvider extends StatefulWidget {
}
class StopTypeProviderState extends State<StopTypeProvider> {
StopType _stopType = StopType.third;
late StopType _stopType;
StopType get stopType => _stopType;
void set(StopType type) {
setState(() {
_stopType = type;
});
@override
void initState() {
super.initState();
_stopType = context.get<UserPreferencesService>().stopType;
}
@override
@ -33,4 +32,11 @@ class StopTypeProviderState extends State<StopTypeProvider> {
child: widget.child,
);
}
void set(StopType type) {
setState(() {
_stopType = type;
});
context.get<UserPreferencesService>().stopType = type;
}
}