Skip to content

Commit

Permalink
implement material you color scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
NeXTormer committed Feb 28, 2024
1 parent ae7c9c7 commit 1766876
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 159 deletions.
19 changes: 8 additions & 11 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:io';
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';
Expand Down Expand Up @@ -42,6 +42,13 @@ void main() async {
startupTimeProfiler =
await FredericProfiler.trackFirebase('App Startup Time');
final timeUntilRunApp = FredericProfiler.track('time until runApp()');

// TODO: may be a race condition
if (Platform.operatingSystem == 'android') {
final colorThemeLoading = FredericProfiler.track('load system color theme');
SystemTheme.accentColor.load().then((value) => colorThemeLoading.stop());
}

LicenseRegistry.addLicense(() async* {
final license =
await rootBundle.loadString('assets/fonts/Montserrat/OFL.txt');
Expand Down Expand Up @@ -105,16 +112,6 @@ void main() async {
_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
Expand Down
109 changes: 51 additions & 58 deletions lib/theme/frederic_theme.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:material_color_utilities/material_color_utilities.dart';
import 'package:system_theme/system_theme.dart';

class FredericColorTheme {
Expand Down Expand Up @@ -303,9 +302,41 @@ class FredericColorTheme {
this.greyTextColor = const Color(0xFFC4C4C4),
this.cardBorderColor = Colors.transparent});

FredericColorTheme.fromColor(Color seedColor) {
var brightness = Brightness.light;
// TODO: support for dark mode
// SchedulerBinding.instance.platformDispatcher.platformBrightness;
final scheme =
ColorScheme.fromSeed(seedColor: seedColor, brightness: brightness);
this.name = "You";
this.uid = 13;

this.mainColor = scheme.primary;
this.mainColorInText = scheme.primary;
this.mainColorLight = scheme.secondaryContainer;
this.accentColor = scheme.secondary;
this.accentColorLight = scheme.secondaryContainer;
this.positiveColor = scheme.tertiary;
this.positiveColorLight = scheme.tertiaryContainer;
this.negativeColor = scheme.error;
this.negativeColorLight = scheme.errorContainer;
this.dividerColor = scheme.inverseSurface;
this.backgroundColor = scheme.surfaceVariant;
this.cardBackgroundColor = scheme.secondaryContainer;
this.greyColor = scheme.outline;
this.disabledGreyColor = scheme.outlineVariant;
this.textColor = scheme.onSurface;
this.textColorBright = scheme.onPrimaryContainer;
this.textColorColorfulBackground = scheme.onPrimary;
this.isDark = brightness == Brightness.dark;
this.isColorful = true;
this.greyTextColor = scheme.onPrimaryContainer;
this.cardBorderColor = scheme.outlineVariant;
}

FredericColorTheme.greenDark(
{this.name = "Dark Green",
this.uid = 13,
this.uid = 14,
this.mainColor = const Color(0xFF3E4F00),
this.mainColorInText = const Color(0xFF479100),
this.mainColorLight = const Color(0x1B4B7410),
Expand All @@ -330,7 +361,7 @@ class FredericColorTheme {

FredericColorTheme.red(
{this.name = "Hot Rod Red",
this.uid = 14,
this.uid = 15,
this.mainColor = const Color(0xFFAA0505),
this.mainColorInText = const Color(0xFFAA0505),
this.mainColorLight = const Color(0x1AAA0505),
Expand All @@ -355,7 +386,7 @@ class FredericColorTheme {

FredericColorTheme.redColorful(
{this.name = "Hot Rod Red Colorful",
this.uid = 15,
this.uid = 16,
this.mainColor = const Color(0xFFAA0505),
this.mainColorInText = const Color(0xFFAA0505),
this.mainColorLight = const Color(0x1AAA0505),
Expand All @@ -380,7 +411,7 @@ class FredericColorTheme {

FredericColorTheme.redDark(
{this.name = "Hot Rod Red Dark",
this.uid = 16,
this.uid = 17,
this.mainColor = const Color(0xFFAA0505),
this.mainColorInText = const Color(0xFFD11616),
this.mainColorLight = const Color(0x1AAA0505),
Expand All @@ -403,55 +434,6 @@ 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:
Expand Down Expand Up @@ -515,21 +497,27 @@ class FredericColorTheme {
'Color theme UIDs not matching! [${theme.uid} != $id]');
return theme;
case 13:
FredericColorTheme theme = FredericColorTheme.greenDark();
FredericColorTheme theme =
FredericColorTheme.fromColor(SystemTheme.accentColor.accent);
assert(theme.uid == id,
'Color theme UIDs not matching! [${theme.uid} != $id]');
return theme;
case 14:
FredericColorTheme theme = FredericColorTheme.red();
FredericColorTheme theme = FredericColorTheme.greenDark();
assert(theme.uid == id,
'Color theme UIDs not matching! [${theme.uid} != $id]');
return theme;
case 15:
FredericColorTheme theme = FredericColorTheme.redColorful();
FredericColorTheme theme = FredericColorTheme.red();
assert(theme.uid == id,
'Color theme UIDs not matching! [${theme.uid} != $id]');
return theme;
case 16:
FredericColorTheme theme = FredericColorTheme.redColorful();
assert(theme.uid == id,
'Color theme UIDs not matching! [${theme.uid} != $id]');
return theme;
case 17:
FredericColorTheme theme = FredericColorTheme.redDark();
assert(theme.uid == id,
'Color theme UIDs not matching! [${theme.uid} != $id]');
Expand All @@ -542,13 +530,18 @@ class FredericColorTheme {

static List<FredericColorTheme> get allThemes {
if (_allThemes.isEmpty) {
for (int i = 1; i <= 16; i++) {
for (int i = 1; i <= 17; i++) {
_allThemes.add(find(i));
}
}
return _allThemes;
}

@override
String toString() {
return 'FredericColorTheme{name: $name, uid: $uid, isDark: $isDark, isColorful: $isColorful, mainColor: $mainColor, mainColorLight: $mainColorLight, accentColor: $accentColor, accentColorLight: $accentColorLight, positiveColor: $positiveColor, positiveColorLight: $positiveColorLight, negativeColor: $negativeColor, negativeColorLight: $negativeColorLight, dividerColor: $dividerColor, backgroundColor: $backgroundColor, cardBackgroundColor: $cardBackgroundColor, greyColor: $greyColor, disabledGreyColor: $disabledGreyColor, mainColorInText: $mainColorInText, textColor: $textColor, textColorBright: $textColorBright, textColorColorfulBackground: $textColorColorfulBackground, greyTextColor: $greyTextColor, cardBorderColor: $cardBorderColor}';
}

late final String name;
late final int uid;

Expand Down
Loading

0 comments on commit 1766876

Please sign in to comment.