From ae7c9c75457731119a503bd545ce72292d417ceb Mon Sep 17 00:00:00 2001 From: Felix Holz Date: Tue, 27 Feb 2024 21:21:10 +0100 Subject: [PATCH] work on material color theme --- lib/main.dart | 13 ++++++ lib/theme/frederic_theme.dart | 83 +++++++++++++++++++++-------------- pubspec.yaml | 2 + 3 files changed, 66 insertions(+), 32 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index a689a72..68655b7 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,6 @@ import 'dart:isolate'; +import 'package:dynamic_color/dynamic_color.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_crashlytics/firebase_crashlytics.dart'; @@ -24,6 +25,7 @@ import 'package:get_it/get_it.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:sheet/route.dart'; +import 'package:system_theme/system_theme.dart'; final getIt = GetIt.instance; @@ -102,6 +104,17 @@ void main() async { if (themeID != null && themeID is int) { _colorTheme = FredericColorTheme.find(themeID); } + + await SystemTheme.accentColor.load(); + final palette = await DynamicColorPlugin.getCorePalette(); + _colorTheme = FredericColorTheme.fromColor(palette!); + + // DynamicColorPlugin.getCorePalette().then((palette) { + // if (palette != null) { + // _colorTheme = FredericColorTheme.fromColor(palette); + // } + // }); + // == Load Startup Preferences == End == // == Disable Crashlytics in debug mode diff --git a/lib/theme/frederic_theme.dart b/lib/theme/frederic_theme.dart index f96a71e..1085287 100644 --- a/lib/theme/frederic_theme.dart +++ b/lib/theme/frederic_theme.dart @@ -1,4 +1,6 @@ import 'package:flutter/material.dart'; +import 'package:material_color_utilities/material_color_utilities.dart'; +import 'package:system_theme/system_theme.dart'; class FredericColorTheme { FredericColorTheme.blue( @@ -326,38 +328,6 @@ class FredericColorTheme { this.greyTextColor = const Color(0xFFC4C4C4), this.cardBorderColor = Colors.transparent}); - FredericColorTheme.fromColor(Color color, bool dark) { - ColorScheme scheme = ColorScheme.fromSeed( - seedColor: color, - brightness: dark ? Brightness.dark : Brightness.light); - bool colorful = dark || false; - this.name = "Custom"; - this.uid = 999; - - this.mainColor = scheme.primary; - this.mainColorInText = scheme.primary; - this.mainColorLight = scheme.primary.withAlpha(15); - this.accentColor = scheme.secondary; - this.accentColorLight = scheme.secondary.withAlpha(15); - this.positiveColor = scheme.tertiary; - this.positiveColorLight = scheme.tertiary.withAlpha(15); - this.negativeColor = scheme.error; - this.negativeColorLight = scheme.error.withAlpha(15); - this.dividerColor = scheme.outline; - this.backgroundColor = scheme.background; - this.cardBackgroundColor = scheme.tertiary.withOpacity(0.038); - this.greyColor = scheme.onSurface; - this.disabledGreyColor = const Color(0x66A5A5A5); - this.textColor = scheme.onBackground; - this.textColorBright = Colors.black; - this.textColorColorfulBackground = - colorful ? scheme.onPrimary : scheme.onBackground; - this.isDark = dark; - this.isColorful = colorful; - this.greyTextColor = const Color(0xFFC4C4C4); - this.cardBorderColor = Colors.transparent; - } - FredericColorTheme.red( {this.name = "Hot Rod Red", this.uid = 14, @@ -433,6 +403,55 @@ class FredericColorTheme { this.greyTextColor = const Color(0xFFC4C4C4), this.cardBorderColor = Colors.transparent}); + FredericColorTheme.fromColor(CorePalette palette) { + //bool colorful = dark || false; + this.name = "You"; + this.uid = 17; + + this.mainColor = SystemTheme.accentColor.accent; + this.mainColorInText = SystemTheme.accentColor.dark; + this.mainColorLight = SystemTheme.accentColor.accent.withAlpha(100); + this.accentColor = SystemTheme.accentColor.lighter; + this.accentColorLight = SystemTheme.accentColor.lighter.withAlpha(100); + this.positiveColor = const Color(0xFF1CBB3F); + this.positiveColorLight = const Color(0x1A1CBB3F); + this.negativeColor = const Color(0xFF6A0C0B); + this.negativeColorLight = const Color(0x1A6A0C0B); + this.dividerColor = const Color(0xFFC9C9C9); + this.backgroundColor = Colors.white; + this.cardBackgroundColor = Colors.white; + this.greyColor = const Color(0xFFC4C4C4); + this.disabledGreyColor = const Color(0x66A5A5A5); + this.textColor = const Color(0xFF272727); + this.textColorBright = Colors.white; + this.textColorColorfulBackground = const Color(0xFF272727); + this.isDark = false; + this.isColorful = false; + this.greyTextColor = const Color(0xBF3A3A3A); + this.cardBorderColor = const Color(0xFFE2E2E2); + // this.mainColorInText = scheme.primary; + // this.mainColorLight = scheme.primary.withAlpha(15); + // this.accentColor = scheme.secondary; + // this.accentColorLight = scheme.secondary.withAlpha(15); + // this.positiveColor = scheme.tertiary; + // this.positiveColorLight = scheme.tertiary.withAlpha(15); + // this.negativeColor = scheme.error; + // this.negativeColorLight = scheme.error.withAlpha(15); + // this.dividerColor = scheme.outline; + // this.backgroundColor = scheme.background; + // this.cardBackgroundColor = scheme.tertiary.withOpacity(0.038); + // this.greyColor = scheme.onSurface; + // this.disabledGreyColor = const Color(0x66A5A5A5); + // this.textColor = scheme.onBackground; + // this.textColorBright = Colors.black; + // this.textColorColorfulBackground = + // colorful ? scheme.onPrimary : scheme.onBackground; + // this.isDark = dark; + // this.isColorful = colorful; + // this.greyTextColor = const Color(0xFFC4C4C4); + // this.cardBorderColor = Colors.transparent; + } + static FredericColorTheme find(int id) { switch (id) { case 1: diff --git a/pubspec.yaml b/pubspec.yaml index 2258ebf..ad04b73 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -58,6 +58,8 @@ dependencies: image_picker: ^1.0.4 url_launcher: ^6.1.14 social_share: ^2.3.1 + system_theme: ^2.3.1 + dynamic_color: ^1.6.9 auto_size_text: ^3.0.0 in_app_purchase: ^3.1.11 cupertino_icons: ^1.0.6