diff --git a/docs/docs/basics/parsers.md b/docs/docs/basics/parsers.md index b9b3b1d1..6b83ca39 100644 --- a/docs/docs/basics/parsers.md +++ b/docs/docs/basics/parsers.md @@ -38,7 +38,7 @@ class MiraiTextParser extends MiraiParser { maxLines: model.maxLines, semanticsLabel: model.semanticsLabel, textWidthBasis: model.textWidthBasis, - selectionColor: model.selectionColor.toColor, + selectionColor: model.selectionColor.toColor(context), ); } } diff --git a/examples/mirai_gallery/assets/json/app_bar_example.json b/examples/mirai_gallery/assets/json/app_bar_example.json index 412cb0cd..169bf4ce 100644 --- a/examples/mirai_gallery/assets/json/app_bar_example.json +++ b/examples/mirai_gallery/assets/json/app_bar_example.json @@ -15,6 +15,7 @@ }, "onPressed": {} }, + "backgroundColor": "primary", "actions": [ { "type": "iconButton", diff --git a/examples/mirai_gallery/ios/Flutter/AppFrameworkInfo.plist b/examples/mirai_gallery/ios/Flutter/AppFrameworkInfo.plist index 9625e105..7c569640 100644 --- a/examples/mirai_gallery/ios/Flutter/AppFrameworkInfo.plist +++ b/examples/mirai_gallery/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 11.0 + 12.0 diff --git a/examples/mirai_gallery/ios/Podfile b/examples/mirai_gallery/ios/Podfile index fdcc671e..d97f17e2 100644 --- a/examples/mirai_gallery/ios/Podfile +++ b/examples/mirai_gallery/ios/Podfile @@ -1,5 +1,5 @@ # Uncomment this line to define a global platform for your project -# platform :ios, '11.0' +# platform :ios, '12.0' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' diff --git a/examples/mirai_gallery/ios/Podfile.lock b/examples/mirai_gallery/ios/Podfile.lock index b2d92b98..86586d7e 100644 --- a/examples/mirai_gallery/ios/Podfile.lock +++ b/examples/mirai_gallery/ios/Podfile.lock @@ -14,9 +14,9 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/webview_flutter_wkwebview/ios" SPEC CHECKSUMS: - Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854 + Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 webview_flutter_wkwebview: 2e2d318f21a5e036e2c3f26171342e95908bd60a -PODFILE CHECKSUM: 70d9d25280d0dd177a5f637cdb0f0b0b12c6a189 +PODFILE CHECKSUM: 819463e6a0290f5a72f145ba7cde16e8b6ef0796 -COCOAPODS: 1.12.1 +COCOAPODS: 1.14.3 diff --git a/examples/mirai_gallery/ios/Runner.xcodeproj/project.pbxproj b/examples/mirai_gallery/ios/Runner.xcodeproj/project.pbxproj index 20915bbb..9c0ec2c2 100644 --- a/examples/mirai_gallery/ios/Runner.xcodeproj/project.pbxproj +++ b/examples/mirai_gallery/ios/Runner.xcodeproj/project.pbxproj @@ -452,7 +452,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -579,7 +579,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -628,7 +628,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 11.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; diff --git a/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action_parser.dart b/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action_parser.dart index 2e2cad10..a57f28d8 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action_parser.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_dialog_action/mirai_dialog_action_parser.dart @@ -49,7 +49,7 @@ class MiraiDialogActionParser extends MiraiActionParser { context: context, builder: (_) => widget, barrierDismissible: model.barrierDismissible, - barrierColor: model.barrierColor.toColor, + barrierColor: model.barrierColor.toColor(context), barrierLabel: model.barrierLabel, useSafeArea: model.useSafeArea, traversalEdgeBehavior: model.traversalEdgeBehavior, diff --git a/packages/mirai/lib/src/action_parsers/mirai_modal_bottom_sheet_action/mirai_modal_bottom_sheet_action_parser.dart b/packages/mirai/lib/src/action_parsers/mirai_modal_bottom_sheet_action/mirai_modal_bottom_sheet_action_parser.dart index 84cc69af..a3c7d10c 100644 --- a/packages/mirai/lib/src/action_parsers/mirai_modal_bottom_sheet_action/mirai_modal_bottom_sheet_action_parser.dart +++ b/packages/mirai/lib/src/action_parsers/mirai_modal_bottom_sheet_action/mirai_modal_bottom_sheet_action_parser.dart @@ -53,12 +53,12 @@ class MiraiModalBottomSheetActionParser return showModalBottomSheet( context: context, builder: (context) => widget, - backgroundColor: model.backgroundColor.toColor, + backgroundColor: model.backgroundColor.toColor(context), barrierLabel: model.barrierLabel, elevation: model.elevation, - shape: model.shape?.parse, + shape: model.shape?.parse(context), constraints: model.constraints?.parse, - barrierColor: model.barrierColor.toColor, + barrierColor: model.barrierColor.toColor(context), isScrollControlled: model.isScrollControlled, useRootNavigator: model.useRootNavigator, isDismissible: model.isDismissible, diff --git a/packages/mirai/lib/src/framework/mirai_app.dart b/packages/mirai/lib/src/framework/mirai_app.dart index 8c008f5c..a7cd8323 100644 --- a/packages/mirai/lib/src/framework/mirai_app.dart +++ b/packages/mirai/lib/src/framework/mirai_app.dart @@ -136,12 +136,12 @@ class MiraiApp extends StatelessWidget { @override Widget build(BuildContext context) { if (routerDelegate != null || routerConfig != null) { - return _materialRouterApp; + return _materialRouterApp(context); } - return _materialApp; + return _materialApp(context); } - Widget get _materialApp { + Widget _materialApp(BuildContext context) { return MaterialApp( navigatorKey: navigatorKey, scaffoldMessengerKey: scaffoldMessengerKey, @@ -162,8 +162,8 @@ class MiraiApp extends StatelessWidget { builder: builder, title: title, onGenerateTitle: onGenerateTitle, - theme: theme?.parse, - darkTheme: darkTheme?.parse, + theme: theme?.parse(context), + darkTheme: darkTheme?.parse(context), highContrastTheme: highContrastTheme, highContrastDarkTheme: highContrastDarkTheme, themeMode: themeMode, @@ -188,7 +188,7 @@ class MiraiApp extends StatelessWidget { ); } - Widget get _materialRouterApp { + Widget _materialRouterApp(BuildContext context) { return MaterialApp.router( scaffoldMessengerKey: scaffoldMessengerKey, routeInformationProvider: routeInformationProvider, @@ -200,8 +200,8 @@ class MiraiApp extends StatelessWidget { title: title, onGenerateTitle: onGenerateTitle, color: color, - theme: theme?.parse, - darkTheme: darkTheme?.parse, + theme: theme?.parse(context), + darkTheme: darkTheme?.parse(context), highContrastTheme: highContrastTheme, highContrastDarkTheme: highContrastDarkTheme, themeMode: themeMode, diff --git a/packages/mirai/lib/src/parsers/mirai_alert_dialog/mirai_alert_dialog_parser.dart b/packages/mirai/lib/src/parsers/mirai_alert_dialog/mirai_alert_dialog_parser.dart index 9102d5d0..a6eaca75 100644 --- a/packages/mirai/lib/src/parsers/mirai_alert_dialog/mirai_alert_dialog_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_alert_dialog/mirai_alert_dialog_parser.dart @@ -22,13 +22,13 @@ class MiraiAlertDialogParser extends MiraiParser { return AlertDialog( icon: Mirai.fromJson(model.icon, context), iconPadding: model.iconPadding?.parse, - iconColor: model.iconColor?.toColor, + iconColor: model.iconColor?.toColor(context), title: Mirai.fromJson(model.title, context), titlePadding: model.titlePadding?.parse, - titleTextStyle: model.titleTextStyle?.parse, + titleTextStyle: model.titleTextStyle?.parse(context), content: Mirai.fromJson(model.content, context), contentPadding: model.contentPadding.parse, - contentTextStyle: model.contentTextStyle?.parse, + contentTextStyle: model.contentTextStyle?.parse(context), actions: model.actions ?.map((action) => Mirai.fromJson(action, context) ?? const SizedBox()) .toList(), @@ -38,7 +38,7 @@ class MiraiAlertDialogParser extends MiraiParser { actionsOverflowDirection: model.actionsOverflowDirection, actionsOverflowButtonSpacing: model.actionsOverflowButtonSpacing, buttonPadding: model.buttonPadding.parse, - backgroundColor: model.backgroundColor.toColor, + backgroundColor: model.backgroundColor.toColor(context), elevation: model.elevation, semanticLabel: model.semanticLabel, insetPadding: model.insetPadding.parse, diff --git a/packages/mirai/lib/src/parsers/mirai_app_bar/mirai_app_bar_parser.dart b/packages/mirai/lib/src/parsers/mirai_app_bar/mirai_app_bar_parser.dart index 164f54e2..5b6ced86 100644 --- a/packages/mirai/lib/src/parsers/mirai_app_bar/mirai_app_bar_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_app_bar/mirai_app_bar_parser.dart @@ -20,12 +20,12 @@ class MiraiAppBarParser extends MiraiParser { return AppBar( leading: Mirai.fromJson(model.leading, context), title: Mirai.fromJson(model.title, context), - titleTextStyle: model.titleTextStyle?.parse, - toolbarTextStyle: model.toolbarTextStyle?.parse, - shadowColor: model.shadowColor?.toColor, - backgroundColor: model.backgroundColor?.toColor, - foregroundColor: model.foregroundColor?.toColor, - surfaceTintColor: model.surfaceTintColor?.toColor, + titleTextStyle: model.titleTextStyle?.parse(context), + toolbarTextStyle: model.toolbarTextStyle?.parse(context), + shadowColor: model.shadowColor?.toColor(context), + backgroundColor: model.backgroundColor?.toColor(context), + foregroundColor: model.foregroundColor?.toColor(context), + surfaceTintColor: model.surfaceTintColor?.toColor(context), actions: model.actions .map((action) => Mirai.fromJson(action, context) ?? const SizedBox()) .toList(), diff --git a/packages/mirai/lib/src/parsers/mirai_app_bar_theme/mirai_app_bar_theme.dart b/packages/mirai/lib/src/parsers/mirai_app_bar_theme/mirai_app_bar_theme.dart index d996ceb8..9d2142d4 100644 --- a/packages/mirai/lib/src/parsers/mirai_app_bar_theme/mirai_app_bar_theme.dart +++ b/packages/mirai/lib/src/parsers/mirai_app_bar_theme/mirai_app_bar_theme.dart @@ -32,22 +32,22 @@ class MiraiAppBarTheme with _$MiraiAppBarTheme { } extension MiraiAppBarThemeParser on MiraiAppBarTheme { - AppBarTheme? get parse { + AppBarTheme? parse(BuildContext context) { return AppBarTheme( - backgroundColor: backgroundColor.toColor, - foregroundColor: foregroundColor.toColor, + backgroundColor: backgroundColor.toColor(context), + foregroundColor: foregroundColor.toColor(context), elevation: elevation, scrolledUnderElevation: scrolledUnderElevation, - shadowColor: shadowColor.toColor, - surfaceTintColor: surfaceTintColor.toColor, - iconTheme: iconTheme?.parse, - actionsIconTheme: actionsIconTheme?.parse, + shadowColor: shadowColor.toColor(context), + surfaceTintColor: surfaceTintColor.toColor(context), + iconTheme: iconTheme?.parse(context), + actionsIconTheme: actionsIconTheme?.parse(context), centerTitle: centerTitle, titleSpacing: titleSpacing, toolbarHeight: toolbarHeight, - toolbarTextStyle: toolbarTextStyle?.parse, - titleTextStyle: titleTextStyle?.parse, - systemOverlayStyle: systemOverlayStyle?.parse, + toolbarTextStyle: toolbarTextStyle?.parse(context), + titleTextStyle: titleTextStyle?.parse(context), + systemOverlayStyle: systemOverlayStyle?.parse(context), ); } } diff --git a/packages/mirai/lib/src/parsers/mirai_border/mirai_border.dart b/packages/mirai/lib/src/parsers/mirai_border/mirai_border.dart index 19887b5c..f17c262d 100644 --- a/packages/mirai/lib/src/parsers/mirai_border/mirai_border.dart +++ b/packages/mirai/lib/src/parsers/mirai_border/mirai_border.dart @@ -19,9 +19,9 @@ class MiraiBorder with _$MiraiBorder { } extension MiraiBorderParser on MiraiBorder { - Border get parse { + Border parse(BuildContext context) { return Border.all( - color: color.toColor ?? const Color(0xFF000000), + color: color.toColor(context) ?? const Color(0xFF000000), width: width, style: borderStyle, strokeAlign: strokeAlign, diff --git a/packages/mirai/lib/src/parsers/mirai_border_side/mirai_border_side.dart b/packages/mirai/lib/src/parsers/mirai_border_side/mirai_border_side.dart index b9eeffe1..2aa45418 100644 --- a/packages/mirai/lib/src/parsers/mirai_border_side/mirai_border_side.dart +++ b/packages/mirai/lib/src/parsers/mirai_border_side/mirai_border_side.dart @@ -19,9 +19,9 @@ class MiraiBorderSide with _$MiraiBorderSide { } extension MiraiBorderSideParser on MiraiBorderSide? { - BorderSide get parse { + BorderSide parse(BuildContext context) { return BorderSide( - color: this?.color.toColor ?? const Color(0xFF000000), + color: this?.color.toColor(context) ?? const Color(0xFF000000), width: this?.width ?? 0.0, style: this?.borderStyle ?? BorderStyle.solid, strokeAlign: this?.strokeAlign ?? 0.0, diff --git a/packages/mirai/lib/src/parsers/mirai_bottom_app_bar_theme/mirai_bottom_app_bar_theme.dart b/packages/mirai/lib/src/parsers/mirai_bottom_app_bar_theme/mirai_bottom_app_bar_theme.dart index a9cac82d..6c2b6b06 100644 --- a/packages/mirai/lib/src/parsers/mirai_bottom_app_bar_theme/mirai_bottom_app_bar_theme.dart +++ b/packages/mirai/lib/src/parsers/mirai_bottom_app_bar_theme/mirai_bottom_app_bar_theme.dart @@ -22,13 +22,13 @@ class MiraiBottomAppBarTheme with _$MiraiBottomAppBarTheme { } extension MiraiBottomAppBarThemeParser on MiraiBottomAppBarTheme { - BottomAppBarTheme? get parse { + BottomAppBarTheme? parse(BuildContext context) { return BottomAppBarTheme( - color: color?.toColor, + color: color?.toColor(context), elevation: elevation, height: height, - surfaceTintColor: surfaceTintColor.toColor, - shadowColor: shadowColor.toColor, + surfaceTintColor: surfaceTintColor.toColor(context), + shadowColor: shadowColor.toColor(context), padding: padding?.parse, ); } diff --git a/packages/mirai/lib/src/parsers/mirai_bottom_nav_bar_theme/mirai_bottom_nav_bar_theme.dart b/packages/mirai/lib/src/parsers/mirai_bottom_nav_bar_theme/mirai_bottom_nav_bar_theme.dart index 38d7fb63..59a23b12 100644 --- a/packages/mirai/lib/src/parsers/mirai_bottom_nav_bar_theme/mirai_bottom_nav_bar_theme.dart +++ b/packages/mirai/lib/src/parsers/mirai_bottom_nav_bar_theme/mirai_bottom_nav_bar_theme.dart @@ -30,16 +30,16 @@ class MiraiBottomNavBarThemeData with _$MiraiBottomNavBarThemeData { } extension MiraiBottomNavBarThemeDataParser on MiraiBottomNavBarThemeData { - BottomNavigationBarThemeData? get parse { + BottomNavigationBarThemeData? parse(BuildContext context) { return BottomNavigationBarThemeData( - backgroundColor: backgroundColor.toColor, + backgroundColor: backgroundColor.toColor(context), elevation: elevation, - selectedIconTheme: selectedIconTheme?.parse, - unselectedIconTheme: unselectedIconTheme?.parse, - selectedItemColor: selectedItemColor.toColor, - unselectedItemColor: unselectedItemColor.toColor, - selectedLabelStyle: selectedLabelStyle?.parse, - unselectedLabelStyle: unselectedLabelStyle?.parse, + selectedIconTheme: selectedIconTheme?.parse(context), + unselectedIconTheme: unselectedIconTheme?.parse(context), + selectedItemColor: selectedItemColor.toColor(context), + unselectedItemColor: unselectedItemColor.toColor(context), + selectedLabelStyle: selectedLabelStyle?.parse(context), + unselectedLabelStyle: unselectedLabelStyle?.parse(context), showSelectedLabels: showSelectedLabels, showUnselectedLabels: showUnselectedLabels, type: type, diff --git a/packages/mirai/lib/src/parsers/mirai_bottom_navigation_bar/mirai_bottom_navigation_bar_parser.dart b/packages/mirai/lib/src/parsers/mirai_bottom_navigation_bar/mirai_bottom_navigation_bar_parser.dart index 214f5af8..807cd1a7 100644 --- a/packages/mirai/lib/src/parsers/mirai_bottom_navigation_bar/mirai_bottom_navigation_bar_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_bottom_navigation_bar/mirai_bottom_navigation_bar_parser.dart @@ -26,15 +26,15 @@ class MiraiBottomNavigationBarParser currentIndex: model.currentIndex, elevation: model.elevation, type: model.navBarType, - fixedColor: model.fixedColor?.toColor, - backgroundColor: model.backgroundColor?.toColor, + fixedColor: model.fixedColor?.toColor(context), + backgroundColor: model.backgroundColor?.toColor(context), iconSize: model.iconSize, - selectedItemColor: model.selectedItemColor?.toColor, - unselectedItemColor: model.unselectedItemColor?.toColor, + selectedItemColor: model.selectedItemColor?.toColor(context), + unselectedItemColor: model.unselectedItemColor?.toColor(context), selectedFontSize: model.selectedFontSize, unselectedFontSize: model.unselectedFontSize, - selectedLabelStyle: model.selectedLabelStyle?.parse, - unselectedLabelStyle: model.unselectedLabelStyle?.parse, + selectedLabelStyle: model.selectedLabelStyle?.parse(context), + unselectedLabelStyle: model.unselectedLabelStyle?.parse(context), showSelectedLabels: model.showSelectedLabels, showUnselectedLabels: model.showUnselectedLabels, enableFeedback: model.enableFeedback, diff --git a/packages/mirai/lib/src/parsers/mirai_bottom_sheet_theme/mirai_bottom_sheet_theme.dart b/packages/mirai/lib/src/parsers/mirai_bottom_sheet_theme/mirai_bottom_sheet_theme.dart index 99efa5a4..0101a7eb 100644 --- a/packages/mirai/lib/src/parsers/mirai_bottom_sheet_theme/mirai_bottom_sheet_theme.dart +++ b/packages/mirai/lib/src/parsers/mirai_bottom_sheet_theme/mirai_bottom_sheet_theme.dart @@ -31,18 +31,18 @@ class MiraiBottomSheetThemeData with _$MiraiBottomSheetThemeData { } extension MiraiBottomSheetThemeDataParser on MiraiBottomSheetThemeData { - BottomSheetThemeData get parse { + BottomSheetThemeData parse(BuildContext context) { return BottomSheetThemeData( - backgroundColor: backgroundColor.toColor, - surfaceTintColor: surfaceTintColor.toColor, + backgroundColor: backgroundColor.toColor(context), + surfaceTintColor: surfaceTintColor.toColor(context), elevation: elevation, - modalBackgroundColor: modalBackgroundColor.toColor, - modalBarrierColor: modalBarrierColor.toColor, - shadowColor: shadowColor.toColor, + modalBackgroundColor: modalBackgroundColor.toColor(context), + modalBarrierColor: modalBarrierColor.toColor(context), + shadowColor: shadowColor.toColor(context), modalElevation: modalElevation, - shape: shape?.parse, + shape: shape?.parse(context), showDragHandle: showDragHandle, - dragHandleColor: dragHandleColor.toColor, + dragHandleColor: dragHandleColor.toColor(context), dragHandleSize: dragHandleSize.parse, clipBehavior: clipBehavior, constraints: constraints?.parse, diff --git a/packages/mirai/lib/src/parsers/mirai_box_decoration/mirai_box_decoration.dart b/packages/mirai/lib/src/parsers/mirai_box_decoration/mirai_box_decoration.dart index 45dc2719..1834145d 100644 --- a/packages/mirai/lib/src/parsers/mirai_box_decoration/mirai_box_decoration.dart +++ b/packages/mirai/lib/src/parsers/mirai_box_decoration/mirai_box_decoration.dart @@ -29,16 +29,16 @@ class MiraiBoxDecoration with _$MiraiBoxDecoration { } extension MiraiBoxDecorationParser on MiraiBoxDecoration? { - BoxDecoration? get parse { + BoxDecoration? parse(BuildContext context) { return BoxDecoration( - color: this?.color.toColor, + color: this?.color.toColor(context), backgroundBlendMode: this?.blendMode, - boxShadow: this?.boxShadow?.map((elem) => elem.parse).toList(), + boxShadow: this?.boxShadow?.map((elem) => elem.parse(context)).toList(), shape: this?.shape ?? BoxShape.rectangle, - border: this?.border?.parse, + border: this?.border?.parse(context), borderRadius: this?.borderRadius.parse, image: this?.image.parse, - gradient: this?.gradient?.parse, + gradient: this?.gradient?.parse(context), ); } } diff --git a/packages/mirai/lib/src/parsers/mirai_box_shadow/mirai_box_shadow.dart b/packages/mirai/lib/src/parsers/mirai_box_shadow/mirai_box_shadow.dart index e6b37408..9e42a0aa 100644 --- a/packages/mirai/lib/src/parsers/mirai_box_shadow/mirai_box_shadow.dart +++ b/packages/mirai/lib/src/parsers/mirai_box_shadow/mirai_box_shadow.dart @@ -21,9 +21,9 @@ class MiraiBoxShadow with _$MiraiBoxShadow { } extension MiraiBoxShadowParser on MiraiBoxShadow? { - BoxShadow get parse { + BoxShadow parse(BuildContext context) { return BoxShadow( - color: this?.color.toColor ?? const Color(0xFF000000), + color: this?.color.toColor(context) ?? const Color(0xFF000000), blurRadius: this?.blurRadius ?? 0.0, offset: this?.offset.parse ?? Offset.zero, spreadRadius: this?.spreadRadius ?? 0.0, diff --git a/packages/mirai/lib/src/parsers/mirai_button_style/mirai_button_style.dart b/packages/mirai/lib/src/parsers/mirai_button_style/mirai_button_style.dart index f950f19b..8f48b27e 100644 --- a/packages/mirai/lib/src/parsers/mirai_button_style/mirai_button_style.dart +++ b/packages/mirai/lib/src/parsers/mirai_button_style/mirai_button_style.dart @@ -38,80 +38,80 @@ class MiraiButtonStyle with _$MiraiButtonStyle { } extension MiraiButtonStyleParser on MiraiButtonStyle { - ButtonStyle get parseElevated { + ButtonStyle parseElevated(BuildContext context) { return ElevatedButton.styleFrom( - foregroundColor: foregroundColor?.toColor, - backgroundColor: backgroundColor.toColor, - disabledForegroundColor: disabledForegroundColor.toColor, - disabledBackgroundColor: disabledBackgroundColor.toColor, - shadowColor: shadowColor.toColor, - surfaceTintColor: surfaceTintColor.toColor, + foregroundColor: foregroundColor?.toColor(context), + backgroundColor: backgroundColor.toColor(context), + disabledForegroundColor: disabledForegroundColor.toColor(context), + disabledBackgroundColor: disabledBackgroundColor.toColor(context), + shadowColor: shadowColor.toColor(context), + surfaceTintColor: surfaceTintColor.toColor(context), elevation: elevation, - textStyle: textStyle?.parse, + textStyle: textStyle?.parse(context), enableFeedback: enableFeedback, minimumSize: minimumSize?.parse, fixedSize: fixedSize?.parse, maximumSize: maximumSize?.parse, - shape: shape.parse, + shape: shape.parse(context), padding: padding.parse, ); } - ButtonStyle get parseText { + ButtonStyle parseText(BuildContext context) { return TextButton.styleFrom( - foregroundColor: foregroundColor.toColor, - backgroundColor: backgroundColor.toColor, - disabledForegroundColor: disabledForegroundColor.toColor, - disabledBackgroundColor: disabledBackgroundColor.toColor, - shadowColor: shadowColor.toColor, - surfaceTintColor: surfaceTintColor.toColor, - iconColor: iconColor.toColor, - disabledIconColor: disabledIconColor.toColor, + foregroundColor: foregroundColor.toColor(context), + backgroundColor: backgroundColor.toColor(context), + disabledForegroundColor: disabledForegroundColor.toColor(context), + disabledBackgroundColor: disabledBackgroundColor.toColor(context), + shadowColor: shadowColor.toColor(context), + surfaceTintColor: surfaceTintColor.toColor(context), + iconColor: iconColor.toColor(context), + disabledIconColor: disabledIconColor.toColor(context), elevation: elevation, - textStyle: textStyle?.parse, + textStyle: textStyle?.parse(context), enableFeedback: enableFeedback, minimumSize: minimumSize?.parse, fixedSize: fixedSize?.parse, maximumSize: maximumSize?.parse, - shape: shape.parse, + shape: shape.parse(context), padding: padding.parse, ); } - ButtonStyle get parseOutlined { + ButtonStyle parseOutlined(BuildContext context) { return OutlinedButton.styleFrom( - foregroundColor: foregroundColor.toColor, - backgroundColor: backgroundColor.toColor, - disabledForegroundColor: disabledForegroundColor.toColor, - disabledBackgroundColor: disabledBackgroundColor.toColor, - shadowColor: shadowColor.toColor, - surfaceTintColor: surfaceTintColor.toColor, + foregroundColor: foregroundColor.toColor(context), + backgroundColor: backgroundColor.toColor(context), + disabledForegroundColor: disabledForegroundColor.toColor(context), + disabledBackgroundColor: disabledBackgroundColor.toColor(context), + shadowColor: shadowColor.toColor(context), + surfaceTintColor: surfaceTintColor.toColor(context), elevation: elevation, - textStyle: textStyle?.parse, + textStyle: textStyle?.parse(context), enableFeedback: enableFeedback, minimumSize: minimumSize?.parse, fixedSize: fixedSize?.parse, maximumSize: maximumSize?.parse, - side: side.parse, - shape: shape.parse, + side: side.parse(context), + shape: shape.parse(context), padding: padding.parse, ); } - ButtonStyle get parseIcon { + ButtonStyle parseIcon(BuildContext context) { return IconButton.styleFrom( - foregroundColor: foregroundColor.toColor, - backgroundColor: backgroundColor.toColor, - disabledForegroundColor: disabledForegroundColor.toColor, - disabledBackgroundColor: disabledBackgroundColor.toColor, - shadowColor: shadowColor.toColor, - surfaceTintColor: surfaceTintColor.toColor, + foregroundColor: foregroundColor.toColor(context), + backgroundColor: backgroundColor.toColor(context), + disabledForegroundColor: disabledForegroundColor.toColor(context), + disabledBackgroundColor: disabledBackgroundColor.toColor(context), + shadowColor: shadowColor.toColor(context), + surfaceTintColor: surfaceTintColor.toColor(context), elevation: elevation, enableFeedback: enableFeedback, minimumSize: minimumSize?.parse, fixedSize: fixedSize?.parse, maximumSize: maximumSize?.parse, - shape: shape.parse, + shape: shape.parse(context), padding: padding.parse, iconSize: iconSize, ); diff --git a/packages/mirai/lib/src/parsers/mirai_card/mirai_card_parser.dart b/packages/mirai/lib/src/parsers/mirai_card/mirai_card_parser.dart index f0b3c07c..81e41d75 100644 --- a/packages/mirai/lib/src/parsers/mirai_card/mirai_card_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_card/mirai_card_parser.dart @@ -18,9 +18,9 @@ class MiraiCardParser extends MiraiParser { @override Widget parse(BuildContext context, MiraiCard model) { return Card( - color: model.color?.toColor, - shadowColor: model.shadowColor?.toColor, - surfaceTintColor: model.surfaceTintColor?.toColor, + color: model.color?.toColor(context), + shadowColor: model.shadowColor?.toColor(context), + surfaceTintColor: model.surfaceTintColor?.toColor(context), elevation: model.elevation, borderOnForeground: model.borderOnForeground, clipBehavior: model.clipBehavior, diff --git a/packages/mirai/lib/src/parsers/mirai_card_theme_data/mirai_card_theme_data.dart b/packages/mirai/lib/src/parsers/mirai_card_theme_data/mirai_card_theme_data.dart index c3e0871b..d9daadd3 100644 --- a/packages/mirai/lib/src/parsers/mirai_card_theme_data/mirai_card_theme_data.dart +++ b/packages/mirai/lib/src/parsers/mirai_card_theme_data/mirai_card_theme_data.dart @@ -24,15 +24,15 @@ class MiraiCardThemeData with _$MiraiCardThemeData { } extension MiraiCardThemeDataParser on MiraiCardThemeData { - CardTheme? get parse { + CardTheme? parse(BuildContext context) { return CardTheme( clipBehavior: clipBehavior, - color: color.toColor, - shadowColor: shadowColor.toColor, - surfaceTintColor: surfaceTintColor.toColor, + color: color.toColor(context), + shadowColor: shadowColor.toColor(context), + surfaceTintColor: surfaceTintColor.toColor(context), elevation: elevation, margin: margin.parse, - shape: shape?.parse, + shape: shape?.parse(context), ); } } diff --git a/packages/mirai/lib/src/parsers/mirai_check_box_widget/mirai_check_box_widget_parser.dart b/packages/mirai/lib/src/parsers/mirai_check_box_widget/mirai_check_box_widget_parser.dart index a170d174..751268ab 100644 --- a/packages/mirai/lib/src/parsers/mirai_check_box_widget/mirai_check_box_widget_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_check_box_widget/mirai_check_box_widget_parser.dart @@ -65,14 +65,15 @@ class __MiraiCheckBoxWidgetState extends State<_MiraiCheckBoxWidget> { .updateValidation(widget.model.id!, isMarkChecked); } }, - activeColor: widget.model.activeColor.toColor, - fillColor: MaterialStateProperty.all(widget.model.fillColor?.parse), - checkColor: widget.model.checkColor.toColor, + activeColor: widget.model.activeColor.toColor(context), + fillColor: + MaterialStateProperty.all(widget.model.fillColor?.parse(context)), + checkColor: widget.model.checkColor.toColor(context), tristate: widget.model.tristate, - focusColor: widget.model.focusColor.toColor, - hoverColor: widget.model.hoverColor.toColor, - overlayColor: - MaterialStateProperty.all(widget.model.overlayColor?.parse), + focusColor: widget.model.focusColor.toColor(context), + hoverColor: widget.model.hoverColor.toColor(context), + overlayColor: MaterialStateProperty.all( + widget.model.overlayColor?.parse(context)), splashRadius: widget.model.splashRadius, autofocus: widget.model.autofocus, isError: widget.model.isError); diff --git a/packages/mirai/lib/src/parsers/mirai_color_scheme/mirai_color_scheme.dart b/packages/mirai/lib/src/parsers/mirai_color_scheme/mirai_color_scheme.dart index aa734c88..3ca94fad 100644 --- a/packages/mirai/lib/src/parsers/mirai_color_scheme/mirai_color_scheme.dart +++ b/packages/mirai/lib/src/parsers/mirai_color_scheme/mirai_color_scheme.dart @@ -46,39 +46,39 @@ class MiraiColorScheme with _$MiraiColorScheme { } extension MiraiColorSchemeParser on MiraiColorScheme { - ColorScheme get parse { + ColorScheme parse(BuildContext context) { return ColorScheme( brightness: brightness, - primary: primary.toColor!, - onPrimary: onPrimary.toColor!, - primaryContainer: primaryContainer.toColor, - onPrimaryContainer: onPrimaryContainer.toColor, - secondary: secondary.toColor!, - onSecondary: onSecondary.toColor!, - secondaryContainer: secondaryContainer.toColor, - onSecondaryContainer: onSecondaryContainer.toColor, - tertiary: tertiary.toColor, - onTertiary: onTertiary.toColor, - tertiaryContainer: tertiaryContainer.toColor, - onTertiaryContainer: onTertiaryContainer.toColor, - error: error.toColor!, - onError: onError.toColor!, - errorContainer: errorContainer.toColor, - onErrorContainer: onErrorContainer.toColor, - background: background.toColor!, - onBackground: onBackground.toColor!, - surface: surface.toColor!, - onSurface: onSurface.toColor!, - surfaceVariant: surfaceVariant.toColor, - onSurfaceVariant: onSurfaceVariant.toColor, - outline: outline.toColor, - outlineVariant: outlineVariant.toColor, - shadow: shadow.toColor, - scrim: scrim.toColor, - inverseSurface: inverseSurface.toColor, - onInverseSurface: onInverseSurface.toColor, - inversePrimary: inversePrimary.toColor, - surfaceTint: surfaceTint.toColor, + primary: primary.toColor(context)!, + onPrimary: onPrimary.toColor(context)!, + primaryContainer: primaryContainer.toColor(context), + onPrimaryContainer: onPrimaryContainer.toColor(context), + secondary: secondary.toColor(context)!, + onSecondary: onSecondary.toColor(context)!, + secondaryContainer: secondaryContainer.toColor(context), + onSecondaryContainer: onSecondaryContainer.toColor(context), + tertiary: tertiary.toColor(context), + onTertiary: onTertiary.toColor(context), + tertiaryContainer: tertiaryContainer.toColor(context), + onTertiaryContainer: onTertiaryContainer.toColor(context), + error: error.toColor(context)!, + onError: onError.toColor(context)!, + errorContainer: errorContainer.toColor(context), + onErrorContainer: onErrorContainer.toColor(context), + background: background.toColor(context)!, + onBackground: onBackground.toColor(context)!, + surface: surface.toColor(context)!, + onSurface: onSurface.toColor(context)!, + surfaceVariant: surfaceVariant.toColor(context), + onSurfaceVariant: onSurfaceVariant.toColor(context), + outline: outline.toColor(context), + outlineVariant: outlineVariant.toColor(context), + shadow: shadow.toColor(context), + scrim: scrim.toColor(context), + inverseSurface: inverseSurface.toColor(context), + onInverseSurface: onInverseSurface.toColor(context), + inversePrimary: inversePrimary.toColor(context), + surfaceTint: surfaceTint.toColor(context), ); } } diff --git a/packages/mirai/lib/src/parsers/mirai_container/mirai_container_parser.dart b/packages/mirai/lib/src/parsers/mirai_container/mirai_container_parser.dart index 17eb18e4..067b415b 100644 --- a/packages/mirai/lib/src/parsers/mirai_container/mirai_container_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_container/mirai_container_parser.dart @@ -23,10 +23,10 @@ class MiraiContainerParser extends MiraiParser { alignment: model.alignment?.value, padding: model.padding.parse, decoration: model.color == null - ? model.decoration.parse - : model.decoration.parse?.copyWith( - color: model.color.toColor, - ), + ? model.decoration.parse(context) + : model.decoration.parse(context)?.copyWith( + color: model.color.toColor(context), + ), width: model.width, height: model.height, margin: model.margin.parse, diff --git a/packages/mirai/lib/src/parsers/mirai_dialog_theme/mirai_dialog_theme.dart b/packages/mirai/lib/src/parsers/mirai_dialog_theme/mirai_dialog_theme.dart index 4d8f98d0..df90cce1 100644 --- a/packages/mirai/lib/src/parsers/mirai_dialog_theme/mirai_dialog_theme.dart +++ b/packages/mirai/lib/src/parsers/mirai_dialog_theme/mirai_dialog_theme.dart @@ -29,18 +29,18 @@ class MiraiDialogTheme with _$MiraiDialogTheme { } extension MiraiDialogThemeParser on MiraiDialogTheme { - DialogTheme? get parse { + DialogTheme? parse(BuildContext context) { return DialogTheme( - backgroundColor: backgroundColor.toColor, + backgroundColor: backgroundColor.toColor(context), elevation: elevation, - shadowColor: shadowColor.toColor, - surfaceTintColor: surfaceTintColor.toColor, - shape: shape?.parse, + shadowColor: shadowColor.toColor(context), + surfaceTintColor: surfaceTintColor.toColor(context), + shape: shape?.parse(context), alignment: alignment?.parse, - titleTextStyle: titleTextStyle?.parse, - contentTextStyle: contentTextStyle?.parse, + titleTextStyle: titleTextStyle?.parse(context), + contentTextStyle: contentTextStyle?.parse(context), actionsPadding: actionsPadding.parse, - iconColor: iconColor.toColor, + iconColor: iconColor.toColor(context), ); } } diff --git a/packages/mirai/lib/src/parsers/mirai_elevated_button/mirai_elevated_button_parser.dart b/packages/mirai/lib/src/parsers/mirai_elevated_button/mirai_elevated_button_parser.dart index f46326fc..08f31a5b 100644 --- a/packages/mirai/lib/src/parsers/mirai_elevated_button/mirai_elevated_button_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_elevated_button/mirai_elevated_button_parser.dart @@ -21,7 +21,7 @@ class MiraiElevatedButtonParser extends MiraiParser { ? null : () => Mirai.onCallFromJson(model.onPressed, context), autofocus: model.autofocus, - style: model.style?.parseElevated, + style: model.style?.parseElevated(context), clipBehavior: model.clipBehavior, child: Mirai.fromJson(model.child, context), ); diff --git a/packages/mirai/lib/src/parsers/mirai_floating_action_button/mirai_floating_action_button_parser.dart b/packages/mirai/lib/src/parsers/mirai_floating_action_button/mirai_floating_action_button_parser.dart index 5e57a8dc..8df860f8 100644 --- a/packages/mirai/lib/src/parsers/mirai_floating_action_button/mirai_floating_action_button_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_floating_action_button/mirai_floating_action_button_parser.dart @@ -27,12 +27,12 @@ class MiraiFloatingActionButtonParser ? null : () => Mirai.onCallFromJson(model.onPressed, context), icon: Mirai.fromJson(model.icon, context), - backgroundColor: model.backgroundColor?.toColor, - foregroundColor: model.foregroundColor?.toColor, - focusColor: model.focusColor?.toColor, - hoverColor: model.hoverColor?.toColor, - splashColor: model.splashColor?.toColor, - extendedTextStyle: model.extendedTextStyle?.parse, + backgroundColor: model.backgroundColor?.toColor(context), + foregroundColor: model.foregroundColor?.toColor(context), + focusColor: model.focusColor?.toColor(context), + hoverColor: model.hoverColor?.toColor(context), + splashColor: model.splashColor?.toColor(context), + extendedTextStyle: model.extendedTextStyle?.parse(context), elevation: model.elevation, focusElevation: model.focusElevation, hoverElevation: model.hoverElevation, @@ -51,11 +51,11 @@ class MiraiFloatingActionButtonParser onPressed: model.onPressed == null ? null : () => Mirai.onCallFromJson(model.onPressed, context), - backgroundColor: model.backgroundColor?.toColor, - foregroundColor: model.foregroundColor?.toColor, - focusColor: model.focusColor?.toColor, - hoverColor: model.hoverColor?.toColor, - splashColor: model.splashColor?.toColor, + backgroundColor: model.backgroundColor?.toColor(context), + foregroundColor: model.foregroundColor?.toColor(context), + focusColor: model.focusColor?.toColor(context), + hoverColor: model.hoverColor?.toColor(context), + splashColor: model.splashColor?.toColor(context), elevation: model.elevation, focusElevation: model.focusElevation, hoverElevation: model.hoverElevation, @@ -73,11 +73,11 @@ class MiraiFloatingActionButtonParser onPressed: model.onPressed == null ? null : () => Mirai.onCallFromJson(model.onPressed, context), - backgroundColor: model.backgroundColor?.toColor, - foregroundColor: model.foregroundColor?.toColor, - focusColor: model.focusColor?.toColor, - hoverColor: model.hoverColor?.toColor, - splashColor: model.splashColor?.toColor, + backgroundColor: model.backgroundColor?.toColor(context), + foregroundColor: model.foregroundColor?.toColor(context), + focusColor: model.focusColor?.toColor(context), + hoverColor: model.hoverColor?.toColor(context), + splashColor: model.splashColor?.toColor(context), elevation: model.elevation, focusElevation: model.focusElevation, hoverElevation: model.hoverElevation, @@ -95,11 +95,11 @@ class MiraiFloatingActionButtonParser onPressed: model.onPressed == null ? null : () => Mirai.onCallFromJson(model.onPressed, context), - backgroundColor: model.backgroundColor?.toColor, - foregroundColor: model.foregroundColor?.toColor, - focusColor: model.focusColor?.toColor, - hoverColor: model.hoverColor?.toColor, - splashColor: model.splashColor?.toColor, + backgroundColor: model.backgroundColor?.toColor(context), + foregroundColor: model.foregroundColor?.toColor(context), + focusColor: model.focusColor?.toColor(context), + hoverColor: model.hoverColor?.toColor(context), + splashColor: model.splashColor?.toColor(context), elevation: model.elevation, focusElevation: model.focusElevation, hoverElevation: model.hoverElevation, diff --git a/packages/mirai/lib/src/parsers/mirai_floating_action_button_theme_data/mirai_floating_action_button_theme_data.dart b/packages/mirai/lib/src/parsers/mirai_floating_action_button_theme_data/mirai_floating_action_button_theme_data.dart index a38abdd1..e691db84 100644 --- a/packages/mirai/lib/src/parsers/mirai_floating_action_button_theme_data/mirai_floating_action_button_theme_data.dart +++ b/packages/mirai/lib/src/parsers/mirai_floating_action_button_theme_data/mirai_floating_action_button_theme_data.dart @@ -34,13 +34,13 @@ class MiraiFloatingActionButtonThemeData } extension MiraiFloatingActionThemeParser on MiraiFloatingActionButtonThemeData { - FloatingActionButtonThemeData get parse { + FloatingActionButtonThemeData parse(BuildContext context) { return FloatingActionButtonThemeData( - foregroundColor: foregroundColor.toColor, - backgroundColor: backgroundColor.toColor, - focusColor: focusColor.toColor, - hoverColor: hoverColor.toColor, - splashColor: splashColor.toColor, + foregroundColor: foregroundColor.toColor(context), + backgroundColor: backgroundColor.toColor(context), + focusColor: focusColor.toColor(context), + hoverColor: hoverColor.toColor(context), + splashColor: splashColor.toColor(context), elevation: elevation, focusElevation: focusElevation, hoverElevation: hoverElevation, @@ -50,7 +50,7 @@ extension MiraiFloatingActionThemeParser on MiraiFloatingActionButtonThemeData { iconSize: iconSize, extendedIconLabelSpacing: extendedIconLabelSpacing, extendedPadding: extendedPadding.parse, - extendedTextStyle: extendedTextStyle?.parse, + extendedTextStyle: extendedTextStyle?.parse(context), ); } } diff --git a/packages/mirai/lib/src/parsers/mirai_gradient/mirai_gradient.dart b/packages/mirai/lib/src/parsers/mirai_gradient/mirai_gradient.dart index a4127126..2d95c069 100644 --- a/packages/mirai/lib/src/parsers/mirai_gradient/mirai_gradient.dart +++ b/packages/mirai/lib/src/parsers/mirai_gradient/mirai_gradient.dart @@ -32,9 +32,9 @@ class MiraiGradient with _$MiraiGradient { } extension MiraiGradientParser on MiraiGradient { - Gradient? get parse { + Gradient? parse(BuildContext context) { Gradient linearGradient() => LinearGradient( - colors: colors.map((e) => e.toColor!).toList(), + colors: colors.map((e) => e.toColor(context)!).toList(), begin: begin.value, end: end.value, stops: stops, @@ -42,7 +42,7 @@ extension MiraiGradientParser on MiraiGradient { ); Gradient radialGradient() => RadialGradient( - colors: colors.map((e) => e.toColor!).toList(), + colors: colors.map((e) => e.toColor(context)!).toList(), stops: stops, tileMode: tileMode, focal: focal?.parse, @@ -52,7 +52,7 @@ extension MiraiGradientParser on MiraiGradient { ); Gradient sweepGradient() => SweepGradient( - colors: colors.map((e) => e.toColor!).toList(), + colors: colors.map((e) => e.toColor(context)!).toList(), stops: stops, center: center.value, startAngle: startAngle, diff --git a/packages/mirai/lib/src/parsers/mirai_icon/mirai_icon_parser.dart b/packages/mirai/lib/src/parsers/mirai_icon/mirai_icon_parser.dart index 98e45a08..c58ce1fe 100644 --- a/packages/mirai/lib/src/parsers/mirai_icon/mirai_icon_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_icon/mirai_icon_parser.dart @@ -20,7 +20,7 @@ class MiraiIconParser extends MiraiParser { return Icon( materialIconMap[model.icon], size: model.size, - color: model.color.toColor, + color: model.color.toColor(context), semanticLabel: model.semanticLabel, textDirection: model.textDirection, ); @@ -28,7 +28,7 @@ class MiraiIconParser extends MiraiParser { return Icon( cupertinoIconsMap[model.icon], size: model.size, - color: model.color.toColor, + color: model.color.toColor(context), semanticLabel: model.semanticLabel, textDirection: model.textDirection, ); diff --git a/packages/mirai/lib/src/parsers/mirai_icon_button/mirai_icon_button_parser.dart b/packages/mirai/lib/src/parsers/mirai_icon_button/mirai_icon_button_parser.dart index 40a19b18..441b1f5d 100644 --- a/packages/mirai/lib/src/parsers/mirai_icon_button/mirai_icon_button_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_icon_button/mirai_icon_button_parser.dart @@ -25,13 +25,13 @@ class MiraiIconButtonParser extends MiraiParser { padding: model.padding?.parse, alignment: model.alignment.value, splashRadius: model.splashRadius, - color: model.color.toColor, - focusColor: model.focusColor.toColor, - hoverColor: model.hoverColor.toColor, - highlightColor: model.highlightColor.toColor, - splashColor: model.splashColor.toColor, - disabledColor: model.disabledColor.toColor, - style: model.style?.parseIcon, + color: model.color.toColor(context), + focusColor: model.focusColor.toColor(context), + hoverColor: model.hoverColor.toColor(context), + highlightColor: model.highlightColor.toColor(context), + splashColor: model.splashColor.toColor(context), + disabledColor: model.disabledColor.toColor(context), + style: model.style?.parseIcon(context), autofocus: model.autofocus, isSelected: model.isSelected, selectedIcon: Mirai.fromJson(model.selectedIcon, context), diff --git a/packages/mirai/lib/src/parsers/mirai_icon_theme_data/mirai_icon_theme_data.dart b/packages/mirai/lib/src/parsers/mirai_icon_theme_data/mirai_icon_theme_data.dart index e582a117..4d5fe74f 100644 --- a/packages/mirai/lib/src/parsers/mirai_icon_theme_data/mirai_icon_theme_data.dart +++ b/packages/mirai/lib/src/parsers/mirai_icon_theme_data/mirai_icon_theme_data.dart @@ -24,16 +24,16 @@ class MiraiIconThemeData with _$MiraiIconThemeData { } extension MiraiIconThemeDataParser on MiraiIconThemeData { - IconThemeData? get parse { + IconThemeData? parse(BuildContext context) { return IconThemeData( size: size, fill: fill, weight: weight, grade: grade, opticalSize: opticalSize, - color: color.toColor, + color: color.toColor(context), opacity: opacity, - shadows: shadows?.map((shadow) => shadow.parse).toList(), + shadows: shadows?.map((shadow) => shadow.parse(context)).toList(), ); } } diff --git a/packages/mirai/lib/src/parsers/mirai_image/mirai_image_parser.dart b/packages/mirai/lib/src/parsers/mirai_image/mirai_image_parser.dart index 633085b1..63f26306 100644 --- a/packages/mirai/lib/src/parsers/mirai_image/mirai_image_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_image/mirai_image_parser.dart @@ -19,21 +19,21 @@ class MiraiImageParser extends MiraiParser { Widget parse(BuildContext context, MiraiImage model) { switch (model.imageType) { case MiraiImageType.network: - return _networkImage(model); + return _networkImage(model, context); case MiraiImageType.file: - return _fileImage(model); + return _fileImage(model, context); case MiraiImageType.asset: - return _assetImage(model); + return _assetImage(model, context); default: - return _networkImage(model); + return _networkImage(model, context); } } - Widget _networkImage(MiraiImage model) => Image.network( + Widget _networkImage(MiraiImage model, BuildContext context) => Image.network( model.src, alignment: model.alignment.value, - color: model.color?.toColor, + color: model.color?.toColor(context), width: model.width, height: model.height, fit: model.fit, @@ -41,10 +41,10 @@ class MiraiImageParser extends MiraiParser { return const SizedBox(); }, ); - Widget _fileImage(MiraiImage model) => Image.file( + Widget _fileImage(MiraiImage model, BuildContext context) => Image.file( File(model.src), alignment: model.alignment.value, - color: model.color?.toColor, + color: model.color?.toColor(context), width: model.width, height: model.height, fit: model.fit, @@ -53,10 +53,10 @@ class MiraiImageParser extends MiraiParser { }, ); - Widget _assetImage(MiraiImage model) => Image.asset( + Widget _assetImage(MiraiImage model, BuildContext context) => Image.asset( model.src, alignment: model.alignment.value, - color: model.color?.toColor, + color: model.color?.toColor(context), width: model.width, height: model.height, fit: model.fit, diff --git a/packages/mirai/lib/src/parsers/mirai_input_border/mirai_input_border.dart b/packages/mirai/lib/src/parsers/mirai_input_border/mirai_input_border.dart index a6878708..45a2fa0d 100644 --- a/packages/mirai/lib/src/parsers/mirai_input_border/mirai_input_border.dart +++ b/packages/mirai/lib/src/parsers/mirai_input_border/mirai_input_border.dart @@ -27,14 +27,14 @@ class MiraiInputBorder with _$MiraiInputBorder { } extension MiraiInputBorderParser on MiraiInputBorder { - InputBorder get parse { + InputBorder parse(BuildContext context) { switch (type) { case MiraiInputBorderType.none: return InputBorder.none; case MiraiInputBorderType.underlineInputBorder: return UnderlineInputBorder( borderSide: BorderSide( - color: color?.toColor ?? Colors.black, + color: color?.toColor(context) ?? Colors.black, width: width, ), borderRadius: borderRadius.parse, @@ -44,8 +44,8 @@ extension MiraiInputBorderParser on MiraiInputBorder { width: width, borderRadius: borderRadius.parse, gapPadding: gapPadding, - color: color?.toColor ?? Colors.black, - gradient: gradient?.parse, + color: color?.toColor(context) ?? Colors.black, + gradient: gradient?.parse(context), ); } } diff --git a/packages/mirai/lib/src/parsers/mirai_input_decoration/mirai_input_decoration.dart b/packages/mirai/lib/src/parsers/mirai_input_decoration/mirai_input_decoration.dart index 75d906eb..b05c4600 100644 --- a/packages/mirai/lib/src/parsers/mirai_input_decoration/mirai_input_decoration.dart +++ b/packages/mirai/lib/src/parsers/mirai_input_decoration/mirai_input_decoration.dart @@ -74,20 +74,20 @@ extension MiraiInputDecorationParser on MiraiInputDecoration? { InputDecoration parse(BuildContext context) { return InputDecoration( icon: Mirai.fromJson(this?.icon, context), - iconColor: this?.iconColor.toColor, + iconColor: this?.iconColor.toColor(context), label: Mirai.fromJson(this?.label, context), labelText: this?.labelText, - labelStyle: this?.labelStyle?.parse, - floatingLabelStyle: this?.floatingLabelStyle?.parse, + labelStyle: this?.labelStyle?.parse(context), + floatingLabelStyle: this?.floatingLabelStyle?.parse(context), helperText: this?.helperText, - helperStyle: this?.helperStyle?.parse, + helperStyle: this?.helperStyle?.parse(context), helperMaxLines: this?.helperMaxLines, hintText: this?.hintText, - hintStyle: this?.hintStyle?.parse, + hintStyle: this?.hintStyle?.parse(context), hintTextDirection: this?.hintTextDirection, hintMaxLines: this?.hintMaxLines, errorText: this?.errorText, - errorStyle: this?.errorStyle?.parse, + errorStyle: this?.errorStyle?.parse(context), errorMaxLines: this?.errorMaxLines, floatingLabelBehavior: this?.floatingLabelBehavior, floatingLabelAlignment: this?.floatingLabelAlignment?.parse, @@ -98,27 +98,27 @@ extension MiraiInputDecorationParser on MiraiInputDecoration? { prefixIconConstraints: this?.prefixIconConstraints?.parse, prefix: Mirai.fromJson(this?.prefix, context), prefixText: this?.prefixText, - prefixStyle: this?.prefixStyle?.parse, - prefixIconColor: this?.prefixIconColor?.toColor, + prefixStyle: this?.prefixStyle?.parse(context), + prefixIconColor: this?.prefixIconColor?.toColor(context), suffixIcon: Mirai.fromJson(this?.suffixIcon, context), suffix: Mirai.fromJson(this?.suffix, context), suffixText: this?.suffixText, - suffixStyle: this?.suffixStyle?.parse, - suffixIconColor: this?.suffixIconColor?.toColor, + suffixStyle: this?.suffixStyle?.parse(context), + suffixIconColor: this?.suffixIconColor?.toColor(context), suffixIconConstraints: this?.suffixIconConstraints?.parse, counter: Mirai.fromJson(this?.counter, context), counterText: this?.counterText, - counterStyle: this?.counterStyle?.parse, + counterStyle: this?.counterStyle?.parse(context), filled: this?.filled, - fillColor: this?.fillColor.toColor, - focusColor: this?.focusColor.toColor, - hoverColor: this?.hoverColor.toColor, - errorBorder: this?.errorBorder?.parse, - focusedBorder: this?.focusedBorder?.parse, - focusedErrorBorder: this?.focusedErrorBorder?.parse, - disabledBorder: this?.disabledBorder?.parse, - enabledBorder: this?.enabledBorder?.parse, - border: this?.border?.parse, + fillColor: this?.fillColor.toColor(context), + focusColor: this?.focusColor.toColor(context), + hoverColor: this?.hoverColor.toColor(context), + errorBorder: this?.errorBorder?.parse(context), + focusedBorder: this?.focusedBorder?.parse(context), + focusedErrorBorder: this?.focusedErrorBorder?.parse(context), + disabledBorder: this?.disabledBorder?.parse(context), + enabledBorder: this?.enabledBorder?.parse(context), + border: this?.border?.parse(context), enabled: this?.enabled ?? true, semanticCounterText: this?.semanticCounterText, alignLabelWithHint: this?.alignLabelWithHint, diff --git a/packages/mirai/lib/src/parsers/mirai_input_decoration_theme/mirai_input_decoration_theme.dart b/packages/mirai/lib/src/parsers/mirai_input_decoration_theme/mirai_input_decoration_theme.dart index a789ffca..a61ea920 100644 --- a/packages/mirai/lib/src/parsers/mirai_input_decoration_theme/mirai_input_decoration_theme.dart +++ b/packages/mirai/lib/src/parsers/mirai_input_decoration_theme/mirai_input_decoration_theme.dart @@ -66,14 +66,14 @@ class MiraiInputDecorationTheme with _$MiraiInputDecorationTheme { } extension MiraiInputDecorationThemeParser on MiraiInputDecorationTheme? { - InputDecorationTheme get parse { + InputDecorationTheme parse(BuildContext context) { return InputDecorationTheme( - labelStyle: this?.labelStyle?.parse, - floatingLabelStyle: this?.floatingLabelStyle?.parse, - helperStyle: this?.helperStyle?.parse, + labelStyle: this?.labelStyle?.parse(context), + floatingLabelStyle: this?.floatingLabelStyle?.parse(context), + helperStyle: this?.helperStyle?.parse(context), helperMaxLines: this?.helperMaxLines, - hintStyle: this?.hintStyle?.parse, - errorStyle: this?.errorStyle?.parse, + hintStyle: this?.hintStyle?.parse(context), + errorStyle: this?.errorStyle?.parse(context), errorMaxLines: this?.errorMaxLines, floatingLabelBehavior: this?.floatingLabelBehavior ?? FloatingLabelBehavior.auto, @@ -82,24 +82,24 @@ extension MiraiInputDecorationThemeParser on MiraiInputDecorationTheme? { isDense: this?.isDense ?? false, contentPadding: this?.contentPadding?.parse, isCollapsed: this?.isCollapsed ?? false, - iconColor: this?.iconColor.toColor, - prefixStyle: this?.prefixStyle?.parse, - prefixIconColor: this?.prefixIconColor.toColor, - suffixStyle: this?.suffixStyle?.parse, - suffixIconColor: this?.suffixIconColor.toColor, - counterStyle: this?.counterStyle?.parse, + iconColor: this?.iconColor.toColor(context), + prefixStyle: this?.prefixStyle?.parse(context), + prefixIconColor: this?.prefixIconColor.toColor(context), + suffixStyle: this?.suffixStyle?.parse(context), + suffixIconColor: this?.suffixIconColor.toColor(context), + counterStyle: this?.counterStyle?.parse(context), filled: this?.filled ?? false, - fillColor: this?.fillColor.toColor, - activeIndicatorBorder: this?.activeIndicatorBorder.parse, - outlineBorder: this?.outlineBorder.parse, - focusColor: this?.focusColor.toColor, - hoverColor: this?.hoverColor.toColor, - errorBorder: this?.errorBorder?.parse, - focusedBorder: this?.focusedBorder?.parse, - focusedErrorBorder: this?.focusedErrorBorder?.parse, - disabledBorder: this?.disabledBorder?.parse, - enabledBorder: this?.enabledBorder?.parse, - border: this?.border?.parse, + fillColor: this?.fillColor.toColor(context), + activeIndicatorBorder: this?.activeIndicatorBorder.parse(context), + outlineBorder: this?.outlineBorder.parse(context), + focusColor: this?.focusColor.toColor(context), + hoverColor: this?.hoverColor.toColor(context), + errorBorder: this?.errorBorder?.parse(context), + focusedBorder: this?.focusedBorder?.parse(context), + focusedErrorBorder: this?.focusedErrorBorder?.parse(context), + disabledBorder: this?.disabledBorder?.parse(context), + enabledBorder: this?.enabledBorder?.parse(context), + border: this?.border?.parse(context), alignLabelWithHint: this?.alignLabelWithHint ?? false, constraints: this?.constraints?.parse, ); diff --git a/packages/mirai/lib/src/parsers/mirai_list_tile/mirai_list_tile_parser.dart b/packages/mirai/lib/src/parsers/mirai_list_tile/mirai_list_tile_parser.dart index 1fdc6bb4..d54820e3 100644 --- a/packages/mirai/lib/src/parsers/mirai_list_tile/mirai_list_tile_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_list_tile/mirai_list_tile_parser.dart @@ -28,17 +28,17 @@ class MiraiListTileParser extends MiraiParser { isThreeLine: model.isThreeLine, dense: model.dense, style: model.style, - selectedColor: model.selectedColor?.toColor, - iconColor: model.iconColor?.toColor, - textColor: model.textColor?.toColor, + selectedColor: model.selectedColor?.toColor(context), + iconColor: model.iconColor?.toColor(context), + textColor: model.textColor?.toColor(context), contentPadding: model.contentPadding?.parse, enabled: model.enabled, selected: model.selected, - focusColor: model.focusColor?.toColor, - hoverColor: model.hoverColor?.toColor, + focusColor: model.focusColor?.toColor(context), + hoverColor: model.hoverColor?.toColor(context), autofocus: model.autofocus, - tileColor: model.tileColor?.toColor, - selectedTileColor: model.selectedTileColor?.toColor, + tileColor: model.tileColor?.toColor(context), + selectedTileColor: model.selectedTileColor?.toColor(context), enableFeedback: model.enableFeedback, horizontalTitleGap: model.horizontalTitleGap, minVerticalPadding: model.minVerticalPadding, diff --git a/packages/mirai/lib/src/parsers/mirai_list_tile_theme_data/mirai_list_tile_theme_data.dart b/packages/mirai/lib/src/parsers/mirai_list_tile_theme_data/mirai_list_tile_theme_data.dart index 5dab6346..2f01849f 100644 --- a/packages/mirai/lib/src/parsers/mirai_list_tile_theme_data/mirai_list_tile_theme_data.dart +++ b/packages/mirai/lib/src/parsers/mirai_list_tile_theme_data/mirai_list_tile_theme_data.dart @@ -41,20 +41,20 @@ class MiraiListTileThemeData with _$MiraiListTileThemeData { } extension MiraiListTileThemeDataParser on MiraiListTileThemeData { - ListTileThemeData get parse { + ListTileThemeData parse(BuildContext context) { return ListTileThemeData( dense: dense, - shape: shape?.parse, + shape: shape?.parse(context), style: style, - selectedColor: selectedColor.toColor, - iconColor: iconColor.toColor, - textColor: textColor.toColor, - titleTextStyle: titleTextStyle?.parse, - subtitleTextStyle: subtitleTextStyle?.parse, - leadingAndTrailingTextStyle: leadingAndTrailingTextStyle?.parse, + selectedColor: selectedColor.toColor(context), + iconColor: iconColor.toColor(context), + textColor: textColor.toColor(context), + titleTextStyle: titleTextStyle?.parse(context), + subtitleTextStyle: subtitleTextStyle?.parse(context), + leadingAndTrailingTextStyle: leadingAndTrailingTextStyle?.parse(context), contentPadding: contentPadding.parse, - tileColor: tileColor.toColor, - selectedTileColor: selectedTileColor.toColor, + tileColor: tileColor.toColor(context), + selectedTileColor: selectedTileColor.toColor(context), horizontalTitleGap: horizontalTitleGap, minVerticalPadding: minVerticalPadding, minLeadingWidth: minLeadingWidth, diff --git a/packages/mirai/lib/src/parsers/mirai_material_color/mirai_material_color.dart b/packages/mirai/lib/src/parsers/mirai_material_color/mirai_material_color.dart index 5f61caf2..4387dd85 100644 --- a/packages/mirai/lib/src/parsers/mirai_material_color/mirai_material_color.dart +++ b/packages/mirai/lib/src/parsers/mirai_material_color/mirai_material_color.dart @@ -26,22 +26,22 @@ class MiraiMaterialColor with _$MiraiMaterialColor { } extension MiraiThemeParser on MiraiMaterialColor { - MaterialColor get parse { + MaterialColor parse(BuildContext context) { Map color = { - 50: shade50.toColor!, - 100: shade100.toColor!, - 200: shade200.toColor!, - 300: shade300.toColor!, - 400: shade400.toColor!, - 500: shade500.toColor!, - 600: shade600.toColor!, - 700: shade700.toColor!, - 800: shade800.toColor!, - 900: shade900.toColor!, + 50: shade50.toColor(context)!, + 100: shade100.toColor(context)!, + 200: shade200.toColor(context)!, + 300: shade300.toColor(context)!, + 400: shade400.toColor(context)!, + 500: shade500.toColor(context)!, + 600: shade600.toColor(context)!, + 700: shade700.toColor(context)!, + 800: shade800.toColor(context)!, + 900: shade900.toColor(context)!, }; return MaterialColor( - (primary.toColor)!.value, + (primary.toColor(context))!.value, color, ); } diff --git a/packages/mirai/lib/src/parsers/mirai_navigation_bar_item/mirai_bottom_navigation_bar_item.dart b/packages/mirai/lib/src/parsers/mirai_navigation_bar_item/mirai_bottom_navigation_bar_item.dart index c91dc88f..7d29fc8a 100644 --- a/packages/mirai/lib/src/parsers/mirai_navigation_bar_item/mirai_bottom_navigation_bar_item.dart +++ b/packages/mirai/lib/src/parsers/mirai_navigation_bar_item/mirai_bottom_navigation_bar_item.dart @@ -27,7 +27,7 @@ extension MiraiBottomNavigationBarItemParser on MiraiBottomNavigationBarItem { activeIcon: activeIcon == null ? null : Mirai.fromJson(activeIcon, context), label: label, - backgroundColor: backgroundColor?.toColor, + backgroundColor: backgroundColor?.toColor(context), tooltip: tooltip, ); } diff --git a/packages/mirai/lib/src/parsers/mirai_navigation_bar_theme_data/mirai_navigation_bar_theme_data.dart b/packages/mirai/lib/src/parsers/mirai_navigation_bar_theme_data/mirai_navigation_bar_theme_data.dart index 40458be4..28cc1131 100644 --- a/packages/mirai/lib/src/parsers/mirai_navigation_bar_theme_data/mirai_navigation_bar_theme_data.dart +++ b/packages/mirai/lib/src/parsers/mirai_navigation_bar_theme_data/mirai_navigation_bar_theme_data.dart @@ -28,17 +28,17 @@ class MiraiNavigationBarThemeData with _$MiraiNavigationBarThemeData { } extension MiraiNavigationBarThemeDataParser on MiraiNavigationBarThemeData { - NavigationBarThemeData? get parse { + NavigationBarThemeData? parse(BuildContext context) { return NavigationBarThemeData( height: height, - backgroundColor: backgroundColor.toColor, + backgroundColor: backgroundColor.toColor(context), elevation: elevation, - shadowColor: shadowColor.toColor, - surfaceTintColor: surfaceTintColor.toColor, - indicatorColor: indicatorColor.toColor, - indicatorShape: indicatorShape?.parse, - labelTextStyle: MaterialStateProperty.all(labelTextStyle?.parse), - iconTheme: MaterialStateProperty.all(iconTheme?.parse), + shadowColor: shadowColor.toColor(context), + surfaceTintColor: surfaceTintColor.toColor(context), + indicatorColor: indicatorColor.toColor(context), + indicatorShape: indicatorShape?.parse(context), + labelTextStyle: MaterialStateProperty.all(labelTextStyle?.parse(context)), + iconTheme: MaterialStateProperty.all(iconTheme?.parse(context)), labelBehavior: labelBehavior, ); } diff --git a/packages/mirai/lib/src/parsers/mirai_outlined_button/mirai_outlined_button_parser.dart b/packages/mirai/lib/src/parsers/mirai_outlined_button/mirai_outlined_button_parser.dart index e2340258..fc6eeaca 100644 --- a/packages/mirai/lib/src/parsers/mirai_outlined_button/mirai_outlined_button_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_outlined_button/mirai_outlined_button_parser.dart @@ -20,7 +20,7 @@ class MiraiOutlinedButtonParser extends MiraiParser { onPressed: model.onPressed == null ? null : () => Mirai.onCallFromJson(model.onPressed, context), - style: model.style?.parseOutlined, + style: model.style?.parseOutlined(context), autofocus: model.autofocus, clipBehavior: model.clipBehavior, child: Mirai.fromJson(model.child, context), diff --git a/packages/mirai/lib/src/parsers/mirai_rounded_rectangle_border/mirai_rounded_rectangle_border.dart b/packages/mirai/lib/src/parsers/mirai_rounded_rectangle_border/mirai_rounded_rectangle_border.dart index 509d5f3c..14fd8176 100644 --- a/packages/mirai/lib/src/parsers/mirai_rounded_rectangle_border/mirai_rounded_rectangle_border.dart +++ b/packages/mirai/lib/src/parsers/mirai_rounded_rectangle_border/mirai_rounded_rectangle_border.dart @@ -17,9 +17,9 @@ class MiraiRoundedRectangleBorder with _$MiraiRoundedRectangleBorder { } extension MiraiRoundedRectangleBorderParser on MiraiRoundedRectangleBorder? { - RoundedRectangleBorder get parse { + RoundedRectangleBorder parse(BuildContext context) { return RoundedRectangleBorder( - side: this?.side.parse ?? BorderSide.none, + side: this?.side.parse(context) ?? BorderSide.none, borderRadius: this?.borderRadius.parse ?? BorderRadius.zero, ); } diff --git a/packages/mirai/lib/src/parsers/mirai_scaffold/mirai_scaffold_parser.dart b/packages/mirai/lib/src/parsers/mirai_scaffold/mirai_scaffold_parser.dart index f75b6df6..48843fd1 100644 --- a/packages/mirai/lib/src/parsers/mirai_scaffold/mirai_scaffold_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_scaffold/mirai_scaffold_parser.dart @@ -24,7 +24,7 @@ class MiraiScaffoldParser extends MiraiParser { floatingActionButtonLocation: model.floatingActionButtonLocation?.value, bottomNavigationBar: Mirai.fromJson(model.bottomNavigationBar, context), bottomSheet: Mirai.fromJson(model.bottomSheet, context), - backgroundColor: model.backgroundColor.toColor, + backgroundColor: model.backgroundColor.toColor(context), resizeToAvoidBottomInset: model.resizeToAvoidBottomInset, primary: model.primary, extendBody: model.extendBody, diff --git a/packages/mirai/lib/src/parsers/mirai_shadow/mirai_shadow.dart b/packages/mirai/lib/src/parsers/mirai_shadow/mirai_shadow.dart index f3f12a03..40556bde 100644 --- a/packages/mirai/lib/src/parsers/mirai_shadow/mirai_shadow.dart +++ b/packages/mirai/lib/src/parsers/mirai_shadow/mirai_shadow.dart @@ -19,9 +19,9 @@ class MiraiShadow with _$MiraiShadow { } extension MiraiShadowParser on MiraiShadow { - Shadow get parse { + Shadow parse(BuildContext context) { return Shadow( - color: color.toColor!, + color: color.toColor(context)!, offset: offset.parse, blurRadius: blurRadius, ); diff --git a/packages/mirai/lib/src/parsers/mirai_switch/mirai_switch.dart b/packages/mirai/lib/src/parsers/mirai_switch/mirai_switch.dart index f412bac8..9c9a8ae4 100644 --- a/packages/mirai/lib/src/parsers/mirai_switch/mirai_switch.dart +++ b/packages/mirai/lib/src/parsers/mirai_switch/mirai_switch.dart @@ -48,17 +48,21 @@ class MiraiSwitch with _$MiraiSwitch { ); } - Color? get activeColorValue => activeColor?.toColor; + Color? activeColorValue(BuildContext context) => + activeColor?.toColor(context); - Color? get activeTrackColorValue => activeTrackColor?.toColor; + Color? activeTrackColorValue(BuildContext context) => + activeTrackColor?.toColor(context); - Color? get focusColorValue => focusColor?.toColor; + Color? focusColorValue(BuildContext context) => focusColor?.toColor(context); - Color? get hoverColorValue => hoverColor?.toColor; + Color? hoverColorValue(BuildContext context) => hoverColor?.toColor(context); - Color? get inactiveThumbColorValue => inactiveThumbColor?.toColor; + Color? inactiveThumbColorValue(BuildContext context) => + inactiveThumbColor?.toColor(context); - Color? get inactiveTrackColorValue => inactiveTrackColor?.toColor; + Color? inactiveTrackColorValue(BuildContext context) => + inactiveTrackColor?.toColor(context); MaterialTapTargetSize? get materialTapTargetSizeValue { return MaterialTapTargetSize.values.firstWhere( diff --git a/packages/mirai/lib/src/parsers/mirai_switch/widget/mirai_switch_widget.dart b/packages/mirai/lib/src/parsers/mirai_switch/widget/mirai_switch_widget.dart index 6fa0e88d..8cf34d74 100644 --- a/packages/mirai/lib/src/parsers/mirai_switch/widget/mirai_switch_widget.dart +++ b/packages/mirai/lib/src/parsers/mirai_switch/widget/mirai_switch_widget.dart @@ -42,6 +42,7 @@ class _MiraiSwitchUiWidget extends State { switch (model.switchType) { case MiraiSwitchType.cupertino: return _buildCupertinoSwitch( + context, model, isSelected: isSelected, onChanged: _changeValue, @@ -66,6 +67,7 @@ class _MiraiSwitchUiWidget extends State { } Widget _buildCupertinoSwitch( + BuildContext context, MiraiSwitch model, { required bool isSelected, required void Function(bool value) onChanged, @@ -73,12 +75,12 @@ Widget _buildCupertinoSwitch( return CupertinoSwitch( value: isSelected, onChanged: !model.disabled ? onChanged : null, - thumbColor: model.thumbColor?.parse, + thumbColor: model.thumbColor?.parse(context), dragStartBehavior: model.dragStateBehaviorValue, - trackColor: model.trackColor?.parse, - activeColor: model.activeColorValue, + trackColor: model.trackColor?.parse(context), + activeColor: model.activeColorValue(context), autofocus: model.autofocus, - focusColor: model.focusColorValue, + focusColor: model.focusColorValue(context), ); } @@ -91,21 +93,21 @@ Widget _buildAdaptiveSwitch( return Switch.adaptive( value: isSelected, onChanged: !model.disabled ? onChanged : null, - activeColor: model.activeColorValue, - activeTrackColor: model.activeTrackColorValue, + activeColor: model.activeColorValue(context), + activeTrackColor: model.activeTrackColorValue(context), autofocus: model.autofocus, - focusColor: model.focusColorValue, - hoverColor: model.hoverColorValue, - inactiveThumbColor: model.inactiveThumbColorValue, - inactiveTrackColor: model.inactiveTrackColorValue, + focusColor: model.focusColorValue(context), + hoverColor: model.hoverColorValue(context), + inactiveThumbColor: model.inactiveThumbColorValue(context), + inactiveTrackColor: model.inactiveTrackColorValue(context), splashRadius: model.splashRadius, dragStartBehavior: model.dragStateBehaviorValue, materialTapTargetSize: model.materialTapTargetSizeValue, - overlayColor: MaterialStateProperty.all(model.overlayColor?.parse), - thumbColor: MaterialStateProperty.all(model.thumbColor?.parse), - trackColor: MaterialStateProperty.all(model.trackColor?.parse), + overlayColor: MaterialStateProperty.all(model.overlayColor?.parse(context)), + thumbColor: MaterialStateProperty.all(model.thumbColor?.parse(context)), + trackColor: MaterialStateProperty.all(model.trackColor?.parse(context)), trackOutlineColor: - MaterialStateProperty.all(model.trackOutlineColor?.parse), + MaterialStateProperty.all(model.trackOutlineColor?.parse(context)), trackOutlineWidth: MaterialStateProperty.all(model.trackOutlineWidth), thumbIcon: MaterialStateProperty.all(model.thumbIconWidget(context)), inactiveThumbImage: model.inactiveThumbImageWidget(context), @@ -122,21 +124,21 @@ Widget _buildMaterialSwitch( return Switch( value: isSelected, onChanged: !model.disabled ? onChanged : null, - activeColor: model.activeColorValue, - activeTrackColor: model.activeTrackColorValue, + activeColor: model.activeColorValue(context), + activeTrackColor: model.activeTrackColorValue(context), autofocus: model.autofocus, - focusColor: model.focusColorValue, - hoverColor: model.hoverColorValue, - inactiveThumbColor: model.inactiveThumbColorValue, - inactiveTrackColor: model.inactiveTrackColorValue, + focusColor: model.focusColorValue(context), + hoverColor: model.hoverColorValue(context), + inactiveThumbColor: model.inactiveThumbColorValue(context), + inactiveTrackColor: model.inactiveTrackColorValue(context), splashRadius: model.splashRadius, dragStartBehavior: model.dragStateBehaviorValue, materialTapTargetSize: model.materialTapTargetSizeValue, - overlayColor: MaterialStateProperty.all(model.overlayColor?.parse), - thumbColor: MaterialStateProperty.all(model.thumbColor?.parse), - trackColor: MaterialStateProperty.all(model.trackColor?.parse), + overlayColor: MaterialStateProperty.all(model.overlayColor?.parse(context)), + thumbColor: MaterialStateProperty.all(model.thumbColor?.parse(context)), + trackColor: MaterialStateProperty.all(model.trackColor?.parse(context)), trackOutlineColor: - MaterialStateProperty.all(model.trackOutlineColor?.parse), + MaterialStateProperty.all(model.trackOutlineColor?.parse(context)), trackOutlineWidth: MaterialStateProperty.all(model.trackOutlineWidth), thumbIcon: MaterialStateProperty.all(model.thumbIconWidget(context)), inactiveThumbImage: model.inactiveThumbImageWidget(context), diff --git a/packages/mirai/lib/src/parsers/mirai_system_ui_olverlay_style/mirai_system_ui_overlay_style.dart b/packages/mirai/lib/src/parsers/mirai_system_ui_olverlay_style/mirai_system_ui_overlay_style.dart index 138e0ce3..3054737a 100644 --- a/packages/mirai/lib/src/parsers/mirai_system_ui_olverlay_style/mirai_system_ui_overlay_style.dart +++ b/packages/mirai/lib/src/parsers/mirai_system_ui_olverlay_style/mirai_system_ui_overlay_style.dart @@ -1,3 +1,4 @@ +import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:mirai/src/utils/color_utils.dart'; @@ -23,13 +24,14 @@ class MiraiSystemUIOverlayStyle with _$MiraiSystemUIOverlayStyle { } extension MiraiSystemUIOverlayStyleParser on MiraiSystemUIOverlayStyle { - SystemUiOverlayStyle get parse { + SystemUiOverlayStyle parse(BuildContext context) { return SystemUiOverlayStyle( - systemNavigationBarColor: systemNavigationBarColor.toColor, - systemNavigationBarDividerColor: systemNavigationBarDividerColor.toColor, + systemNavigationBarColor: systemNavigationBarColor.toColor(context), + systemNavigationBarDividerColor: + systemNavigationBarDividerColor.toColor(context), systemNavigationBarIconBrightness: systemNavigationBarIconBrightness, systemNavigationBarContrastEnforced: systemNavigationBarContrastEnforced, - statusBarColor: statusBarColor.toColor, + statusBarColor: statusBarColor.toColor(context), statusBarBrightness: statusBarBrightness, statusBarIconBrightness: statusBarIconBrightness, systemStatusBarContrastEnforced: systemStatusBarContrastEnforced, diff --git a/packages/mirai/lib/src/parsers/mirai_tab_bar/mirai_tab_bar_parser.dart b/packages/mirai/lib/src/parsers/mirai_tab_bar/mirai_tab_bar_parser.dart index 2c00ded6..bdae6df6 100644 --- a/packages/mirai/lib/src/parsers/mirai_tab_bar/mirai_tab_bar_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_tab_bar/mirai_tab_bar_parser.dart @@ -27,17 +27,17 @@ class MiraiTabBarParser extends MiraiParser { .toList(), isScrollable: model.isScrollable, padding: model.padding?.parse, - indicatorColor: model.indicatorColor?.toColor, + indicatorColor: model.indicatorColor?.toColor(context), automaticIndicatorColorAdjustment: model.automaticIndicatorColorAdjustment, indicatorWeight: model.indicatorWeight, indicatorPadding: model.indicatorPadding.parse, indicatorSize: model.indicatorSize, - labelColor: model.labelColor.toColor, - labelStyle: model.labelStyle?.parse, + labelColor: model.labelColor.toColor(context), + labelStyle: model.labelStyle?.parse(context), labelPadding: model.labelPadding.parse, - unselectedLabelColor: model.unselectedLabelColor.toColor, - unselectedLabelStyle: model.unselectedLabelStyle?.parse, + unselectedLabelColor: model.unselectedLabelColor.toColor(context), + unselectedLabelStyle: model.unselectedLabelStyle?.parse(context), dragStartBehavior: model.dragStartBehavior, enableFeedback: model.enableFeedback, onTap: (_) {}, diff --git a/packages/mirai/lib/src/parsers/mirai_tab_bar_theme_data/mirai_tab_bar_theme_data.dart b/packages/mirai/lib/src/parsers/mirai_tab_bar_theme_data/mirai_tab_bar_theme_data.dart index 7926322f..e86bf85a 100644 --- a/packages/mirai/lib/src/parsers/mirai_tab_bar_theme_data/mirai_tab_bar_theme_data.dart +++ b/packages/mirai/lib/src/parsers/mirai_tab_bar_theme_data/mirai_tab_bar_theme_data.dart @@ -28,18 +28,18 @@ class MiraiTabBarThemeData with _$MiraiTabBarThemeData { } extension MiraiTabBarThemeDataParser on MiraiTabBarThemeData { - TabBarTheme? get parse { + TabBarTheme? parse(BuildContext context) { return TabBarTheme( - indicator: indicator.parse, - indicatorColor: indicatorColor.toColor, + indicator: indicator.parse(context), + indicatorColor: indicatorColor.toColor(context), indicatorSize: indicatorSize, - dividerColor: dividerColor.toColor, - labelColor: labelColor.toColor, + dividerColor: dividerColor.toColor(context), + labelColor: labelColor.toColor(context), labelPadding: labelPadding.parse, - labelStyle: labelStyle?.parse, - unselectedLabelColor: unselectedLabelColor.toColor, - unselectedLabelStyle: unselectedLabelStyle?.parse, - overlayColor: MaterialStateProperty.all(overlayColor.toColor), + labelStyle: labelStyle?.parse(context), + unselectedLabelColor: unselectedLabelColor.toColor(context), + unselectedLabelStyle: unselectedLabelStyle?.parse(context), + overlayColor: MaterialStateProperty.all(overlayColor.toColor(context)), ); } } diff --git a/packages/mirai/lib/src/parsers/mirai_text/mirai_text_parser.dart b/packages/mirai/lib/src/parsers/mirai_text/mirai_text_parser.dart index bdf26cac..c583ec0b 100644 --- a/packages/mirai/lib/src/parsers/mirai_text/mirai_text_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_text/mirai_text_parser.dart @@ -25,14 +25,14 @@ class MiraiTextParser extends MiraiParser { .map( (child) => TextSpan( text: child.data, - style: child.style?.parse, + style: child.style?.parse(context), recognizer: TapGestureRecognizer() ..onTap = () => Mirai.onCallFromJson(child.onTap, context), ), ) .toList(), ), - style: model.style?.parse, + style: model.style?.parse(context), textAlign: model.textAlign, textDirection: model.textDirection, softWrap: model.softWrap, @@ -41,7 +41,7 @@ class MiraiTextParser extends MiraiParser { maxLines: model.maxLines, semanticsLabel: model.semanticsLabel, textWidthBasis: model.textWidthBasis, - selectionColor: model.selectionColor.toColor, + selectionColor: model.selectionColor.toColor(context), ); } } diff --git a/packages/mirai/lib/src/parsers/mirai_text_button/mirai_text_button_parser.dart b/packages/mirai/lib/src/parsers/mirai_text_button/mirai_text_button_parser.dart index 923a3512..c517747a 100644 --- a/packages/mirai/lib/src/parsers/mirai_text_button/mirai_text_button_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_text_button/mirai_text_button_parser.dart @@ -20,7 +20,7 @@ class MiraiTextButtonParser extends MiraiParser { onPressed: model.onPressed == null ? null : () => Mirai.onCallFromJson(model.onPressed, context), - style: model.style?.parseText, + style: model.style?.parseText(context), autofocus: model.autofocus, clipBehavior: model.clipBehavior, child: Mirai.fromJson(model.child, context) ?? const SizedBox(), diff --git a/packages/mirai/lib/src/parsers/mirai_text_field/mirai_text_field_parser.dart b/packages/mirai/lib/src/parsers/mirai_text_field/mirai_text_field_parser.dart index fcba3683..94a8aa16 100644 --- a/packages/mirai/lib/src/parsers/mirai_text_field/mirai_text_field_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_text_field/mirai_text_field_parser.dart @@ -49,8 +49,8 @@ class MiraiTextFieldParser extends MiraiParser { expands: model.expands, cursorWidth: model.cursorWidth, cursorHeight: model.cursorHeight, - cursorColor: model.cursorColor?.toColor, - style: model.style?.parse, + cursorColor: model.cursorColor?.toColor(context), + style: model.style?.parse(context), decoration: model.decoration?.parse(context), inputFormatters: model.inputFormatters .map((MiraiInputFormatter formatter) => diff --git a/packages/mirai/lib/src/parsers/mirai_text_form_field/mirai_text_form_field_parser.dart b/packages/mirai/lib/src/parsers/mirai_text_form_field/mirai_text_form_field_parser.dart index f39d57ce..f2a19464 100644 --- a/packages/mirai/lib/src/parsers/mirai_text_form_field/mirai_text_form_field_parser.dart +++ b/packages/mirai/lib/src/parsers/mirai_text_form_field/mirai_text_form_field_parser.dart @@ -101,8 +101,8 @@ class __TextFormFieldWidgetState extends State<_TextFormFieldWidget> { enabled: widget.model.enabled, cursorWidth: widget.model.cursorWidth, cursorHeight: widget.model.cursorHeight, - cursorColor: widget.model.cursorColor?.toColor, - style: widget.model.style?.parse, + cursorColor: widget.model.cursorColor?.toColor(context), + style: widget.model.style?.parse(context), decoration: _inputDecoration(widget.model), inputFormatters: widget.model.inputFormatters .map((MiraiInputFormatter formatter) => diff --git a/packages/mirai/lib/src/parsers/mirai_text_style/mirai_text_style.dart b/packages/mirai/lib/src/parsers/mirai_text_style/mirai_text_style.dart index 449f0120..62e0d3f0 100644 --- a/packages/mirai/lib/src/parsers/mirai_text_style/mirai_text_style.dart +++ b/packages/mirai/lib/src/parsers/mirai_text_style/mirai_text_style.dart @@ -28,11 +28,11 @@ class MiraiTextStyle with _$MiraiTextStyle { } extension MiraiTextStyleParser on MiraiTextStyle { - TextStyle? get parse { + TextStyle? parse(BuildContext context) { return TextStyle( inherit: inherit, - color: color?.toColor, - backgroundColor: backgroundColor.toColor, + color: color?.toColor(context), + backgroundColor: backgroundColor.toColor(context), fontSize: fontSize, fontWeight: fontWeight?.value, fontStyle: fontStyle, diff --git a/packages/mirai/lib/src/parsers/mirai_theme/mirai_theme.dart b/packages/mirai/lib/src/parsers/mirai_theme/mirai_theme.dart index ef947c64..00be9464 100644 --- a/packages/mirai/lib/src/parsers/mirai_theme/mirai_theme.dart +++ b/packages/mirai/lib/src/parsers/mirai_theme/mirai_theme.dart @@ -73,52 +73,54 @@ class MiraiTheme with _$MiraiTheme { } extension MiraiThemeParser on MiraiTheme { - ThemeData? get parse { + ThemeData? parse(BuildContext context) { return ThemeData( applyElevationOverlayColor: applyElevationOverlayColor, - inputDecorationTheme: inputDecorationTheme.parse, + inputDecorationTheme: inputDecorationTheme.parse(context), useMaterial3: useMaterial3, brightness: brightness, - canvasColor: canvasColor?.toColor, - colorScheme: colorScheme?.parse, - colorSchemeSeed: colorSchemeSeed.toColor, - dialogBackgroundColor: dialogBackgroundColor.toColor, - disabledColor: disabledColor.toColor, - dividerColor: dividerColor.toColor, - focusColor: focusColor.toColor, - highlightColor: highlightColor.toColor, - hintColor: hintColor.toColor, - hoverColor: hoverColor.toColor, - indicatorColor: indicatorColor.toColor, - primaryColor: primaryColor.toColor, - primaryColorDark: primaryColorDark.toColor, - primaryColorLight: primaryColorLight.toColor, - scaffoldBackgroundColor: scaffoldBackgroundColor.toColor, - secondaryHeaderColor: secondaryHeaderColor.toColor, - shadowColor: shadowColor.toColor, - splashColor: splashColor.toColor, - unselectedWidgetColor: unselectedWidgetColor.toColor, + canvasColor: canvasColor?.toColor(context), + colorScheme: colorScheme?.parse(context), + colorSchemeSeed: colorSchemeSeed.toColor(context), + dialogBackgroundColor: dialogBackgroundColor.toColor(context), + disabledColor: disabledColor.toColor(context), + dividerColor: dividerColor.toColor(context), + focusColor: focusColor.toColor(context), + highlightColor: highlightColor.toColor(context), + hintColor: hintColor.toColor(context), + hoverColor: hoverColor.toColor(context), + indicatorColor: indicatorColor.toColor(context), + primaryColor: primaryColor.toColor(context), + primaryColorDark: primaryColorDark.toColor(context), + primaryColorLight: primaryColorLight.toColor(context), + scaffoldBackgroundColor: scaffoldBackgroundColor.toColor(context), + secondaryHeaderColor: secondaryHeaderColor.toColor(context), + shadowColor: shadowColor.toColor(context), + splashColor: splashColor.toColor(context), + unselectedWidgetColor: unselectedWidgetColor.toColor(context), fontFamily: fontFamily, fontFamilyFallback: fontFamilyFallback, - primarySwatch: primarySwatch?.parse, - appBarTheme: appBarTheme?.parse, - elevatedButtonTheme: - ElevatedButtonThemeData(style: elevatedButtonTheme?.parseElevated), - outlinedButtonTheme: - OutlinedButtonThemeData(style: outlinedButtonTheme?.parseOutlined), - iconButtonTheme: IconButtonThemeData(style: iconButtonTheme?.parseIcon), - iconTheme: iconTheme?.parse, - primaryIconTheme: primaryIconTheme?.parse, - dialogTheme: dialogTheme?.parse, - floatingActionButtonTheme: floatingActionButtonTheme?.parse, - textButtonTheme: TextButtonThemeData(style: textButtonTheme?.parseText), - bottomAppBarTheme: bottomAppBarTheme?.parse, - bottomNavigationBarTheme: bottomNavigationBarTheme?.parse, - bottomSheetTheme: bottomSheetTheme?.parse, - cardTheme: cardTheme?.parse, - listTileTheme: listTileTheme?.parse, - navigationBarTheme: navigationBarTheme?.parse, - tabBarTheme: tabBarTheme?.parse, + primarySwatch: primarySwatch?.parse(context), + appBarTheme: appBarTheme?.parse(context), + elevatedButtonTheme: ElevatedButtonThemeData( + style: elevatedButtonTheme?.parseElevated(context)), + outlinedButtonTheme: OutlinedButtonThemeData( + style: outlinedButtonTheme?.parseOutlined(context)), + iconButtonTheme: + IconButtonThemeData(style: iconButtonTheme?.parseIcon(context)), + iconTheme: iconTheme?.parse(context), + primaryIconTheme: primaryIconTheme?.parse(context), + dialogTheme: dialogTheme?.parse(context), + floatingActionButtonTheme: floatingActionButtonTheme?.parse(context), + textButtonTheme: + TextButtonThemeData(style: textButtonTheme?.parseText(context)), + bottomAppBarTheme: bottomAppBarTheme?.parse(context), + bottomNavigationBarTheme: bottomNavigationBarTheme?.parse(context), + bottomSheetTheme: bottomSheetTheme?.parse(context), + cardTheme: cardTheme?.parse(context), + listTileTheme: listTileTheme?.parse(context), + navigationBarTheme: navigationBarTheme?.parse(context), + tabBarTheme: tabBarTheme?.parse(context), ); } } diff --git a/packages/mirai/lib/src/utils/color_type.dart b/packages/mirai/lib/src/utils/color_type.dart new file mode 100644 index 00000000..dda03f5a --- /dev/null +++ b/packages/mirai/lib/src/utils/color_type.dart @@ -0,0 +1,34 @@ +enum ColorType { + primary, + onPrimary, + primaryContainer, + onPrimaryContainer, + secondary, + onSecondary, + secondaryContainer, + onSecondaryContainer, + tertiary, + onTertiary, + tertiaryContainer, + onTertiaryContainer, + error, + onError, + errorContainer, + onErrorContainer, + background, + onBackground, + surface, + onSurface, + surfaceVariant, + onSurfaceVariant, + outline, + outlineVariant, + shadow, + scrim, + inverseSurface, + onInverseSurface, + inversePrimary, + surfaceTint, + scaffoldBackgroundColor, + none, +} diff --git a/packages/mirai/lib/src/utils/color_utils.dart b/packages/mirai/lib/src/utils/color_utils.dart index e04d0a85..3893b367 100644 --- a/packages/mirai/lib/src/utils/color_utils.dart +++ b/packages/mirai/lib/src/utils/color_utils.dart @@ -1,20 +1,85 @@ import 'package:flutter/material.dart'; - -class ColorUtils { - const ColorUtils._(); - - static Color? fromString(String? color) => color.toColor; -} +import 'package:mirai/src/utils/color_type.dart'; extension ColorExt on String? { - Color? get toColor { + Color? toColor(BuildContext context) { if (this?.isEmpty ?? true) return null; - final buffer = StringBuffer(); - if (this!.length == 6 || this!.length == 7) buffer.write('ff'); - buffer.write(this!.replaceFirst('#', '')); - int? intColor = int.tryParse(buffer.toString(), radix: 16); - intColor = intColor ?? 0x00000000; - return Color(intColor); + switch (colorType) { + case ColorType.primary: + return Theme.of(context).colorScheme.primary; + case ColorType.onPrimary: + return Theme.of(context).colorScheme.onPrimary; + case ColorType.primaryContainer: + return Theme.of(context).colorScheme.primaryContainer; + case ColorType.onPrimaryContainer: + return Theme.of(context).colorScheme.onPrimaryContainer; + case ColorType.secondary: + return Theme.of(context).colorScheme.secondary; + case ColorType.onSecondary: + return Theme.of(context).colorScheme.onSecondary; + case ColorType.secondaryContainer: + return Theme.of(context).colorScheme.secondaryContainer; + case ColorType.onSecondaryContainer: + return Theme.of(context).colorScheme.onSecondaryContainer; + case ColorType.tertiary: + return Theme.of(context).colorScheme.tertiary; + case ColorType.onTertiary: + return Theme.of(context).colorScheme.onTertiary; + case ColorType.tertiaryContainer: + return Theme.of(context).colorScheme.tertiaryContainer; + case ColorType.onTertiaryContainer: + return Theme.of(context).colorScheme.onTertiaryContainer; + case ColorType.error: + return Theme.of(context).colorScheme.error; + case ColorType.onError: + return Theme.of(context).colorScheme.onError; + case ColorType.errorContainer: + return Theme.of(context).colorScheme.errorContainer; + case ColorType.onErrorContainer: + return Theme.of(context).colorScheme.onErrorContainer; + case ColorType.background: + return Theme.of(context).colorScheme.background; + case ColorType.onBackground: + return Theme.of(context).colorScheme.onBackground; + case ColorType.surface: + return Theme.of(context).colorScheme.surface; + case ColorType.onSurface: + return Theme.of(context).colorScheme.onSurface; + case ColorType.surfaceVariant: + return Theme.of(context).colorScheme.surfaceVariant; + case ColorType.onSurfaceVariant: + return Theme.of(context).colorScheme.onSurfaceVariant; + case ColorType.outline: + return Theme.of(context).colorScheme.outline; + case ColorType.outlineVariant: + return Theme.of(context).colorScheme.outlineVariant; + case ColorType.shadow: + return Theme.of(context).colorScheme.shadow; + case ColorType.scrim: + return Theme.of(context).colorScheme.scrim; + case ColorType.inverseSurface: + return Theme.of(context).colorScheme.inverseSurface; + case ColorType.onInverseSurface: + return Theme.of(context).colorScheme.onInverseSurface; + case ColorType.inversePrimary: + return Theme.of(context).colorScheme.inversePrimary; + case ColorType.surfaceTint: + return Theme.of(context).colorScheme.surfaceTint; + case ColorType.scaffoldBackgroundColor: + return Theme.of(context).scaffoldBackgroundColor; + case ColorType.none: + final buffer = StringBuffer(); + if (this!.length == 6 || this!.length == 7) buffer.write('ff'); + buffer.write(this!.replaceFirst('#', '')); + int? intColor = int.tryParse(buffer.toString(), radix: 16); + intColor = intColor ?? 0x00000000; + return Color(intColor); + } } + + ColorType get colorType => ColorType.values.firstWhere( + (e) => e.name == this, + orElse: () => ColorType.none, + ); }