mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-21 15:00:40 +00:00
ML-81 Unsaved fractional stops (#83)
* save stop type to sharedPrefs * tests
This commit is contained in:
parent
0c58134733
commit
2735f0b66f
3 changed files with 36 additions and 7 deletions
|
@ -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) {
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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', () {
|
group('meteringScreenLayout', () {
|
||||||
test('get default', () {
|
test('get default', () {
|
||||||
when(
|
when(
|
||||||
|
|
Loading…
Reference in a new issue