dynamic colors -> dynamic color

This commit is contained in:
Vadim 2023-01-23 21:39:55 +03:00
parent 7d7cab0e49
commit 5bcdfb2b1d
6 changed files with 31 additions and 31 deletions

View file

@ -1 +1 @@
enum DynamicColorsState { unavailable, enabled, disabled }
enum DynamicColorState { unavailable, enabled, disabled }

View file

@ -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);
}

View file

@ -22,7 +22,7 @@
"haptics": "Haptics",
"theme": "Theme",
"chooseTheme": "Choose theme",
"dynamicColors": "Dynamic colors",
"dynamicColor": "Dynamic color",
"themeLight": "Light",
"themeDark": "Dark",
"themeSystemDefault": "System default",

View file

@ -26,13 +26,13 @@ class ThemeProvider extends StatefulWidget {
class ThemeProviderState extends State<ThemeProvider> {
late final _themeTypeNotifier = ValueNotifier<ThemeType>(context.read<UserPreferencesService>().themeType);
late final _dynamicColorsNotifier = ValueNotifier<bool>(context.read<UserPreferencesService>().dynamicColors);
late final _dynamicColorNotifier = ValueNotifier<bool>(context.read<UserPreferencesService>().dynamicColor);
late final _primaryColorNotifier = ValueNotifier<Color>(const Color(0xFF2196f3));
@override
void dispose() {
_themeTypeNotifier.dispose();
_dynamicColorsNotifier.dispose();
_dynamicColorNotifier.dispose();
_primaryColorNotifier.dispose();
super.dispose();
}
@ -44,9 +44,9 @@ class ThemeProviderState extends State<ThemeProvider> {
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<ThemeProvider> {
}
}
void enableDynamicColors(bool enable) {
_dynamicColorsNotifier.value = enable;
context.read<UserPreferencesService>().dynamicColors = enable;
void enableDynamicColor(bool enable) {
_dynamicColorNotifier.value = enable;
context.read<UserPreferencesService>().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,

View file

@ -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>() == DynamicColorsState.unavailable) {
if (context.read<DynamicColorState>() == 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>() == DynamicColorsState.enabled,
onChanged: ThemeProvider.of(context).enableDynamicColors,
title: Text(S.of(context).dynamicColor),
value: context.watch<DynamicColorState>() == DynamicColorState.enabled,
onChanged: ThemeProvider.of(context).enableDynamicColor,
);
}
}

View file

@ -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(