diff --git a/lib/data/shared_prefs_service.dart b/lib/data/shared_prefs_service.dart index e90df0e..8fbb6af 100644 --- a/lib/data/shared_prefs_service.dart +++ b/lib/data/shared_prefs_service.dart @@ -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) { diff --git a/lib/providers/stop_type_provider.dart b/lib/providers/stop_type_provider.dart index 690f65f..3b20dd5 100644 --- a/lib/providers/stop_type_provider.dart +++ b/lib/providers/stop_type_provider.dart @@ -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 { - 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().stopType; } @override @@ -33,4 +32,11 @@ class StopTypeProviderState extends State { child: widget.child, ); } + + void set(StopType type) { + setState(() { + _stopType = type; + }); + context.get().stopType = type; + } }