diff --git a/lib/main.dart b/lib/main.dart index 68655b7..96fa1c4 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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'; @@ -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'); @@ -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 diff --git a/lib/theme/frederic_theme.dart b/lib/theme/frederic_theme.dart index 1085287..453b6c6 100644 --- a/lib/theme/frederic_theme.dart +++ b/lib/theme/frederic_theme.dart @@ -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 { @@ -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), @@ -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), @@ -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), @@ -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), @@ -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: @@ -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]'); @@ -542,13 +530,18 @@ class FredericColorTheme { static List 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; diff --git a/lib/widgets/activity_screen/activity_filter_segment.dart b/lib/widgets/activity_screen/activity_filter_segment.dart index 8c73126..eff86d4 100644 --- a/lib/widgets/activity_screen/activity_filter_segment.dart +++ b/lib/widgets/activity_screen/activity_filter_segment.dart @@ -1,5 +1,7 @@ import 'package:easy_localization/easy_localization.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:frederic/backend/util/frederic_profiler.dart'; import 'package:frederic/main.dart'; import 'package:frederic/widgets/activity_screen/activity_musclegroup_button.dart'; @@ -50,97 +52,104 @@ class _ActivityFilterSegmentState extends State { final double padding = 0; //MediaQuery.of(context).size.width / 16; try { return SliverToBoxAdapter( - child: Padding( - padding: - const EdgeInsets.only(left: 16, right: 16, top: 16, bottom: 0), - child: Column( - children: [ - FredericHeading.translate('exercises.muscle_groups.title'), - Stack( - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - ActivityMuscleGroupButton( - tr('exercises.muscle_groups.all'), - key: allKey, - rightPadding: padding, - isActive: selectedIndex == 0, onPressed: () { - setState(() { - handleMuscleFilters(MuscleGroup.All); - selectedIndex = 0; - }); - }), - ActivityMuscleGroupButton( - tr('exercises.muscle_groups.arms'), - key: armsKey, - rightPadding: padding, - isActive: selectedIndex == 1, onPressed: () { - setState(() { - handleMuscleFilters(MuscleGroup.Arms); - selectedIndex = 1; - }); - }), - ActivityMuscleGroupButton( - tr('exercises.muscle_groups.chest'), - key: chestKey, - rightPadding: padding, - isActive: selectedIndex == 2, - onPressed: () => setState(() { - handleMuscleFilters(MuscleGroup.Chest); - selectedIndex = 2; - })), - ActivityMuscleGroupButton( - tr('exercises.muscle_groups.back'), - key: backKey, - rightPadding: padding, - isActive: selectedIndex == 3, - onPressed: () => setState(() { - handleMuscleFilters(MuscleGroup.Back); - selectedIndex = 3; - })), - ActivityMuscleGroupButton( - tr('exercises.muscle_groups.abs'), - key: absKey, - rightPadding: padding, - isActive: selectedIndex == 4, - onPressed: () => setState(() { - handleMuscleFilters(MuscleGroup.Abs); - selectedIndex = 4; - })), - ActivityMuscleGroupButton( - tr('exercises.muscle_groups.legs'), - key: legsKey, - rightPadding: padding, - isActive: selectedIndex == 5, - onPressed: () => setState(() { - handleMuscleFilters(MuscleGroup.Legs); - selectedIndex = 5; - })), - SizedBox(width: 12) - ], - ), - AnimatedPositioned( - duration: Duration(milliseconds: 300), - curve: Curves.ease, - bottom: 0, - left: keys[selectedIndex].positionedDifference(dotKey), - child: Icon( - Icons.circle, - size: 8, - color: theme.mainColor, + child: SizedBox( + width: double.infinity, + child: Padding( + padding: + const EdgeInsets.only(left: 16, right: 16, top: 16, bottom: 0), + child: Column( + children: [ + FredericHeading.translate('exercises.muscle_groups.title'), + Stack( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + ActivityMuscleGroupButton( + tr('exercises.muscle_groups.all'), + key: allKey, + rightPadding: padding, + isActive: selectedIndex == 0, onPressed: () { + setState(() { + handleMuscleFilters(MuscleGroup.All); + selectedIndex = 0; + }); + }), + ActivityMuscleGroupButton( + tr('exercises.muscle_groups.arms'), + key: armsKey, + rightPadding: padding, + isActive: selectedIndex == 1, onPressed: () { + setState(() { + handleMuscleFilters(MuscleGroup.Arms); + selectedIndex = 1; + }); + }), + ActivityMuscleGroupButton( + tr('exercises.muscle_groups.chest'), + key: chestKey, + rightPadding: padding, + isActive: selectedIndex == 2, + onPressed: () => setState(() { + handleMuscleFilters(MuscleGroup.Chest); + selectedIndex = 2; + })), + ActivityMuscleGroupButton( + tr('exercises.muscle_groups.back'), + key: backKey, + rightPadding: padding, + isActive: selectedIndex == 3, + onPressed: () => setState(() { + handleMuscleFilters(MuscleGroup.Back); + selectedIndex = 3; + })), + ActivityMuscleGroupButton( + tr('exercises.muscle_groups.abs'), + key: absKey, + rightPadding: padding, + isActive: selectedIndex == 4, + onPressed: () => setState(() { + handleMuscleFilters(MuscleGroup.Abs); + selectedIndex = 4; + })), + ActivityMuscleGroupButton( + tr('exercises.muscle_groups.legs'), + key: legsKey, + rightPadding: padding, + isActive: selectedIndex == 5, + onPressed: () => setState(() { + handleMuscleFilters(MuscleGroup.Legs); + selectedIndex = 5; + })), + SizedBox(width: 12) + ], ), - ), - ], - ), - SizedBox(height: 12), - ], + AnimatedPositioned( + duration: Duration(milliseconds: 300), + curve: Curves.ease, + bottom: 0, + left: keys[selectedIndex].positionedDifference(dotKey), + child: Icon( + Icons.circle, + size: 8, + color: theme.mainColor, + ), + ), + ], + ), + SizedBox(height: 12), + ], + ), ), ), ); } catch (e) { print(e); - return Container(); + FredericProfiler.log('muscle group filter segment: ' + e.toString()); + return SliverToBoxAdapter( + child: Container( + child: kDebugMode ? Text(e.toString()) : Container(height: 16), + )); } } diff --git a/lib/widgets/standard_elements/frederic_date_picker.dart b/lib/widgets/standard_elements/frederic_date_picker.dart index e1eee8f..956677c 100644 --- a/lib/widgets/standard_elements/frederic_date_picker.dart +++ b/lib/widgets/standard_elements/frederic_date_picker.dart @@ -170,9 +170,8 @@ class _FredericDatePickerState extends State { }), child: Container( decoration: BoxDecoration( - color: selected - ? theme.mainColorLight - : (theme.isDark ? theme.cardBackgroundColor : Colors.white), + color: + selected ? theme.mainColorLight : (theme.cardBackgroundColor), borderRadius: BorderRadius.circular(8), border: Border.all( color: selected diff --git a/lib/widgets/standard_elements/frederic_text_field.dart b/lib/widgets/standard_elements/frederic_text_field.dart index 3c6e194..de67d64 100644 --- a/lib/widgets/standard_elements/frederic_text_field.dart +++ b/lib/widgets/standard_elements/frederic_text_field.dart @@ -46,7 +46,7 @@ class FredericTextField extends StatefulWidget { class _FredericTextFieldState extends State { final Color textColor = Colors.black87; - final Color disabledBorderColor = Color(0xFFE2E2E2); + final Color disabledBorderColor = theme.greyColor; //Color(0xFFE2E2E2); bool showPassword = false; diff --git a/pubspec.yaml b/pubspec.yaml index ad04b73..683f9d8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -59,7 +59,6 @@ dependencies: 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