mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2025-01-18 19:30:43 +00:00
replaced deprecated color value getter
This commit is contained in:
parent
97f802273c
commit
2b6b27bcf4
5 changed files with 21 additions and 5 deletions
|
@ -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/supported_locale.dart';
|
||||||
import 'package:lightmeter/data/models/theme_type.dart';
|
import 'package:lightmeter/data/models/theme_type.dart';
|
||||||
import 'package:lightmeter/data/models/volume_action.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:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
@ -155,7 +156,7 @@ class UserPreferencesService {
|
||||||
set themeType(ThemeType value) => _sharedPreferences.setInt(themeTypeKey, value.index);
|
set themeType(ThemeType value) => _sharedPreferences.setInt(themeTypeKey, value.index);
|
||||||
|
|
||||||
Color get primaryColor => Color(_sharedPreferences.getInt(primaryColorKey) ?? 0xff2196f3);
|
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;
|
bool get dynamicColor => _sharedPreferences.getBool(dynamicColorKey) ?? false;
|
||||||
set dynamicColor(bool value) => _sharedPreferences.setBool(dynamicColorKey, value);
|
set dynamicColor(bool value) => _sharedPreferences.setBool(dynamicColorKey, value);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:lightmeter/res/dimens.dart';
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
|
import 'package:lightmeter/utils/color_to_int.dart';
|
||||||
import 'package:material_color_utilities/material_color_utilities.dart';
|
import 'package:material_color_utilities/material_color_utilities.dart';
|
||||||
|
|
||||||
const primaryColorsList = [
|
const primaryColorsList = [
|
||||||
|
@ -75,7 +76,7 @@ ThemeData themeFrom(Color primaryColor, Brightness brightness) {
|
||||||
|
|
||||||
ColorScheme _colorSchemeFromColor(Color primaryColor, Brightness brightness) {
|
ColorScheme _colorSchemeFromColor(Color primaryColor, Brightness brightness) {
|
||||||
final scheme = SchemeTonalSpot(
|
final scheme = SchemeTonalSpot(
|
||||||
sourceColorHct: Hct.fromInt(primaryColor.value),
|
sourceColorHct: Hct.fromInt(primaryColor.toInt()),
|
||||||
isDark: brightness == Brightness.dark,
|
isDark: brightness == Brightness.dark,
|
||||||
contrastLevel: 0.0,
|
contrastLevel: 0.0,
|
||||||
);
|
);
|
||||||
|
|
|
@ -3,6 +3,7 @@ import 'package:lightmeter/generated/l10n.dart';
|
||||||
import 'package:lightmeter/res/dimens.dart';
|
import 'package:lightmeter/res/dimens.dart';
|
||||||
import 'package:lightmeter/res/theme.dart';
|
import 'package:lightmeter/res/theme.dart';
|
||||||
import 'package:lightmeter/screens/shared/filled_circle/widget_circle_filled.dart';
|
import 'package:lightmeter/screens/shared/filled_circle/widget_circle_filled.dart';
|
||||||
|
import 'package:lightmeter/utils/color_to_int.dart';
|
||||||
|
|
||||||
class PrimaryColorDialogPicker extends StatefulWidget {
|
class PrimaryColorDialogPicker extends StatefulWidget {
|
||||||
const PrimaryColorDialogPicker({super.key});
|
const PrimaryColorDialogPicker({super.key});
|
||||||
|
@ -45,7 +46,7 @@ class _PrimaryColorDialogPickerState extends State<PrimaryColorDialogPicker> {
|
||||||
padding: EdgeInsets.only(left: index == 0 ? 0 : Dimens.paddingS),
|
padding: EdgeInsets.only(left: index == 0 ? 0 : Dimens.paddingS),
|
||||||
child: _SelectableColorItem(
|
child: _SelectableColorItem(
|
||||||
color: color,
|
color: color,
|
||||||
selected: color.value == _selected.value,
|
selected: color.toInt() == _selected.toInt(),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
_selected = color;
|
_selected = color;
|
||||||
|
|
12
lib/utils/color_to_int.dart
Normal file
12
lib/utils/color_to_int.dart
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,6 +22,7 @@ import 'package:lightmeter/screens/metering/screen_metering.dart';
|
||||||
import 'package:lightmeter/screens/settings/screen_settings.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/shared/animated_circular_button/widget_button_circular_animated.dart';
|
||||||
import 'package:lightmeter/screens/timer/screen_timer.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:lightmeter/utils/platform_utils.dart';
|
||||||
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
import 'package:m3_lightmeter_resources/m3_lightmeter_resources.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
@ -77,7 +78,7 @@ void main() {
|
||||||
|
|
||||||
/// Theme settings
|
/// Theme settings
|
||||||
UserPreferencesService.themeTypeKey: theme.index,
|
UserPreferencesService.themeTypeKey: theme.index,
|
||||||
UserPreferencesService.primaryColorKey: color.value,
|
UserPreferencesService.primaryColorKey: color.toInt(),
|
||||||
UserPreferencesService.dynamicColorKey: false,
|
UserPreferencesService.dynamicColorKey: false,
|
||||||
|
|
||||||
UserPreferencesService.seenChangelogVersionKey: await const PlatformUtils().version,
|
UserPreferencesService.seenChangelogVersionKey: await const PlatformUtils().version,
|
||||||
|
@ -190,7 +191,7 @@ extension on WidgetTester {
|
||||||
name: name,
|
name: name,
|
||||||
deviceName: const String.fromEnvironment('deviceName'),
|
deviceName: const String.fromEnvironment('deviceName'),
|
||||||
platformFolder: _platformFolder,
|
platformFolder: _platformFolder,
|
||||||
backgroundColor: backgroundColor.value.toRadixString(16),
|
backgroundColor: backgroundColor.toInt().toRadixString(16),
|
||||||
isDark: theme.brightness == Brightness.dark,
|
isDark: theme.brightness == Brightness.dark,
|
||||||
).toString(),
|
).toString(),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue