From 5bcdfb2b1da653879344cdc66809bc9c9ead87e5 Mon Sep 17 00:00:00 2001 From: Vadim <44135514+vodemn@users.noreply.github.com> Date: Mon, 23 Jan 2023 21:39:55 +0300 Subject: [PATCH] dynamic colors -> dynamic color --- lib/data/models/dynamic_colors_state.dart | 2 +- lib/data/shared_prefs_service.dart | 6 ++-- lib/l10n/intl_en.arb | 2 +- lib/res/theme.dart | 34 +++++++++---------- .../widget_list_tile_dynamic_color.dart} | 14 ++++---- lib/screens/settings/screen_settings.dart | 4 +-- 6 files changed, 31 insertions(+), 31 deletions(-) rename lib/screens/settings/components/{dynamic_colors/widget_list_tile_dynamic_colors.dart => dynamic_color/widget_list_tile_dynamic_color.dart} (61%) diff --git a/lib/data/models/dynamic_colors_state.dart b/lib/data/models/dynamic_colors_state.dart index a9fb712..39b36ff 100644 --- a/lib/data/models/dynamic_colors_state.dart +++ b/lib/data/models/dynamic_colors_state.dart @@ -1 +1 @@ -enum DynamicColorsState { unavailable, enabled, disabled } +enum DynamicColorState { unavailable, enabled, disabled } diff --git a/lib/data/shared_prefs_service.dart b/lib/data/shared_prefs_service.dart index 2e67fa4..d8fe310 100644 --- a/lib/data/shared_prefs_service.dart +++ b/lib/data/shared_prefs_service.dart @@ -10,7 +10,7 @@ class UserPreferencesService { static const _hapticsKey = "haptics"; static const _themeTypeKey = "themeType"; - static const _dynamicColorsKey = "dynamicColors"; + static const _dynamicColorKey = "dynamicColor"; final SharedPreferences _sharedPreferences; @@ -28,6 +28,6 @@ class UserPreferencesService { ThemeType get themeType => ThemeType.values[_sharedPreferences.getInt(_themeTypeKey) ?? 0]; set themeType(ThemeType value) => _sharedPreferences.setInt(_themeTypeKey, value.index); - bool get dynamicColors => _sharedPreferences.getBool(_dynamicColorsKey) ?? false; - set dynamicColors(bool value) => _sharedPreferences.setBool(_dynamicColorsKey, value); + bool get dynamicColor => _sharedPreferences.getBool(_dynamicColorKey) ?? false; + set dynamicColor(bool value) => _sharedPreferences.setBool(_dynamicColorKey, value); } diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 3dc9941..0818a94 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -22,7 +22,7 @@ "haptics": "Haptics", "theme": "Theme", "chooseTheme": "Choose theme", - "dynamicColors": "Dynamic colors", + "dynamicColor": "Dynamic color", "themeLight": "Light", "themeDark": "Dark", "themeSystemDefault": "System default", diff --git a/lib/res/theme.dart b/lib/res/theme.dart index 85196d6..a3a36d6 100644 --- a/lib/res/theme.dart +++ b/lib/res/theme.dart @@ -26,13 +26,13 @@ class ThemeProvider extends StatefulWidget { class ThemeProviderState extends State { late final _themeTypeNotifier = ValueNotifier(context.read().themeType); - late final _dynamicColorsNotifier = ValueNotifier(context.read().dynamicColors); + late final _dynamicColorNotifier = ValueNotifier(context.read().dynamicColor); late final _primaryColorNotifier = ValueNotifier(const Color(0xFF2196f3)); @override void dispose() { _themeTypeNotifier.dispose(); - _dynamicColorsNotifier.dispose(); + _dynamicColorNotifier.dispose(); _primaryColorNotifier.dispose(); super.dispose(); } @@ -44,9 +44,9 @@ class ThemeProviderState extends State { builder: (_, themeType, __) => Provider.value( value: themeType, child: ValueListenableBuilder( - valueListenable: _dynamicColorsNotifier, - builder: (_, useDynamicColors, __) => _DynamicColorsProvider( - useDynamicColors: useDynamicColors, + valueListenable: _dynamicColorNotifier, + builder: (_, useDynamicColor, __) => _DynamicColorProvider( + useDynamicColor: useDynamicColor, themeBrightness: _themeBrightness, builder: (_, dynamicPrimaryColor) => ValueListenableBuilder( valueListenable: _primaryColorNotifier, @@ -78,19 +78,19 @@ class ThemeProviderState extends State { } } - void enableDynamicColors(bool enable) { - _dynamicColorsNotifier.value = enable; - context.read().dynamicColors = enable; + void enableDynamicColor(bool enable) { + _dynamicColorNotifier.value = enable; + context.read().dynamicColor = enable; } } -class _DynamicColorsProvider extends StatelessWidget { - final bool useDynamicColors; +class _DynamicColorProvider extends StatelessWidget { + final bool useDynamicColor; final Brightness themeBrightness; final Widget Function(BuildContext context, Color? primaryColor) builder; - const _DynamicColorsProvider({ - required this.useDynamicColors, + const _DynamicColorProvider({ + required this.useDynamicColor, required this.themeBrightness, required this.builder, }); @@ -99,19 +99,19 @@ class _DynamicColorsProvider extends StatelessWidget { Widget build(BuildContext context) { return DynamicColorBuilder( builder: (lightDynamic, darkDynamic) { - late final DynamicColorsState state; + late final DynamicColorState state; late final Color? dynamicPrimaryColor; if (lightDynamic != null && darkDynamic != null) { - if (useDynamicColors) { + if (useDynamicColor) { dynamicPrimaryColor = (themeBrightness == Brightness.light ? lightDynamic : darkDynamic).primary; - state = DynamicColorsState.enabled; + state = DynamicColorState.enabled; } else { dynamicPrimaryColor = null; - state = DynamicColorsState.disabled; + state = DynamicColorState.disabled; } } else { dynamicPrimaryColor = null; - state = DynamicColorsState.unavailable; + state = DynamicColorState.unavailable; } return Provider.value( value: state, diff --git a/lib/screens/settings/components/dynamic_colors/widget_list_tile_dynamic_colors.dart b/lib/screens/settings/components/dynamic_color/widget_list_tile_dynamic_color.dart similarity index 61% rename from lib/screens/settings/components/dynamic_colors/widget_list_tile_dynamic_colors.dart rename to lib/screens/settings/components/dynamic_color/widget_list_tile_dynamic_color.dart index 876bc79..44bf25d 100644 --- a/lib/screens/settings/components/dynamic_colors/widget_list_tile_dynamic_colors.dart +++ b/lib/screens/settings/components/dynamic_color/widget_list_tile_dynamic_color.dart @@ -4,18 +4,18 @@ import 'package:lightmeter/data/models/dynamic_colors_state.dart'; import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/res/theme.dart'; -class DynamicColorsListTile extends StatelessWidget { - const DynamicColorsListTile({super.key}); +class DynamicColorListTile extends StatelessWidget { + const DynamicColorListTile({super.key}); @override Widget build(BuildContext context) { - if (context.read() == DynamicColorsState.unavailable) { + if (context.read() == DynamicColorState.unavailable) { return Opacity( opacity: 0.5, child: IgnorePointer( child: SwitchListTile( secondary: const Icon(Icons.colorize), - title: Text(S.of(context).dynamicColors), + title: Text(S.of(context).dynamicColor), value: false, enableFeedback: false, onChanged: (value) {}, @@ -25,9 +25,9 @@ class DynamicColorsListTile extends StatelessWidget { } return SwitchListTile( secondary: const Icon(Icons.colorize), - title: Text(S.of(context).dynamicColors), - value: context.watch() == DynamicColorsState.enabled, - onChanged: ThemeProvider.of(context).enableDynamicColors, + title: Text(S.of(context).dynamicColor), + value: context.watch() == DynamicColorState.enabled, + onChanged: ThemeProvider.of(context).enableDynamicColor, ); } } diff --git a/lib/screens/settings/screen_settings.dart b/lib/screens/settings/screen_settings.dart index 8ebaaca..43ae654 100644 --- a/lib/screens/settings/screen_settings.dart +++ b/lib/screens/settings/screen_settings.dart @@ -6,7 +6,7 @@ import 'components/haptics/provider_list_tile_haptics.dart'; import 'components/report_issue/widget_list_tile_report_issue.dart'; import 'components/shared/settings_section/widget_settings_section.dart'; import 'components/source_code/widget_list_tile_source_code.dart'; -import 'components/dynamic_colors/widget_list_tile_dynamic_colors.dart'; +import 'components/dynamic_color/widget_list_tile_dynamic_color.dart'; import 'components/theme_type/widget_list_tile_theme_type.dart'; import 'components/version/widget_list_tile_version.dart'; import 'components/fractional_stops/widget_list_tile_fractional_stops.dart'; @@ -60,7 +60,7 @@ class SettingsScreen extends StatelessWidget { title: S.of(context).theme, children: const [ ThemeTypeListTile(), - DynamicColorsListTile(), + DynamicColorListTile(), ], ), SettingsSection(