diff --git a/lib/data/shared_prefs_service.dart b/lib/data/shared_prefs_service.dart index 2662d7f..726fd63 100644 --- a/lib/data/shared_prefs_service.dart +++ b/lib/data/shared_prefs_service.dart @@ -7,6 +7,7 @@ import 'package:lightmeter/data/models/metering_screen_layout_config.dart'; import 'package:lightmeter/data/models/supported_locale.dart'; import 'package:lightmeter/data/models/theme_type.dart'; import 'package:lightmeter/data/models/volume_action.dart'; +import 'package:lightmeter/utils/color_to_int.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -155,7 +156,7 @@ class UserPreferencesService { set themeType(ThemeType value) => _sharedPreferences.setInt(themeTypeKey, value.index); Color get primaryColor => Color(_sharedPreferences.getInt(primaryColorKey) ?? 0xff2196f3); - set primaryColor(Color value) => _sharedPreferences.setInt(primaryColorKey, value.value); + set primaryColor(Color value) => _sharedPreferences.setInt(primaryColorKey, value.toInt()); bool get dynamicColor => _sharedPreferences.getBool(dynamicColorKey) ?? false; set dynamicColor(bool value) => _sharedPreferences.setBool(dynamicColorKey, value); diff --git a/lib/res/theme.dart b/lib/res/theme.dart index 9f9d392..c0e0a24 100644 --- a/lib/res/theme.dart +++ b/lib/res/theme.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:lightmeter/res/dimens.dart'; +import 'package:lightmeter/utils/color_to_int.dart'; import 'package:material_color_utilities/material_color_utilities.dart'; const primaryColorsList = [ @@ -75,7 +76,7 @@ ThemeData themeFrom(Color primaryColor, Brightness brightness) { ColorScheme _colorSchemeFromColor(Color primaryColor, Brightness brightness) { final scheme = SchemeTonalSpot( - sourceColorHct: Hct.fromInt(primaryColor.value), + sourceColorHct: Hct.fromInt(primaryColor.toInt()), isDark: brightness == Brightness.dark, contrastLevel: 0.0, ); diff --git a/lib/screens/settings/components/theme/components/primary_color/components/primary_color_picker_dialog/widget_dialog_picker_primary_color.dart b/lib/screens/settings/components/theme/components/primary_color/components/primary_color_picker_dialog/widget_dialog_picker_primary_color.dart index be9e8ad..8330eb6 100644 --- a/lib/screens/settings/components/theme/components/primary_color/components/primary_color_picker_dialog/widget_dialog_picker_primary_color.dart +++ b/lib/screens/settings/components/theme/components/primary_color/components/primary_color_picker_dialog/widget_dialog_picker_primary_color.dart @@ -3,6 +3,7 @@ import 'package:lightmeter/generated/l10n.dart'; import 'package:lightmeter/res/dimens.dart'; import 'package:lightmeter/res/theme.dart'; import 'package:lightmeter/screens/shared/filled_circle/widget_circle_filled.dart'; +import 'package:lightmeter/utils/color_to_int.dart'; class PrimaryColorDialogPicker extends StatefulWidget { const PrimaryColorDialogPicker({super.key}); @@ -45,7 +46,7 @@ class _PrimaryColorDialogPickerState extends State { padding: EdgeInsets.only(left: index == 0 ? 0 : Dimens.paddingS), child: _SelectableColorItem( color: color, - selected: color.value == _selected.value, + selected: color.toInt() == _selected.toInt(), onTap: () { setState(() { _selected = color; diff --git a/lib/utils/color_to_int.dart b/lib/utils/color_to_int.dart new file mode 100644 index 0000000..21e0589 --- /dev/null +++ b/lib/utils/color_to_int.dart @@ -0,0 +1,12 @@ +import 'dart:ui'; + +extension ColorToInt on Color { + int toInt() { + final a = (this.a * 255).round(); + final r = (this.r * 255).round(); + final g = (this.g * 255).round(); + final b = (this.b * 255).round(); + + return (a << 24) | (r << 16) | (g << 8) | b; + } +} diff --git a/screenshots/generate_screenshots.dart b/screenshots/generate_screenshots.dart index a47b9e9..d80159c 100644 --- a/screenshots/generate_screenshots.dart +++ b/screenshots/generate_screenshots.dart @@ -22,6 +22,7 @@ import 'package:lightmeter/screens/metering/screen_metering.dart'; import 'package:lightmeter/screens/settings/screen_settings.dart'; import 'package:lightmeter/screens/shared/animated_circular_button/widget_button_circular_animated.dart'; import 'package:lightmeter/screens/timer/screen_timer.dart'; +import 'package:lightmeter/utils/color_to_int.dart'; import 'package:lightmeter/utils/platform_utils.dart'; import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -77,7 +78,7 @@ void main() { /// Theme settings UserPreferencesService.themeTypeKey: theme.index, - UserPreferencesService.primaryColorKey: color.value, + UserPreferencesService.primaryColorKey: color.toInt(), UserPreferencesService.dynamicColorKey: false, UserPreferencesService.seenChangelogVersionKey: await const PlatformUtils().version, @@ -190,7 +191,7 @@ extension on WidgetTester { name: name, deviceName: const String.fromEnvironment('deviceName'), platformFolder: _platformFolder, - backgroundColor: backgroundColor.value.toRadixString(16), + backgroundColor: backgroundColor.toInt().toRadixString(16), isDark: theme.brightness == Brightness.dark, ).toString(), );