replaced deprecated color value getter

This commit is contained in:
Vadim 2025-01-06 15:14:00 +01:00
parent 97f802273c
commit 2b6b27bcf4
5 changed files with 21 additions and 5 deletions

View file

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

View file

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

View file

@ -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<PrimaryColorDialogPicker> {
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;

View file

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

View file

@ -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(),
);