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 ndFilterKey = "ndFilter";
static const evSourceTypeKey = "evSourceType"; static const evSourceTypeKey = "evSourceType";
static const stopTypeKey = "stopType";
static const cameraEvCalibrationKey = "cameraEvCalibration"; static const cameraEvCalibrationKey = "cameraEvCalibration";
static const lightSensorEvCalibrationKey = "lightSensorEvCalibration"; static const lightSensorEvCalibrationKey = "lightSensorEvCalibration";
static const meteringScreenLayoutKey = "meteringScreenLayout"; static const meteringScreenLayoutKey = "meteringScreenLayout";
@ -84,6 +85,9 @@ class UserPreferencesService {
bool get caffeine => _sharedPreferences.getBool(caffeineKey) ?? false; bool get caffeine => _sharedPreferences.getBool(caffeineKey) ?? false;
set caffeine(bool value) => _sharedPreferences.setBool(caffeineKey, value); 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 { MeteringScreenLayoutConfig get meteringScreenLayout {
final configJson = _sharedPreferences.getString(meteringScreenLayoutKey); final configJson = _sharedPreferences.getString(meteringScreenLayoutKey);
if (configJson != null) { if (configJson != null) {

View file

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