ML-81 Unsaved fractional stops (#83)

* save stop type to sharedPrefs

* tests
This commit is contained in:
Vadim 2023-06-23 10:47:34 +02:00 committed by GitHub
parent 0c58134733
commit 2735f0b66f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 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;
}
}

View file

@ -164,6 +164,25 @@ void main() {
});
});
group('stopType', () {
test('get default', () {
when(() => sharedPreferences.getInt(UserPreferencesService.stopTypeKey)).thenReturn(null);
expect(service.stopType, StopType.third);
});
test('get', () {
when(() => sharedPreferences.getInt(UserPreferencesService.stopTypeKey)).thenReturn(1);
expect(service.stopType, StopType.half);
});
test('set', () {
when(() => sharedPreferences.setInt(UserPreferencesService.stopTypeKey, 0))
.thenAnswer((_) => Future.value(true));
service.stopType = StopType.full;
verify(() => sharedPreferences.setInt(UserPreferencesService.stopTypeKey, 0)).called(1);
});
});
group('meteringScreenLayout', () {
test('get default', () {
when(