diff --git a/lib/data/shared_prefs_service.dart b/lib/data/shared_prefs_service.dart index 443f2e5..3bb6dfb 100644 --- a/lib/data/shared_prefs_service.dart +++ b/lib/data/shared_prefs_service.dart @@ -16,6 +16,7 @@ class UserPreferencesService { static const evSourceTypeKey = "evSourceType"; static const stopTypeKey = "stopType"; + static const showEv100Key = "showEv100"; static const cameraEvCalibrationKey = "cameraEvCalibration"; static const lightSensorEvCalibrationKey = "lightSensorEvCalibration"; static const meteringScreenLayoutKey = "meteringScreenLayout"; @@ -84,6 +85,9 @@ class UserPreferencesService { StopType get stopType => StopType.values[_sharedPreferences.getInt(stopTypeKey) ?? 2]; set stopType(StopType value) => _sharedPreferences.setInt(stopTypeKey, value.index); + bool get showEv100 => _sharedPreferences.getBool(showEv100Key) ?? false; + set showEv100(bool value) => _sharedPreferences.setBool(showEv100Key, value); + MeteringScreenLayoutConfig get meteringScreenLayout { final configJson = _sharedPreferences.getString(meteringScreenLayoutKey); if (configJson != null) { diff --git a/lib/providers/user_preferences_provider.dart b/lib/providers/user_preferences_provider.dart index 764f282..76eaa23 100644 --- a/lib/providers/user_preferences_provider.dart +++ b/lib/providers/user_preferences_provider.dart @@ -53,6 +53,10 @@ class UserPreferencesProvider extends StatefulWidget { return _inheritFromEnumsModel(context, _Aspect.stopType).stopType; } + static bool showEv100Of(BuildContext context) { + return _inheritFromEnumsModel(context, _Aspect.showEv100).showEv100; + } + static CameraFeaturesConfig cameraConfigOf(BuildContext context) { return context.findAncestorWidgetOfExactType<_CameraFeaturesModel>()!.data; } @@ -83,6 +87,7 @@ class UserPreferencesProvider extends StatefulWidget { class _UserPreferencesProviderState extends State with WidgetsBindingObserver { late EvSourceType _evSourceType; late StopType _stopType = widget.userPreferencesService.stopType; + late bool _showEv100 = widget.userPreferencesService.showEv100; late MeteringScreenLayoutConfig _meteringScreenLayout = widget.userPreferencesService.meteringScreenLayout; late CameraFeaturesConfig _cameraFeatures = widget.userPreferencesService.cameraFeatures; late SupportedLocale _locale = widget.userPreferencesService.locale; @@ -135,6 +140,7 @@ class _UserPreferencesProviderState extends State with evSourceType: _evSourceType, locale: _locale, primaryColor: dynamicPrimaryColor ?? _primaryColor, + showEv100: _showEv100, stopType: _stopType, themeType: _themeType, child: _MeteringScreenLayoutModel( @@ -201,6 +207,13 @@ class _UserPreferencesProviderState extends State with widget.userPreferencesService.primaryColor = primaryColor; } + void toggleShowEV100() { + setState(() { + _showEv100 = !_showEv100; + }); + widget.userPreferencesService.showEv100 = _showEv100; + } + void setStopType(StopType stopType) { setState(() { _stopType = stopType; @@ -231,6 +244,7 @@ enum _Aspect { dynamicColorState, evSourceType, locale, + showEv100, stopType, theme, themeType, @@ -240,6 +254,7 @@ class _UserPreferencesModel extends InheritedModel<_Aspect> { final DynamicColorState dynamicColorState; final EvSourceType evSourceType; final SupportedLocale locale; + final bool showEv100; final StopType stopType; final ThemeType themeType; @@ -252,6 +267,7 @@ class _UserPreferencesModel extends InheritedModel<_Aspect> { required this.evSourceType, required this.locale, required Color primaryColor, + required this.showEv100, required this.stopType, required this.themeType, required super.child, @@ -267,6 +283,7 @@ class _UserPreferencesModel extends InheritedModel<_Aspect> { evSourceType != oldWidget.evSourceType || locale != oldWidget.locale || _primaryColor != oldWidget._primaryColor || + showEv100 != oldWidget.showEv100 || stopType != oldWidget.stopType || themeType != oldWidget.themeType; } @@ -279,6 +296,7 @@ class _UserPreferencesModel extends InheritedModel<_Aspect> { return (dependencies.contains(_Aspect.dynamicColorState) && dynamicColorState != oldWidget.dynamicColorState) || (dependencies.contains(_Aspect.evSourceType) && evSourceType != oldWidget.evSourceType) || (dependencies.contains(_Aspect.locale) && locale != oldWidget.locale) || + (dependencies.contains(_Aspect.showEv100) && showEv100 != oldWidget.showEv100) || (dependencies.contains(_Aspect.stopType) && stopType != oldWidget.stopType) || (dependencies.contains(_Aspect.theme) && (_brightness != oldWidget._brightness || _primaryColor != oldWidget._primaryColor)) || diff --git a/test/data/shared_prefs_service_test.dart b/test/data/shared_prefs_service_test.dart index 96f4e1e..269d002 100644 --- a/test/data/shared_prefs_service_test.dart +++ b/test/data/shared_prefs_service_test.dart @@ -181,6 +181,25 @@ void main() { }); }); + group('showEv100', () { + test('get default', () { + when(() => sharedPreferences.getBool(UserPreferencesService.showEv100Key)).thenReturn(null); + expect(service.showEv100, false); + }); + + test('get', () { + when(() => sharedPreferences.getBool(UserPreferencesService.showEv100Key)).thenReturn(true); + expect(service.showEv100, true); + }); + + test('set', () { + when(() => sharedPreferences.setBool(UserPreferencesService.showEv100Key, false)) + .thenAnswer((_) => Future.value(true)); + service.showEv100 = false; + verify(() => sharedPreferences.setBool(UserPreferencesService.showEv100Key, false)).called(1); + }); + }); + group('meteringScreenLayout', () { test('get default', () { when( diff --git a/test/providers/user_preferences_provider_test.dart b/test/providers/user_preferences_provider_test.dart index b6dc2ae..cb9408c 100644 --- a/test/providers/user_preferences_provider_test.dart +++ b/test/providers/user_preferences_provider_test.dart @@ -164,6 +164,27 @@ void main() { }, ); + testWidgets( + 'Toggle EV100', + (tester) async { + when(() => mockUserPreferencesService.showEv100).thenReturn(false); + await pumpTestWidget( + tester, + builder: (context) => ElevatedButton( + onPressed: () => UserPreferencesProvider.of(context).toggleShowEV100(), + child: Text('${UserPreferencesProvider.showEv100Of(context)}'), + ), + ); + await tester.pumpAndSettle(); + expect(find.text("${false}"), findsOneWidget); + + await tester.tap(find.text("${false}")); + await tester.pumpAndSettle(); + expect(find.text("${true}"), findsOneWidget); + verify(() => mockUserPreferencesService.showEv100 = true).called(1); + }, + ); + testWidgets( 'Set metering screen layout config', (tester) async {