diff --git a/README.md b/README.md index 3557897e..e68c8f0b 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,6 @@ builder: (context, themeData, themeMode) { To tie everything together, use the `ZetaProvider` constructor. The `builder` argument is mandatory, while the others are optional but allow you to set initial values: ```dart - @override Widget build(BuildContext context) { return ZetaProvider( @@ -104,6 +103,67 @@ To tie everything together, use the `ZetaProvider` constructor. The `builder` ar } ``` +### Customization + +#### Creating custom themes + +Custom themes can be made by creating `ZetaCustomTheme` objects. `ZetaCustomTheme` can be constructed by passing in a primary or secondary color and, optionally, their dark variants: + +```dart +ZetaCustomTheme( + id: 'custom-theme-red', + primary: Colors.red, + primaryDark : // Dark variant here, + secondary: Colors.blue, + secondaryDark: // Dark variant here, +) +``` + +Color arguments can be of type `ZetaColorSwatch`, `MaterialColor`, or `Color`. If only a `Color` is provided, Zeta will generate a `ZetaColorSwatch`. To have control over every shade of a given color, we reccomend providing either a `ZetaColorSwatch` or a `MaterialColor`. + +If a dark variant of a color is not provided, Zeta generate one by inverting the corresponding color swatch. + +#### Adding custom themes + +Once you have defined the custom themes for your app, give them to the ZetaProvider by passing them through the construtor. You can also initialize the custom theme by setting the `initialTheme` argument to the id of the desired theme. + +```dart + ZetaProvider( + initialTheme: 'custom-theme-red' + customThemes: [ + ZetaCustomTheme( + id: 'custom-theme-red', + primary: Colors.red, + secondary: Colors.purple + ), + ZetaCustomTheme( + id: 'custom-theme-purple', + primary: Colors.purple, + secondary: Colors.green + ), + ] + ) +``` + +You can also get and set the custom themes via the `ZetaProvider`: + +`ZetaProvider.of(context).customThemes` +`ZetaProvider.of(context).setCustomThemes(newCustomThemes)` + +#### Changing the custom theme + +To change the custom theme, call the `updateCustomTheme` function on `ZetaProvider` with an id corresponding to a `ZetaCustomTheme` object: + +`ZetaProvider.of(context).updateCustomTheme('custom-theme-purple')` + +If the id provided does not correspond to a given theme, Zeta will fall back to its default theme. + +You can fetch the id of the currently applied custom theme via the `Zeta` object: + +`Zeta.of(context).customThemeId` + +This will return null if no custom theme is in use. + With these configurations, Zeta makes it easy to achieve consistent theming throughout your Flutter application. ## Licensing diff --git a/example/lib/main.dart b/example/lib/main.dart index 3bffbb27..f713dc16 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,46 +1,58 @@ import 'package:flutter/material.dart'; -import 'package:shared_preferences/shared_preferences.dart'; -import 'package:zeta_example/theme_service.dart'; import 'package:zeta_flutter/zeta_flutter.dart'; import 'home.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); - final preferences = await SharedPreferences.getInstance(); - final themeService = SharedPrefsThemeService(preferences); - final themePreferences = await themeService.loadTheme(); - - runApp( - ZetaExample( - themeService: themeService, - initialZetaThemeData: themePreferences.$1 ?? ZetaThemeData(), - initialThemeMode: themePreferences.$2 ?? ThemeMode.system, - initialContrast: themePreferences.$3 ?? ZetaContrast.aa, - ), - ); + runApp(ZetaExample()); } class ZetaExample extends StatelessWidget { - const ZetaExample({ - super.key, - required this.themeService, - required this.initialContrast, - required this.initialThemeMode, - required this.initialZetaThemeData, - }); - - final ZetaThemeService themeService; - final ZetaContrast initialContrast; - final ThemeMode initialThemeMode; - final ZetaThemeData initialZetaThemeData; + const ZetaExample({super.key}); @override Widget build(BuildContext context) { - return ZetaProvider.base( - initialZetaThemeData: initialZetaThemeData, - initialThemeMode: initialThemeMode, - initialContrast: initialContrast, + return ZetaProvider( + // initialContrast: ZetaContrast.aa, + // initialThemeMode: ThemeMode.system, + customThemes: [ + ZetaCustomTheme( + id: 'teal', + primary: ZetaPrimitivesLight().teal, + primaryDark: ZetaPrimitivesDark().teal, + secondary: ZetaPrimitivesLight().yellow, + secondaryDark: ZetaPrimitivesDark().yellow, + ), + ZetaCustomTheme( + id: 'yellow', + primary: ZetaPrimitivesLight().yellow, + primaryDark: ZetaPrimitivesDark().yellow, + secondary: ZetaPrimitivesLight().red, + secondaryDark: ZetaPrimitivesDark().red, + ), + ZetaCustomTheme( + id: 'red', + primary: ZetaPrimitivesLight().red, + primaryDark: ZetaPrimitivesDark().red, + secondary: ZetaPrimitivesLight().purple, + secondaryDark: ZetaPrimitivesDark().purple, + ), + ZetaCustomTheme( + id: 'purple', + primary: ZetaPrimitivesLight().purple, + primaryDark: ZetaPrimitivesDark().purple, + secondary: ZetaPrimitivesLight().green, + secondaryDark: ZetaPrimitivesDark().green, + ), + ZetaCustomTheme( + id: 'green', + primary: ZetaPrimitivesLight().green, + primaryDark: ZetaPrimitivesDark().green, + secondary: ZetaPrimitivesLight().blue, + secondaryDark: ZetaPrimitivesDark().blue, + ), + ], builder: (context, lightTheme, darkTheme, themeMode) { return MaterialApp.router( routerConfig: router, diff --git a/example/lib/pages/components/avatar_example.dart b/example/lib/pages/components/avatar_example.dart index ff3aaa90..1454f0a7 100644 --- a/example/lib/pages/components/avatar_example.dart +++ b/example/lib/pages/components/avatar_example.dart @@ -22,7 +22,7 @@ class AvatarExample extends StatelessWidget { ZetaAvatar.initials( initials: 'W W', size: ZetaAvatarSize.xxs, - backgroundColor: Zeta.of(context).colors.green, + backgroundColor: Zeta.of(context).colors.borderPositive, ), ], name: AvatarExample.name, @@ -35,7 +35,7 @@ class AvatarExample extends StatelessWidget { ZetaAvatar.initials( initials: 'WW', size: ZetaAvatarSize.xxs, - backgroundColor: Zeta.of(context).colors.green, + backgroundColor: Zeta.of(context).colors.borderPositive, ), Column( children: [ @@ -69,7 +69,7 @@ class AvatarExample extends StatelessWidget { children: ZetaAvatarSize.values .map((size) => Column( children: [ - ZetaAvatar.image(size: size), + ZetaAvatar.image(size: size, image: image), const SizedBox(height: 20), ], )) @@ -82,7 +82,8 @@ class AvatarExample extends StatelessWidget { children: [ ZetaAvatar.image( size: size, - borderColor: Zeta.of(context).colors.green, + image: image, + borderColor: Zeta.of(context).colors.borderPositive, ), const SizedBox(height: 20), ], @@ -110,7 +111,7 @@ class AvatarExample extends StatelessWidget { children: [ ZetaAvatar.image( size: size, - borderColor: Zeta.of(context).colors.green, + borderColor: Zeta.of(context).colors.borderPositive, image: image, ), const SizedBox(height: 20), @@ -171,7 +172,7 @@ class AvatarExample extends StatelessWidget { ZetaAvatar.initials( size: size, initials: 'AB', - borderColor: Zeta.of(context).colors.green, + borderColor: Zeta.of(context).colors.borderPositive, ), const SizedBox(height: 20), ], @@ -230,7 +231,7 @@ class AvatarExample extends StatelessWidget { children: [ ZetaAvatar.image( size: size, - borderColor: Zeta.of(context).colors.green, + borderColor: Zeta.of(context).colors.borderPositive, upperBadge: ZetaAvatarBadge.notification(value: 3), ), const SizedBox(height: 20), @@ -260,7 +261,7 @@ class AvatarExample extends StatelessWidget { children: [ ZetaAvatar.image( size: size, - borderColor: Zeta.of(context).colors.green, + borderColor: Zeta.of(context).colors.borderPositive, upperBadge: ZetaAvatarBadge.notification(value: 3), image: image, ), @@ -323,7 +324,7 @@ class AvatarExample extends StatelessWidget { ZetaAvatar.initials( size: size, initials: 'AB', - borderColor: Zeta.of(context).colors.green, + borderColor: Zeta.of(context).colors.borderPositive, upperBadge: ZetaAvatarBadge.notification(value: 3), ), const SizedBox(height: 20), @@ -383,7 +384,7 @@ class AvatarExample extends StatelessWidget { children: [ ZetaAvatar.image( size: size, - borderColor: Zeta.of(context).colors.green, + borderColor: Zeta.of(context).colors.borderPositive, lowerBadge: ZetaAvatarBadge.icon(), ), const SizedBox(height: 20), @@ -413,7 +414,7 @@ class AvatarExample extends StatelessWidget { children: [ ZetaAvatar.image( size: size, - borderColor: Zeta.of(context).colors.green, + borderColor: Zeta.of(context).colors.borderPositive, lowerBadge: ZetaAvatarBadge.icon(), image: image, ), @@ -476,7 +477,7 @@ class AvatarExample extends StatelessWidget { ZetaAvatar.initials( size: size, initials: 'AB', - borderColor: Zeta.of(context).colors.green, + borderColor: Zeta.of(context).colors.borderPositive, lowerBadge: ZetaAvatarBadge.icon(), ), const SizedBox(height: 20), @@ -539,7 +540,7 @@ class AvatarExample extends StatelessWidget { ZetaAvatar.image( size: size, image: image, - borderColor: Zeta.of(context).colors.green, + borderColor: Zeta.of(context).colors.borderPositive, upperBadge: ZetaAvatarBadge.notification(value: 3), lowerBadge: ZetaAvatarBadge.icon(), ), @@ -571,7 +572,7 @@ class AvatarExample extends StatelessWidget { ZetaAvatar.initials( size: size, initials: 'AB', - borderColor: Zeta.of(context).colors.green, + borderColor: Zeta.of(context).colors.borderPositive, upperBadge: ZetaAvatarBadge.notification(value: 3), lowerBadge: ZetaAvatarBadge.icon(), ), diff --git a/example/lib/pages/components/list_item_example.dart b/example/lib/pages/components/list_item_example.dart index 7a271232..18572b55 100644 --- a/example/lib/pages/components/list_item_example.dart +++ b/example/lib/pages/components/list_item_example.dart @@ -26,7 +26,7 @@ class _ListItemExampleState extends State { return ExampleScaffold( name: ListItemExample.name, child: Container( - color: zetaColors.surfaceSecondary, + color: zetaColors.surfaceWarm, child: SingleChildScrollView( child: Padding( padding: const EdgeInsets.all(16), diff --git a/example/lib/pages/components/navigation_rail_example.dart b/example/lib/pages/components/navigation_rail_example.dart index f1429f9b..9c1c5101 100644 --- a/example/lib/pages/components/navigation_rail_example.dart +++ b/example/lib/pages/components/navigation_rail_example.dart @@ -63,7 +63,7 @@ class _NavigationRailExampleState extends State { _titles[_selectedIndex!], textAlign: TextAlign.center, style: ZetaTextStyles.titleMedium.copyWith( - color: zeta.colors.textDefault, + color: zeta.colors.mainDefault, fontWeight: FontWeight.bold, ), ), diff --git a/example/lib/pages/components/notification_list_example.dart b/example/lib/pages/components/notification_list_example.dart index 1b203145..79a61122 100644 --- a/example/lib/pages/components/notification_list_example.dart +++ b/example/lib/pages/components/notification_list_example.dart @@ -32,7 +32,7 @@ class NotificationListItemExample extends StatelessWidget { avatar: ZetaAvatar.initials( initials: "JS", lowerBadge: ZetaAvatarBadge.icon( - color: ZetaColors().surfacePositive, + color: Zeta.of(context).colors.surfacePositive, icon: Icons.check, ), )), @@ -63,7 +63,7 @@ class NotificationListItemExample extends StatelessWidget { avatar: ZetaAvatar.initials( initials: "JS", lowerBadge: ZetaAvatarBadge.icon( - color: ZetaColors().surfacePositive, + color: Zeta.of(context).colors.surfacePositive, icon: Icons.check, ), )), @@ -88,7 +88,7 @@ class NotificationListItemExample extends StatelessWidget { initials: "JS", semanticUpperBadgeLabel: 'Urgent', lowerBadge: ZetaAvatarBadge.icon( - color: ZetaColors().surfacePositive, + color: Zeta.of(context).colors.surfacePositive, icon: Icons.check, ), ), diff --git a/example/lib/pages/theme/color_example.dart b/example/lib/pages/theme/color_example.dart index 9bb96c64..9b6f5602 100644 --- a/example/lib/pages/theme/color_example.dart +++ b/example/lib/pages/theme/color_example.dart @@ -16,117 +16,131 @@ class _ColorExampleState extends State { @override Widget build(BuildContext context) { - final zeta = Zeta.of(context); - final colors = zeta.colors; + final colors = Zeta.of(context).colors; return LayoutBuilder( builder: (context, constraints) { - final Map swatches = { - 'Blue': colors.blue, - 'Green': colors.green, - 'Red': colors.red, - 'Orange': colors.orange, - 'Purple': colors.purple, - 'Yellow': colors.yellow, - 'Teal': colors.teal, - 'Pink': colors.pink, - 'Grey Warm': colors.warm, - 'Grey Cool': colors.cool, + final blockSize = constraints.maxWidth / 11; + final Map primitives = { + 'cool': colors.primitives.cool, + 'warm': colors.primitives.warm, + 'blue': colors.primitives.blue, + 'green': colors.primitives.green, + 'red': colors.primitives.red, + 'orange': colors.primitives.orange, + 'purple': colors.primitives.purple, + 'yellow': colors.primitives.yellow, + 'teal': colors.primitives.teal, + 'pink': colors.primitives.pink, }; - - final Map generatedSwatches = { - 'Gen-Blue': ZetaColorSwatch.fromColor( - colors.blue, - brightness: zeta.brightness, - contrast: colors.contrast, - ), - 'Blue': colors.blue, - 'Gen-Green': ZetaColorSwatch.fromColor( - colors.green, - brightness: zeta.brightness, - contrast: colors.contrast, - ), - 'Green': colors.green, - 'Gen-Red': ZetaColorSwatch.fromColor( - colors.red, - brightness: zeta.brightness, - contrast: colors.contrast, - ), - 'Red': colors.red, - 'Gen-Orange': ZetaColorSwatch.fromColor( - colors.orange, - brightness: zeta.brightness, - contrast: colors.contrast, - ), - 'Orange': colors.orange, - 'Gen-Purple': ZetaColorSwatch.fromColor( - colors.purple, - brightness: zeta.brightness, - contrast: colors.contrast, - ), - 'Purple': colors.purple, - 'Gen-Yellow': ZetaColorSwatch.fromColor( - colors.yellow, - brightness: zeta.brightness, - contrast: colors.contrast, - ), - 'Yellow': colors.yellow, - 'Gen-Teal': ZetaColorSwatch.fromColor( - colors.teal, - brightness: zeta.brightness, - contrast: colors.contrast, - ), - 'Teal': colors.teal, - 'Gen-Pink': ZetaColorSwatch.fromColor( - colors.pink, - brightness: zeta.brightness, - contrast: colors.contrast, - ), - 'Pink': colors.pink, - 'Gen-Grey Warm': ZetaColorSwatch.fromColor( - colors.warm, - brightness: zeta.brightness, - contrast: colors.contrast, - ), - 'Grey Warm': colors.warm, - 'Gen-Grey Cool': ZetaColorSwatch.fromColor( - colors.cool, - brightness: zeta.brightness, - contrast: colors.contrast, - ), - 'Grey Cool': colors.cool, + final Map primitivesPure = { + 'white': colors.primitives.pure.shade0, + 'mid': colors.primitives.pure.shade500, + 'black': colors.primitives.pure.shade1000, }; - final Map textIcon = { - 'textDefault': colors.textDefault, - 'textSubtle': colors.textSubtle, - 'textDisabled': colors.textDisabled, - 'textInverse': colors.textInverse, - }; - final Map border = { - 'borderDefault': colors.borderDefault, - 'borderSubtle': colors.borderSubtle, - 'borderDisabled': colors.borderDisabled, - 'borderSelected': colors.borderSelected, + final Map mainColors = { + 'defaultColor': colors.mainDefault, + 'subtle': colors.mainSubtle, + 'light': colors.mainLight, + 'inverse': colors.mainInverse, + 'disabled': colors.mainDisabled, + 'primary': colors.mainPrimary, + 'secondary': colors.mainSecondary, + 'positive': colors.mainPositive, + 'warning': colors.mainWarning, + 'negative': colors.mainNegative, + 'info': colors.mainInfo, }; - final Map backdrop = { - 'surfacePrimary': colors.surfacePrimary, - 'surfaceDisabled': colors.surfaceDisabled, - 'surfaceHover': colors.surfaceHover, - 'surfaceSecondary': colors.surfaceSecondary, - 'surfaceTertiary': colors.surfaceTertiary, - 'surfaceSelectedHover': colors.surfaceSelectedHover, - 'surfaceSelected': colors.surfaceSelected, + final Map borderColors = { + 'defaultColor': colors.borderDefault, + 'subtle': colors.borderSubtle, + 'hover': colors.borderHover, + 'selected': colors.borderSelected, + 'disabled': colors.borderDisabled, + 'pure': colors.borderPure, + 'primaryMain': colors.borderPrimaryMain, + 'primary': colors.borderPrimary, + 'secondary': colors.borderSecondary, + 'positive': colors.borderPositive, + 'warning': colors.borderWarning, + 'negative': colors.borderNegative, + 'info': colors.borderInfo, }; - - final Map primaries = { - 'primaryColor': colors.primary.text, - 'secondaryColor': colors.secondary.text, - }; - - final Map alerts = { - 'negative': colors.surfaceNegative, + final Map surfaceColors = { + 'defaultColor': colors.surfaceDefault, + 'defaultInverse': colors.surfaceDefaultInverse, + 'hover': colors.surfaceHover, + 'selected': colors.surfaceSelected, + 'selectedHover': colors.surfaceSelectedHover, + 'disabled': colors.surfaceDisabled, + 'cool': colors.surfaceCool, + 'warm': colors.surfaceWarm, + 'primary': colors.surfacePrimary, + 'primarySubtle': colors.surfacePrimarySubtle, + 'secondary': colors.surfaceSecondary, + 'secondarySubtle': colors.surfaceSecondarySubtle, + 'positive': colors.surfacePositive, + 'positiveSubtle': colors.surfacePositiveSubtle, 'warning': colors.surfaceWarning, + 'warningSubtle': colors.surfaceWarningSubtle, + 'negative': colors.surfaceNegative, + 'negativeSubtle': colors.surfaceNegativeSubtle, 'info': colors.surfaceInfo, + 'infoSubtle': colors.surfaceInfoSubtle, + }; + final Map avatarColors = { + 'blue': colors.surfaceAvatarBlue, + 'green': colors.surfaceAvatarGreen, + 'orange': colors.surfaceAvatarOrange, + 'pink': colors.surfaceAvatarPink, + 'purple': colors.surfaceAvatarPurple, + 'teal': colors.surfaceAvatarTeal, + 'yellow': colors.surfaceAvatarYellow, + }; + final Map disabled = { + 'disabled': colors.stateDisabledDisabled, + }; + final Map defaultColors = { + 'enabled': colors.stateDefaultEnabled, + 'hover': colors.stateDefaultHover, + 'selected': colors.stateDefaultSelected, + 'focus': colors.stateDefaultFocus, + }; + final Map primary = { + 'enabled': colors.statePrimaryEnabled, + 'hover': colors.statePrimaryHover, + 'selected': colors.statePrimarySelected, + 'focus': colors.statePrimaryFocus, + }; + final Map secondary = { + 'enabled': colors.stateSecondaryEnabled, + 'hover': colors.stateSecondaryHover, + 'selected': colors.stateSecondarySelected, + 'focus': colors.stateSecondaryFocus, + }; + final Map positive = { + 'enabled': colors.statePositiveEnabled, + 'hover': colors.statePositiveHover, + 'selected': colors.statePositiveSelected, + 'focus': colors.statePositiveFocus, + }; + final Map negative = { + 'enabled': colors.stateNegativeEnabled, + 'hover': colors.stateNegativeHover, + 'selected': colors.stateNegativeSelected, + 'focus': colors.stateNegativeFocus, + }; + final Map info = { + 'enabled': colors.stateInfoEnabled, + 'hover': colors.stateInfoHover, + 'selected': colors.stateInfoSelected, + 'focus': colors.stateInfoFocus, + }; + final Map inverse = { + 'enabled': colors.stateInverseEnabled, + 'hover': colors.stateInverseHover, + 'selected': colors.stateInverseSelected, + 'focus': colors.stateInverseFocus, }; return ExampleScaffold( @@ -135,90 +149,53 @@ class _ColorExampleState extends State { padding: EdgeInsets.all(Zeta.of(context).spacing.medium), child: Column( children: [ - MyRow(children: textIcon, title: 'Text and icon styles'), - MyRow(children: border, title: 'Border styles'), - MyRow(children: backdrop, title: 'Backdrop colors'), - MyRow(children: primaries, title: 'Primary colors'), - MyRow(children: alerts, title: 'Alert colors'), - Row(children: [Text('Full color swatches', style: ZetaTextStyles.displayMedium)]) - .paddingVertical(Zeta.of(context).spacing.xl_4), - ...swatches.entries.map( - (value) => Row( - children: List.generate(10, (index) => 100 - (10 * index)) - .map( - (e) => Expanded( - child: Container( - height: constraints.maxWidth / 10, - color: value.value[e], - child: FittedBox( - fit: BoxFit.scaleDown, - child: Column(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - DefaultTextStyle( - style: ZetaTextStyles.bodyMedium - .copyWith(color: calculateTextColor(value.value[e] ?? Colors.white)), - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Text('${value.key.toLowerCase().replaceAll(' ', '')}-$e'), - Text(value.value[e].toString().replaceAll('Color(0xff', '#').substring(0, 7)), - ], - ), - ), - ]), - ), - ), - ), - ) - .toList(), - ), + Text('Semantic colors', style: ZetaTextStyles.displaySmall), + MyRow(children: mainColors, title: 'Main Colors'), + MyRow(children: borderColors, title: 'Main Colors'), + MyRow(children: surfaceColors, title: 'Surface Colors'), + MyRow(children: avatarColors, title: 'Surface / Avatar Colors'), + MyRow(children: disabled, title: 'State / disabled Colors'), + MyRow(children: defaultColors, title: 'State / default Colors'), + MyRow(children: primary, title: 'State / primary Colors'), + MyRow(children: secondary, title: 'State / secondary Colors'), + MyRow(children: positive, title: 'State / positive Colors'), + MyRow(children: negative, title: 'State / negative Colors'), + MyRow(children: info, title: 'State / info Colors'), + MyRow(children: inverse, title: 'State / inverse Colors'), + Row(children: [ + Text('Full color swatches', style: ZetaTextStyles.displayMedium), + ]).paddingVertical(Zeta.of(context).spacing.xl_4), + Row( + children: primitivesPure.entries + .map( + (value) => SwatchBox( + color: value.value, + name: 'pure', + blockSize: blockSize, + value: value.key == 'mid' + ? 500 + : value.key == 'white' + ? 0 + : 1000, + ), + ) + .toList(), ), - ElevatedButton( - onPressed: () => setState(() => showGeneratedColors = !showGeneratedColors), - child: const Text('Toggle generated colors').paddingAll(Zeta.of(context).spacing.medium), - ).paddingAll(Zeta.of(context).spacing.medium), - if (showGeneratedColors) - Row(children: [Text('Generated color swatches', style: ZetaTextStyles.displayMedium)]) - .paddingVertical(Zeta.of(context).spacing.xl_4), - if (showGeneratedColors) - ...generatedSwatches.entries.map( - (value) => Row( - children: List.generate(11, (index) => 110 - (10 * index)) - .map( - (e) => Expanded( - child: Container( - height: constraints.maxWidth / 10, - color: e == 110 ? colors.surfacePrimary : value.value[e], - child: e == 110 - ? Nothing() - : FittedBox( - fit: BoxFit.scaleDown, - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - DefaultTextStyle( - style: ZetaTextStyles.bodyMedium - .copyWith(color: calculateTextColor(value.value[e] ?? Colors.white)), - child: Column( - children: [ - Text('${value.key.toLowerCase().replaceAll(' ', '')}-$e'), - Text( - value.value[e] - .toString() - .replaceAll('Color(0xff', '#') - .substring(0, 7), - ), - ], - ), - ), - ], - ), - ), - ), - ), - ) - .toList(), - ), - ), + ...primitives.entries + .map( + (value) => Row( + children: List.generate(10, (index) => 100 - (10 * index)) + .map( + (e) => SwatchBox( + color: value.value[e] ?? Colors.white, + name: value.key, + blockSize: blockSize, + value: e, + ), + ) + .toList()), + ) + .toList(), ], ), ), @@ -228,6 +205,39 @@ class _ColorExampleState extends State { } } +class SwatchBox extends StatelessWidget { + const SwatchBox({super.key, required this.color, required this.name, required this.blockSize, required this.value}); + + final Color color; + final int value; + final String name; + final double blockSize; + + @override + Widget build(BuildContext context) { + return Container( + height: blockSize, + width: blockSize, + color: color, + child: FittedBox( + fit: BoxFit.scaleDown, + child: Column(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ + DefaultTextStyle( + style: ZetaTextStyles.bodyMedium.copyWith(color: calculateTextColor(color)), + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + Text('${name.toLowerCase().replaceAll(' ', '')}-$value'), + Text(color.toString().replaceAll('Color(0xff', '#').substring(0, 7)), + ], + ), + ), + ]), + ), + ); + } +} + class MyRow extends StatelessWidget { final Map children; final String title; diff --git a/example/lib/pages/theme/radius_example.dart b/example/lib/pages/theme/radius_example.dart index 199ce397..6137da88 100644 --- a/example/lib/pages/theme/radius_example.dart +++ b/example/lib/pages/theme/radius_example.dart @@ -31,21 +31,21 @@ class RadiusExample extends StatelessWidget { height: 100, decoration: BoxDecoration( borderRadius: rad, - color: Zeta.of(context).colors.blue.shade30, - border: Border.all(color: colors.blue.shade80, width: 3), + color: Zeta.of(context).colors.surfacePrimarySubtle, + border: Border.all(color: colors.borderPrimary, width: 3), ), child: Center( child: Container( decoration: BoxDecoration( borderRadius: rad, - color: Zeta.of(context).colors.surfacePrimary, - border: Border.all(color: colors.blue.shade50, width: 3), + color: Zeta.of(context).colors.surfaceDefault, + border: Border.all(color: colors.borderPrimary, width: 3), ), padding: EdgeInsets.all(Zeta.of(context).spacing.large), child: Text( rad.radiusString.split('.').last.capitalize(), style: ZetaTextStyles.titleMedium.apply( - color: Zeta.of(context).colors.textDefault, + color: Zeta.of(context).colors.mainDefault, fontStyle: FontStyle.normal, decoration: TextDecoration.none, ), diff --git a/example/lib/pages/theme/spacing_example.dart b/example/lib/pages/theme/spacing_example.dart index 4be2cb92..2dce69b1 100644 --- a/example/lib/pages/theme/spacing_example.dart +++ b/example/lib/pages/theme/spacing_example.dart @@ -59,8 +59,8 @@ class SpacingExample extends StatelessWidget { ), Column( crossAxisAlignment: CrossAxisAlignment.start, - children: baseSpacings.entries.map((obj) => _SpacingDemo(obj)).toList(), - ), + children: baseSpacings.entries.map((obj) => _SpacingDemo(obj, true)).toList(), + ) ], ), ), @@ -71,26 +71,27 @@ class SpacingExample extends StatelessWidget { class _SpacingDemo extends StatelessWidget { final MapEntry size; + final bool primitive; - const _SpacingDemo(this.size); + const _SpacingDemo(this.size, [this.primitive = false]); @override Widget build(BuildContext context) { final colors = Zeta.of(context).colors; return Container( - color: colors.blue.shade30, + color: colors.primitives.blue.shade30, margin: EdgeInsets.all(Zeta.of(context).spacing.xl_2), child: CustomPaint( - painter: _TagPainter(color: colors.pink), + painter: _TagPainter(color: colors.primitives.pink), child: LayoutBuilder(builder: (context, c2) { return Container( margin: EdgeInsets.all(size.value), padding: EdgeInsets.all(Zeta.of(context).spacing.medium), - color: colors.surfacePrimary, + color: colors.surfaceDefault, child: Text( 'Zeta.of(context).spacing.' + size.key, style: ZetaTextStyles.titleMedium.apply( - color: Zeta.of(context).colors.textDefault, + color: Zeta.of(context).colors.mainDefault, fontStyle: FontStyle.normal, decoration: TextDecoration.none, ), diff --git a/example/lib/theme_service.dart b/example/lib/theme_service.dart deleted file mode 100644 index 3c80a1b9..00000000 --- a/example/lib/theme_service.dart +++ /dev/null @@ -1,47 +0,0 @@ -import 'package:flutter/src/material/app.dart'; -import 'package:shared_preferences/shared_preferences.dart'; -import 'package:zeta_example/utils/theme_color_switch.dart'; -import 'package:zeta_flutter/zeta_flutter.dart'; - -class SharedPrefsThemeService extends ZetaThemeService { - SharedPrefsThemeService(this.preferences); - - final SharedPreferences preferences; - - @override - Future<(ZetaThemeData?, ThemeMode?, ZetaContrast?)> loadTheme() async { - final theme = preferences.getString('theme') ?? 'default'; - final themeData = appThemes[theme]; - - final modeString = preferences.getString('themeMode'); - final themeMode = modeString == 'light' - ? ThemeMode.light - : modeString == 'dark' - ? ThemeMode.dark - : ThemeMode.system; - - final contrastString = preferences.getString('contrast'); - final contrast = contrastString == 'aaa' ? ZetaContrast.aaa : ZetaContrast.aa; - - return (themeData, themeMode, contrast); - } - - @override - Future saveTheme({ - required ZetaThemeData themeData, - required ThemeMode themeMode, - required ZetaContrast contrast, - }) async { - await preferences.setString('theme', themeData.identifier); - - final modeString = themeMode == ThemeMode.light - ? 'light' - : themeMode == ThemeMode.dark - ? 'dark' - : 'system'; - await preferences.setString('themeMode', modeString); - - final contrastString = contrast == ZetaContrast.aaa ? 'aaa' : 'aa'; - await preferences.setString('contrast', contrastString); - } -} diff --git a/example/lib/utils/rounded_switch.dart b/example/lib/utils/rounded_switch.dart index f8d3acd7..3d555518 100644 --- a/example/lib/utils/rounded_switch.dart +++ b/example/lib/utils/rounded_switch.dart @@ -21,11 +21,11 @@ class ZetaRoundedSwitch extends StatelessWidget { alignment: Alignment.center, child: ZetaAvatar( size: ZetaAvatarSize.xxs, - image: Icon(e ? Icons.circle : Icons.square, color: zeta.colors.primary), + image: Icon(e ? Icons.circle : Icons.square, color: zeta.colors.mainPrimary), initialTextStyle: TextStyle( fontSize: 28, letterSpacing: Zeta.of(context).spacing.none, - color: Zeta.of(context).colors.primary, + color: Zeta.of(context).colors.mainPrimary, fontWeight: FontWeight.w500, ), ), diff --git a/example/lib/utils/theme_color_switch.dart b/example/lib/utils/theme_color_switch.dart index c205ed11..6c71234d 100644 --- a/example/lib/utils/theme_color_switch.dart +++ b/example/lib/utils/theme_color_switch.dart @@ -1,66 +1,57 @@ import 'package:flutter/material.dart'; import 'package:zeta_flutter/zeta_flutter.dart'; -late final appThemes = { - "default": ZetaThemeData(), - "teal": ZetaThemeData( - identifier: 'teal', - primary: ZetaColorBase.teal, - ), - "yellow": ZetaThemeData( - identifier: 'yellow', - primary: ZetaColorBase.yellow, - ), - "red": ZetaThemeData( - identifier: 'red', - primary: ZetaColorBase.red, - ), - "purple": ZetaThemeData( - identifier: 'purple', - primary: ZetaColorBase.purple, - ), -}; - -class ZetaThemeColorSwitch extends StatelessWidget { +class ZetaThemeColorSwitch extends StatefulWidget { ZetaThemeColorSwitch({super.key}); + @override + State createState() => _ZetaThemeColorSwitchState(); +} + +class _ZetaThemeColorSwitchState extends State { @override Widget build(BuildContext context) { final zeta = Zeta.of(context); + final zetaProvider = ZetaProvider.of(context); + + final Map items = {}; + items.putIfAbsent(null, () => ZetaIcon(ZetaIcons.block)); - ZetaColors primary(ZetaThemeData data) { - if (zeta.brightness == Brightness.light) { - return data.colorsLight; - } else { - return data.colorsDark; - } - } + zetaProvider.customThemes.forEach((e) { + final color = e.primary; + final name = e.id; + items.putIfAbsent( + name, + () => ZetaAvatar( + size: ZetaAvatarSize.xxs, + backgroundColor: zeta.colors.surfaceDefault, + image: ZetaIcon( + Icons.color_lens, + color: color ?? + (Zeta.of(context).brightness == Brightness.light + ? ZetaPrimitivesLight().blue + : ZetaPrimitivesDark().blue), + ), + ), + ); + }); return DropdownButtonHideUnderline( - child: DropdownButton( - value: zeta.themeData.identifier, + child: DropdownButton( + value: zeta.customThemeId, elevation: 0, padding: EdgeInsets.all(8), icon: Nothing(), dropdownColor: zeta.colors.borderDisabled, - items: appThemes.entries.map((e) { - final zetaColors = primary(appThemes[e.key]!); - final color = zetaColors.primary; - return DropdownMenuItem( - value: e.value.identifier, - alignment: Alignment.center, - child: ZetaAvatar( - size: ZetaAvatarSize.xxs, - backgroundColor: color.surface, - image: ZetaIcon(Icons.color_lens, color: color), - ), - ); - }).toList(), + items: items.entries + .map((e) => DropdownMenuItem( + value: e.key, + alignment: Alignment.center, + child: e.value, + )) + .toList(), onChanged: (value) { - final theme = appThemes[value]; - if (theme != null) { - ZetaProvider.of(context).updateThemeData(theme); - } + ZetaProvider.of(context).updateCustomTheme(themeId: value); }, ), ); diff --git a/example/lib/utils/theme_constrast_switch.dart b/example/lib/utils/theme_constrast_switch.dart index de59993d..658e6b82 100644 --- a/example/lib/utils/theme_constrast_switch.dart +++ b/example/lib/utils/theme_constrast_switch.dart @@ -13,14 +13,6 @@ class ZetaThemeContrastSwitch extends StatelessWidget { Widget build(BuildContext context) { final zeta = Zeta.of(context); - ZetaColors zetaColors(ZetaContrast contrast) { - if (zeta.brightness == Brightness.light) { - return zeta.themeData.apply(contrast: contrast).colorsLight; - } else { - return zeta.themeData.apply(contrast: contrast).colorsDark; - } - } - return DropdownButtonHideUnderline( child: DropdownButton( value: zeta.contrast, @@ -29,18 +21,20 @@ class ZetaThemeContrastSwitch extends StatelessWidget { icon: Nothing(), dropdownColor: zeta.colors.borderDisabled, items: _themes.map((e) { - final colors = zetaColors(e); + final ZetaColors colors = (e == ZetaContrast.aa + ? ZetaColorsAA(primitives: Zeta.of(context).colors.primitives) + : ZetaColorsAAA(primitives: Zeta.of(context).colors.primitives)) as ZetaColors; return DropdownMenuItem( value: e, alignment: Alignment.center, child: ZetaAvatar( size: ZetaAvatarSize.xxs, - backgroundColor: colors.primary.surface, - initials: e == ZetaContrast.aa ? 'AA' : 'AAA', + backgroundColor: colors.surfaceDefault, + initials: e.name.toUpperCase(), initialTextStyle: TextStyle( fontSize: 14, letterSpacing: Zeta.of(context).spacing.none, - color: colors.primary, + color: colors.mainPrimary, fontWeight: FontWeight.w500, ), ), diff --git a/example/lib/utils/theme_mode_switch.dart b/example/lib/utils/theme_mode_switch.dart index 1250c93b..f642cb20 100644 --- a/example/lib/utils/theme_mode_switch.dart +++ b/example/lib/utils/theme_mode_switch.dart @@ -13,15 +13,7 @@ class ZetaThemeModeSwitch extends StatelessWidget { @override Widget build(BuildContext context) { final zeta = Zeta.of(context); - - ZetaColors zetaColors(ThemeMode mode) { - if ((mode == ThemeMode.system && MediaQuery.of(context).platformBrightness == Brightness.light) || - mode == ThemeMode.light) { - return zeta.themeData.colorsLight; - } else { - return zeta.themeData.colorsDark; - } - } + final colors = zeta.colors; return DropdownButtonHideUnderline( child: DropdownButton( @@ -31,20 +23,19 @@ class ZetaThemeModeSwitch extends StatelessWidget { icon: Nothing(), dropdownColor: zeta.colors.borderDisabled, items: _themes.map((e) { - final colors = zetaColors(e); return DropdownMenuItem( value: e, alignment: Alignment.center, child: ZetaAvatar( size: ZetaAvatarSize.xxs, - backgroundColor: colors.primary.surface, + backgroundColor: colors.surfaceDefault, image: ZetaIcon( e == ThemeMode.system ? Icons.system_security_update_good : e == ThemeMode.light ? Icons.light_mode : Icons.dark_mode, - color: colors.primary, + color: colors.mainPrimary, ), ), ); diff --git a/example/macos/Podfile.lock b/example/macos/Podfile.lock index fbd492e5..1aff447e 100644 --- a/example/macos/Podfile.lock +++ b/example/macos/Podfile.lock @@ -35,7 +35,7 @@ SPEC CHECKSUMS: FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24 path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46 shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78 - sqflite_darwin: a553b1fd6fe66f53bbb0fe5b4f5bab93f08d7a13 + sqflite_darwin: 5a7236e3b501866c1c9befc6771dfd73ffb8702d url_launcher_macos: c82c93949963e55b228a30115bd219499a6fe404 PODFILE CHECKSUM: 353c8bcc5d5b0994e508d035b5431cfe18c1dea7 diff --git a/example/macos/Runner/AppDelegate.swift b/example/macos/Runner/AppDelegate.swift index 8e02df28..b3c17614 100644 --- a/example/macos/Runner/AppDelegate.swift +++ b/example/macos/Runner/AppDelegate.swift @@ -6,4 +6,8 @@ class AppDelegate: FlutterAppDelegate { override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { return true } + + override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { + return true + } } diff --git a/example/widgetbook/pages/components/avatar_rail_widgetbook.dart b/example/widgetbook/pages/components/avatar_rail_widgetbook.dart index 1b738085..a70122be 100644 --- a/example/widgetbook/pages/components/avatar_rail_widgetbook.dart +++ b/example/widgetbook/pages/components/avatar_rail_widgetbook.dart @@ -23,18 +23,19 @@ Widget avatarRailUseCase(BuildContext context) { upperBadge: context.knobs.boolean(label: 'Status Badge', initialValue: false) ? ZetaAvatarBadge.icon( icon: ZetaIcons.close, - color: context.knobs.colorOrNull(label: "Upper Badge Color", initialValue: colors.green) ?? - colors.iconDefault, + color: context.knobs.colorOrNull(label: "Upper Badge Color", initialValue: colors.primitives.green) ?? + colors.mainDefault, ) : null, - borderColor: context.knobs.colorOrNull(label: 'Outline', initialValue: colors.green), + borderColor: context.knobs.colorOrNull(label: 'Outline', initialValue: colors.primitives.green), lowerBadge: context.knobs.boolean(label: 'Notification Badge', initialValue: false) ? ZetaAvatarBadge.notification( value: context.knobs.intOrNull.input(label: "Value", initialValue: 1), ) : null, initials: context.knobs.stringOrNull(label: 'Initials', initialValue: 'AZ'), - backgroundColor: context.knobs.colorOrNull(label: 'Background color', initialValue: colors.purple.shade80), + backgroundColor: + context.knobs.colorOrNull(label: 'Background color', initialValue: colors.primitives.purple.shade80), onTap: () => print('Avatar tapped'), label: context.knobs.stringOrNull(label: 'Label', initialValue: 'ABC'), ), @@ -49,18 +50,19 @@ Widget avatarRailUseCase(BuildContext context) { upperBadge: context.knobs.boolean(label: 'Status Badge', initialValue: false) ? ZetaAvatarBadge.icon( icon: ZetaIcons.close, - color: context.knobs.colorOrNull(label: "Upper Badge Color", initialValue: colors.green) ?? - colors.iconDefault, + color: context.knobs.colorOrNull(label: "Upper Badge Color", initialValue: colors.primitives.green) ?? + colors.mainDefault, ) : null, - borderColor: context.knobs.colorOrNull(label: 'Outline', initialValue: colors.green), + borderColor: context.knobs.colorOrNull(label: 'Outline', initialValue: colors.primitives.green), lowerBadge: context.knobs.boolean(label: 'Notification Badge', initialValue: false) ? ZetaAvatarBadge.notification( value: context.knobs.intOrNull.input(label: "Value", initialValue: 1), ) : null, initials: context.knobs.stringOrNull(label: 'Initials', initialValue: 'AZ'), - backgroundColor: context.knobs.colorOrNull(label: 'Background color', initialValue: colors.purple.shade80), + backgroundColor: + context.knobs.colorOrNull(label: 'Background color', initialValue: colors.primitives.purple.shade80), onTap: () => print('Avatar tapped'), label: context.knobs.stringOrNull(label: 'Label', initialValue: 'ABC'), ), @@ -75,18 +77,19 @@ Widget avatarRailUseCase(BuildContext context) { upperBadge: context.knobs.boolean(label: 'Status Badge', initialValue: false) ? ZetaAvatarBadge.icon( icon: ZetaIcons.close, - color: context.knobs.colorOrNull(label: "Upper Badge Color", initialValue: colors.green) ?? - colors.iconDefault, + color: context.knobs.colorOrNull(label: "Upper Badge Color", initialValue: colors.primitives.green) ?? + colors.mainDefault, ) : null, - borderColor: context.knobs.colorOrNull(label: 'Outline', initialValue: colors.green), + borderColor: context.knobs.colorOrNull(label: 'Outline', initialValue: colors.primitives.green), lowerBadge: context.knobs.boolean(label: 'Notification Badge', initialValue: false) ? ZetaAvatarBadge.notification( value: context.knobs.intOrNull.input(label: "Value", initialValue: 1), ) : null, initials: context.knobs.stringOrNull(label: 'Initials', initialValue: 'AZ'), - backgroundColor: context.knobs.colorOrNull(label: 'Background color', initialValue: colors.purple.shade80), + backgroundColor: + context.knobs.colorOrNull(label: 'Background color', initialValue: colors.primitives.purple.shade80), onTap: () => print('Avatar tapped'), label: context.knobs.stringOrNull(label: 'Label', initialValue: 'ABC'), ), @@ -101,18 +104,19 @@ Widget avatarRailUseCase(BuildContext context) { upperBadge: context.knobs.boolean(label: 'Status Badge', initialValue: false) ? ZetaAvatarBadge.icon( icon: ZetaIcons.close, - color: context.knobs.colorOrNull(label: "Upper Badge Color", initialValue: colors.green) ?? - colors.iconDefault, + color: context.knobs.colorOrNull(label: "Upper Badge Color", initialValue: colors.primitives.green) ?? + colors.mainDefault, ) : null, - borderColor: context.knobs.colorOrNull(label: 'Outline', initialValue: colors.green), + borderColor: context.knobs.colorOrNull(label: 'Outline', initialValue: colors.primitives.green), lowerBadge: context.knobs.boolean(label: 'Notification Badge', initialValue: false) ? ZetaAvatarBadge.notification( value: context.knobs.intOrNull.input(label: "Value", initialValue: 1), ) : null, initials: context.knobs.stringOrNull(label: 'Initials', initialValue: 'AZ'), - backgroundColor: context.knobs.colorOrNull(label: 'Background color', initialValue: colors.purple.shade80), + backgroundColor: + context.knobs.colorOrNull(label: 'Background color', initialValue: colors.primitives.purple.shade80), onTap: () => print('Avatar tapped'), label: context.knobs.stringOrNull(label: 'Label', initialValue: 'ABC'), ), @@ -127,18 +131,19 @@ Widget avatarRailUseCase(BuildContext context) { upperBadge: context.knobs.boolean(label: 'Status Badge', initialValue: false) ? ZetaAvatarBadge.icon( icon: ZetaIcons.close, - color: context.knobs.colorOrNull(label: "Upper Badge Color", initialValue: colors.green) ?? - colors.iconDefault, + color: context.knobs.colorOrNull(label: "Upper Badge Color", initialValue: colors.primitives.green) ?? + colors.mainDefault, ) : null, - borderColor: context.knobs.colorOrNull(label: 'Outline', initialValue: colors.green), + borderColor: context.knobs.colorOrNull(label: 'Outline', initialValue: colors.primitives.green), lowerBadge: context.knobs.boolean(label: 'Notification Badge', initialValue: false) ? ZetaAvatarBadge.notification( value: context.knobs.intOrNull.input(label: "Value", initialValue: 1), ) : null, initials: context.knobs.stringOrNull(label: 'Initials', initialValue: 'AZ'), - backgroundColor: context.knobs.colorOrNull(label: 'Background color', initialValue: colors.purple.shade80), + backgroundColor: + context.knobs.colorOrNull(label: 'Background color', initialValue: colors.primitives.purple.shade80), onTap: () => print('Avatar tapped'), label: context.knobs.stringOrNull(label: 'Label', initialValue: 'ABC'), ), @@ -153,18 +158,19 @@ Widget avatarRailUseCase(BuildContext context) { upperBadge: context.knobs.boolean(label: 'Status Badge', initialValue: false) ? ZetaAvatarBadge.icon( icon: ZetaIcons.close, - color: context.knobs.colorOrNull(label: "Upper Badge Color", initialValue: colors.green) ?? - colors.iconDefault, + color: context.knobs.colorOrNull(label: "Upper Badge Color", initialValue: colors.primitives.green) ?? + colors.mainDefault, ) : null, - borderColor: context.knobs.colorOrNull(label: 'Outline', initialValue: colors.green), + borderColor: context.knobs.colorOrNull(label: 'Outline', initialValue: colors.primitives.green), lowerBadge: context.knobs.boolean(label: 'Notification Badge', initialValue: false) ? ZetaAvatarBadge.notification( value: context.knobs.intOrNull.input(label: "Value", initialValue: 1), ) : null, initials: context.knobs.stringOrNull(label: 'Initials', initialValue: 'AZ'), - backgroundColor: context.knobs.colorOrNull(label: 'Background color', initialValue: colors.purple.shade80), + backgroundColor: + context.knobs.colorOrNull(label: 'Background color', initialValue: colors.primitives.purple.shade80), onTap: () => print('Avatar tapped'), label: context.knobs.stringOrNull(label: 'Label', initialValue: 'ABC'), ), diff --git a/example/widgetbook/pages/components/avatar_widgetbook.dart b/example/widgetbook/pages/components/avatar_widgetbook.dart index 8751ee0d..4bab90c1 100644 --- a/example/widgetbook/pages/components/avatar_widgetbook.dart +++ b/example/widgetbook/pages/components/avatar_widgetbook.dart @@ -20,18 +20,19 @@ Widget avatarUseCase(BuildContext context) { upperBadge: context.knobs.boolean(label: 'Status Badge', initialValue: false) ? ZetaAvatarBadge.icon( icon: ZetaIcons.close, - color: context.knobs.colorOrNull(label: "Upper Badge Color", initialValue: colors.green) ?? - colors.iconDefault, + color: context.knobs.colorOrNull(label: "Upper Badge Color", initialValue: colors.primitives.green) ?? + colors.mainDefault, ) : null, - borderColor: context.knobs.colorOrNull(label: 'Outline', initialValue: colors.green), + borderColor: context.knobs.colorOrNull(label: 'Outline', initialValue: colors.primitives.green), lowerBadge: context.knobs.boolean(label: 'Notification Badge', initialValue: false) ? ZetaAvatarBadge.notification( value: context.knobs.intOrNull.input(label: "Value", initialValue: 1), ) : null, initials: context.knobs.stringOrNull(label: 'Initials', initialValue: 'AZ'), - backgroundColor: context.knobs.colorOrNull(label: 'Background color', initialValue: colors.purple.shade80), + backgroundColor: + context.knobs.colorOrNull(label: 'Background color', initialValue: colors.primitives.purple.shade80), onTap: () => print('Avatar tapped'), label: context.knobs.stringOrNull(label: 'Label', initialValue: 'ABC'), labelMaxLines: context.knobs.int.slider(label: 'Label Max Lines', min: 1, max: 3, initialValue: 1), diff --git a/example/widgetbook/pages/components/navigation_rail_widgetbook.dart b/example/widgetbook/pages/components/navigation_rail_widgetbook.dart index bafbf9f2..4b4016e5 100644 --- a/example/widgetbook/pages/components/navigation_rail_widgetbook.dart +++ b/example/widgetbook/pages/components/navigation_rail_widgetbook.dart @@ -48,7 +48,7 @@ Widget navigationRailUseCase(BuildContext context) { itemsList[selectedIndex!], textAlign: TextAlign.center, style: ZetaTextStyles.titleMedium.copyWith( - color: zeta.colors.textDefault, + color: zeta.colors.mainDefault, fontWeight: FontWeight.bold, ), ), diff --git a/example/widgetbook/pages/introduction.dart b/example/widgetbook/pages/introduction.dart index a72d8f3c..56bc2bc1 100644 --- a/example/widgetbook/pages/introduction.dart +++ b/example/widgetbook/pages/introduction.dart @@ -42,7 +42,7 @@ class _IntroductionWidgetbookState extends State { children: [ Container( decoration: BoxDecoration( - color: colors.cool.shade20, + color: colors.surfaceHover, borderRadius: BorderRadius.only(topLeft: radius, topRight: radius), ), child: Padding( @@ -82,7 +82,7 @@ class _IntroductionWidgetbookState extends State { ), Container( decoration: BoxDecoration( - color: isDark ? colors.warm.shade10 : colors.surfacePrimary, + color: colors.surfaceDefault, borderRadius: BorderRadius.only(bottomLeft: radius, bottomRight: radius), ), width: double.infinity, @@ -97,7 +97,7 @@ class _IntroductionWidgetbookState extends State { configs: [ LinkConfig( style: TextStyle( - color: colors.blue.shade50, + color: colors.mainPrimary, decoration: TextDecoration.underline, ), onTap: (url) { @@ -151,7 +151,7 @@ class _CodeWrapperWidget extends StatelessWidget { return Stack( children: [ DefaultTextStyle( - style: GoogleFonts.ibmPlexMono(color: Zeta.of(context).colors.textDefault), + style: GoogleFonts.ibmPlexMono(color: Zeta.of(context).colors.mainDefault), child: child, ), if (language.isNotEmpty) @@ -163,7 +163,8 @@ class _CodeWrapperWidget extends StatelessWidget { child: Text(language), padding: EdgeInsets.symmetric( vertical: Zeta.of(context).spacing.minimum, horizontal: Zeta.of(context).spacing.medium), - decoration: BoxDecoration(color: colors.cool.shade40, borderRadius: Zeta.of(context).radius.rounded), + decoration: + BoxDecoration(color: colors.surfaceSelectedHover, borderRadius: Zeta.of(context).radius.rounded), ), ), ), diff --git a/example/widgetbook/pages/theme/color_widgetbook.dart b/example/widgetbook/pages/theme/color_widgetbook.dart index 23ccec58..ec98f8ef 100644 --- a/example/widgetbook/pages/theme/color_widgetbook.dart +++ b/example/widgetbook/pages/theme/color_widgetbook.dart @@ -2,6 +2,8 @@ import 'package:flutter/material.dart'; import 'package:zeta_example/pages/theme/color_example.dart'; import 'package:zeta_flutter/zeta_flutter.dart'; +import '../../utils/scaffold.dart'; + Widget colorUseCase(BuildContext context) => ColorBody(); class ColorBody extends StatelessWidget { @@ -9,107 +11,185 @@ class ColorBody extends StatelessWidget { @override Widget build(BuildContext context) { - return LayoutBuilder(builder: (_, constraints) { - final colors = Zeta.of(context).colors; + final colors = Zeta.of(context).colors; - final Map swatches = { - 'Blue': colors.blue, - 'Green': colors.green, - 'Red': colors.red, - 'Orange': colors.orange, - 'Purple': colors.purple, - 'Yellow': colors.yellow, - 'Teal': colors.teal, - 'Pink': colors.pink, - 'Grey Warm': colors.warm, - 'Grey Cool': colors.cool, + return WidgetbookScaffold(builder: (context, constraints) { + final blockSize = constraints.maxWidth / 11; + final Map primitives = { + 'cool': colors.primitives.cool, + 'warm': colors.primitives.warm, + 'blue': colors.primitives.blue, + 'green': colors.primitives.green, + 'red': colors.primitives.red, + 'orange': colors.primitives.orange, + 'purple': colors.primitives.purple, + 'yellow': colors.primitives.yellow, + 'teal': colors.primitives.teal, + 'pink': colors.primitives.pink, }; - final Map textIcon = { - 'textDefault': colors.textDefault, - 'textSubtle': colors.textSubtle, - 'textDisabled': colors.textDisabled, - 'textInverse': colors.textInverse, + final Map primitivesPure = { + 'white': colors.primitives.pure.shade0, + 'mid': colors.primitives.pure.shade500, + 'black': colors.primitives.pure.shade1000, }; - final Map border = { - 'borderDefault': colors.borderDefault, - 'borderSubtle': colors.borderSubtle, - 'borderDisabled': colors.borderDisabled, - 'borderSelected': colors.borderSelected, + + final Map mainColors = { + 'defaultColor': colors.mainDefault, + 'subtle': colors.mainSubtle, + 'light': colors.mainLight, + 'inverse': colors.mainInverse, + 'disabled': colors.mainDisabled, + 'primary': colors.mainPrimary, + 'secondary': colors.mainSecondary, + 'positive': colors.mainPositive, + 'warning': colors.mainWarning, + 'negative': colors.mainNegative, + 'info': colors.mainInfo, }; - final Map backdrop = { - 'surfacePrimary': colors.surfacePrimary, - 'surfaceDisabled': colors.surfaceDisabled, - 'surfaceHover': colors.surfaceHover, - 'surfaceSecondary': colors.surfaceSecondary, - 'surfaceTertiary': colors.surfaceTertiary, - 'surfaceSelectedHover': colors.surfaceSelectedHover, - 'surfaceSelected': colors.surfaceSelected, + final Map borderColors = { + 'defaultColor': colors.borderDefault, + 'subtle': colors.borderSubtle, + 'hover': colors.borderHover, + 'selected': colors.borderSelected, + 'disabled': colors.borderDisabled, + 'pure': colors.borderPure, + 'primaryMain': colors.borderPrimaryMain, + 'primary': colors.borderPrimary, + 'secondary': colors.borderSecondary, + 'positive': colors.borderPositive, + 'warning': colors.borderWarning, + 'negative': colors.borderNegative, + 'info': colors.borderInfo, }; - final Map alerts = { + final Map surfaceColors = { + 'defaultColor': colors.surfaceDefault, + 'defaultInverse': colors.surfaceDefaultInverse, + 'hover': colors.surfaceHover, + 'selected': colors.surfaceSelected, + 'selectedHover': colors.surfaceSelectedHover, + 'disabled': colors.surfaceDisabled, + 'cool': colors.surfaceCool, + 'warm': colors.surfaceWarm, + 'primary': colors.surfacePrimary, + 'primarySubtle': colors.surfacePrimarySubtle, + 'secondary': colors.surfaceSecondary, + 'secondarySubtle': colors.surfaceSecondarySubtle, 'positive': colors.surfacePositive, - 'negative': colors.surfaceNegative, + 'positiveSubtle': colors.surfacePositiveSubtle, 'warning': colors.surfaceWarning, + 'warningSubtle': colors.surfaceWarningSubtle, + 'negative': colors.surfaceNegative, + 'negativeSubtle': colors.surfaceNegativeSubtle, 'info': colors.surfaceInfo, + 'infoSubtle': colors.surfaceInfoSubtle, + }; + final Map avatarColors = { + 'blue': colors.surfaceAvatarBlue, + 'green': colors.surfaceAvatarGreen, + 'orange': colors.surfaceAvatarOrange, + 'pink': colors.surfaceAvatarPink, + 'purple': colors.surfaceAvatarPurple, + 'teal': colors.surfaceAvatarTeal, + 'yellow': colors.surfaceAvatarYellow, + }; + final Map disabled = { + 'disabled': colors.stateDisabledDisabled, + }; + final Map defaultColors = { + 'enabled': colors.stateDefaultEnabled, + 'hover': colors.stateDefaultHover, + 'selected': colors.stateDefaultSelected, + 'focus': colors.stateDefaultFocus, + }; + final Map primary = { + 'enabled': colors.statePrimaryEnabled, + 'hover': colors.statePrimaryHover, + 'selected': colors.statePrimarySelected, + 'focus': colors.statePrimaryFocus, + }; + final Map secondary = { + 'enabled': colors.stateSecondaryEnabled, + 'hover': colors.stateSecondaryHover, + 'selected': colors.stateSecondarySelected, + 'focus': colors.stateSecondaryFocus, + }; + final Map positive = { + 'enabled': colors.statePositiveEnabled, + 'hover': colors.statePositiveHover, + 'selected': colors.statePositiveSelected, + 'focus': colors.statePositiveFocus, + }; + final Map negative = { + 'enabled': colors.stateNegativeEnabled, + 'hover': colors.stateNegativeHover, + 'selected': colors.stateNegativeSelected, + 'focus': colors.stateNegativeFocus, + }; + final Map info = { + 'enabled': colors.stateInfoEnabled, + 'hover': colors.stateInfoHover, + 'selected': colors.stateInfoSelected, + 'focus': colors.stateInfoFocus, + }; + final Map inverse = { + 'enabled': colors.stateInverseEnabled, + 'hover': colors.stateInverseHover, + 'selected': colors.stateInverseSelected, + 'focus': colors.stateInverseFocus, }; - return DefaultTextStyle( - style: ZetaTextStyles.displayMedium.apply( - color: Zeta.of(context).colors.cool, - decoration: TextDecoration.none, - ), - child: Container( - padding: EdgeInsets.symmetric(horizontal: Zeta.of(context).spacing.xl_4), - child: SingleChildScrollView( - key: PageStorageKey(0), - child: Column( - children: [ - SizedBox(height: Zeta.of(context).spacing.xl_4), - MyRow(children: textIcon, title: 'Text and icon styles'), - MyRow(children: border, title: 'Border styles'), - MyRow(children: backdrop, title: 'Backdrop colors'), - MyRow(children: alerts, title: 'Alert colors'), - Row(children: [Text('Full color swatches')]).paddingVertical(Zeta.of(context).spacing.xl_4), - ...swatches.entries.map( - (value) { - return Row( - children: List.generate(10, (index) => 100 - (10 * index)).map( - (e) { - return Expanded( - child: Container( - height: constraints.maxWidth / 10, - color: value.value[e], - child: FittedBox( - fit: BoxFit.scaleDown, - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - DefaultTextStyle( - style: ZetaTextStyles.bodyMedium.copyWith( - color: calculateTextColor(value.value[e] ?? Colors.white), - ), - child: Column( - children: [ - Text('${value.key.toLowerCase().replaceAll(' ', '')}-$e'), - Text( - value.value[e].toString().replaceAll('Color(0xff', '#').substring(0, 7), - ), - ], - ), - ), - ], - ), - ), - ), - ); - }, - ).toList(), - ); - }, - ), - SizedBox(height: Zeta.of(context).spacing.xl_4), - ], + return SingleChildScrollView( + padding: EdgeInsets.all(Zeta.of(context).spacing.medium), + child: Column( + children: [ + Text('Semantic colors', style: ZetaTextStyles.displaySmall), + MyRow(children: mainColors, title: 'Main Colors'), + MyRow(children: borderColors, title: 'Main Colors'), + MyRow(children: surfaceColors, title: 'Surface Colors'), + MyRow(children: avatarColors, title: 'Surface / Avatar Colors'), + MyRow(children: disabled, title: 'State / disabled Colors'), + MyRow(children: defaultColors, title: 'State / default Colors'), + MyRow(children: primary, title: 'State / primary Colors'), + MyRow(children: secondary, title: 'State / secondary Colors'), + MyRow(children: positive, title: 'State / positive Colors'), + MyRow(children: negative, title: 'State / negative Colors'), + MyRow(children: info, title: 'State / info Colors'), + MyRow(children: inverse, title: 'State / inverse Colors'), + Row(children: [ + Text('Full color swatches', style: ZetaTextStyles.displayMedium), + ]).paddingVertical(Zeta.of(context).spacing.xl_4), + Row( + children: primitivesPure.entries + .map( + (value) => SwatchBox( + color: value.value, + name: 'pure', + blockSize: blockSize, + value: value.key == 'mid' + ? 500 + : value.key == 'white' + ? 0 + : 1000, + ), + ) + .toList(), ), - ), + ...primitives.entries + .map( + (value) => Row( + children: List.generate(10, (index) => 100 - (10 * index)) + .map( + (e) => SwatchBox( + color: value.value[e] ?? Colors.white, + name: value.key, + blockSize: blockSize, + value: e, + ), + ) + .toList()), + ) + .toList(), + ], ), ); }); diff --git a/example/widgetbook/pages/theme/radius_widgetbook.dart b/example/widgetbook/pages/theme/radius_widgetbook.dart index 69a3a72e..e680cfcc 100644 --- a/example/widgetbook/pages/theme/radius_widgetbook.dart +++ b/example/widgetbook/pages/theme/radius_widgetbook.dart @@ -27,21 +27,21 @@ Widget radiusUseCase(BuildContext context) { height: 250, decoration: BoxDecoration( borderRadius: rad, - color: Zeta.of(context).colors.blue.shade30, - border: Border.all(color: colors.blue.shade80, width: 3), + color: Zeta.of(context).colors.surfacePrimarySubtle, + border: Border.all(color: colors.borderPrimary, width: 3), ), child: Center( child: Container( decoration: BoxDecoration( borderRadius: rad, - color: Zeta.of(context).colors.surfacePrimary, - border: Border.all(color: colors.blue.shade50, width: 3), + color: Zeta.of(context).colors.surfaceDefault, + border: Border.all(color: colors.borderPrimary, width: 3), ), padding: EdgeInsets.all(Zeta.of(context).spacing.large), child: Text( rad.radiusString.split('.').last.capitalize(), style: ZetaTextStyles.titleMedium.apply( - color: Zeta.of(context).colors.textDefault, + color: Zeta.of(context).colors.mainDefault, fontStyle: FontStyle.normal, decoration: TextDecoration.none, ), diff --git a/example/widgetbook/pages/theme/spacing_widgetbook.dart b/example/widgetbook/pages/theme/spacing_widgetbook.dart index 51a441c1..462958d2 100644 --- a/example/widgetbook/pages/theme/spacing_widgetbook.dart +++ b/example/widgetbook/pages/theme/spacing_widgetbook.dart @@ -66,10 +66,10 @@ class _SpacingDemo extends StatelessWidget { Widget build(BuildContext context) { final colors = Zeta.of(context).colors; return Container( - color: colors.blue.shade30, + color: colors.surfacePrimarySubtle, margin: EdgeInsets.all(Zeta.of(context).spacing.xl_2), child: CustomPaint( - painter: _TagPainter(color: colors.pink), + painter: _TagPainter(color: colors.primitives.pink), child: LayoutBuilder(builder: (context, c2) { return Container( margin: EdgeInsets.all(size.value), @@ -78,7 +78,7 @@ class _SpacingDemo extends StatelessWidget { child: Text( 'Zeta.of(context).spacing.' + size.key, style: ZetaTextStyles.titleMedium.apply( - color: Zeta.of(context).colors.textDefault, + color: Zeta.of(context).colors.mainDefault, fontStyle: FontStyle.normal, decoration: TextDecoration.none, ), diff --git a/example/widgetbook/pages/theme/typography_widgetbook.dart b/example/widgetbook/pages/theme/typography_widgetbook.dart index 900e36b1..8bb108e3 100644 --- a/example/widgetbook/pages/theme/typography_widgetbook.dart +++ b/example/widgetbook/pages/theme/typography_widgetbook.dart @@ -23,7 +23,8 @@ const Map allTypes = { 'Label indicator': ZetaTextStyles.labelIndicator, }; -Widget typographyUseCase(BuildContext context) => Padding( +Widget typographyUseCase(BuildContext context) => Container( + color: Zeta.of(context).colors.surfaceDefault, padding: EdgeInsets.all(Zeta.of(context).spacing.xl_2), child: Text( context.knobs.string(label: 'Text', initialValue: 'The quick brown fox jumps over the lazy dog.'), @@ -34,7 +35,7 @@ Widget typographyUseCase(BuildContext context) => Padding( options: allTypes.values.toList(), ) .apply( - color: Zeta.of(context).colors.textDefault, + color: Zeta.of(context).colors.mainDefault, fontStyle: FontStyle.normal, decoration: TextDecoration.none, ), diff --git a/example/widgetbook/utils/zeta_addon.dart b/example/widgetbook/utils/zeta_addon.dart index 9b28b3c4..01094b3f 100644 --- a/example/widgetbook/utils/zeta_addon.dart +++ b/example/widgetbook/utils/zeta_addon.dart @@ -17,7 +17,7 @@ class ZetaAddon extends WidgetbookAddon<_ZetaAddon> { @override Widget buildUseCase(BuildContext context, Widget child, _ZetaAddon data) { - return ZetaProvider.base( + return ZetaProvider( initialRounded: data.rounded, initialThemeMode: data.themeMode, initialContrast: data.contrast, diff --git a/lib/generated/tokens/semantics.g.dart b/lib/generated/tokens/semantics.g.dart index 475c4a5e..07b35439 100644 --- a/lib/generated/tokens/semantics.g.dart +++ b/lib/generated/tokens/semantics.g.dart @@ -1,11 +1,12 @@ +import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; import 'primitives.g.dart'; // This file is automatically generated by the zeta repository // DO NOT MODIFY -/// Semantic tokens for Colors. -abstract interface class ZetaSemanticColors { +/// The semantic tokens for colors +abstract interface class ZetaColors { /// Primitives used to construct semantic colors ZetaPrimitives get primitives; @@ -42,6 +43,33 @@ abstract interface class ZetaSemanticColors { /// Main Inverse color Color get mainInverse; + /// Text Default color + Color get textDefault; + + /// Icon Subtle color + Color get iconSubtle; + + /// Icon Inverse color + Color get iconInverse; + + /// Icon Disabled color + Color get iconDisabled; + + /// Icon Flavor Primary color + Color get iconFlavorPrimary; + + /// Icon Flavor Positive color + Color get iconFlavorPositive; + + /// Icon Flavor Warning color + Color get iconFlavorWarning; + + /// Icon Flavor Negative color + Color get iconFlavorNegative; + + /// Icon Flavor Info color + Color get iconFlavorInfo; + /// Border Default color Color get borderDefault; @@ -250,63 +278,63 @@ abstract interface class ZetaSemanticColors { Color get statePositiveFocus; } -/// Semantic tokens for Size. -abstract interface class ZetaSpacingSemantics { - /// Primitives used to construct semantic spaces +/// The semantic tokens for spacing +abstract interface class ZetaSpacing { + /// Primitives used to construct semantic spacing ZetaPrimitives get primitives; - /// None space + /// None spacing double get none; - /// Minimum space + /// Minimum spacing double get minimum; - /// Small space + /// Small spacing double get small; - /// Medium space + /// Medium spacing double get medium; - /// Large space + /// Large spacing double get large; - /// Xl space + /// Xl spacing double get xl; - /// Xl_2 space + /// Xl_2 spacing double get xl_2; - /// Xl_3 space + /// Xl_3 spacing double get xl_3; - /// Xl_4 space + /// Xl_4 spacing double get xl_4; - /// Xl_5 space + /// Xl_5 spacing double get xl_5; - /// Xl_6 space + /// Xl_6 spacing double get xl_6; - /// Xl_7 space + /// Xl_7 spacing double get xl_7; - /// Xl_8 space + /// Xl_8 spacing double get xl_8; - /// Xl_9 space + /// Xl_9 spacing double get xl_9; - /// Xl_10 space + /// Xl_10 spacing double get xl_10; - /// Xl_11 space + /// Xl_11 spacing double get xl_11; } -/// Semantic tokens for Radii. -abstract interface class ZetaRadiiSemantics { - /// Primitives used to construct semantic radii +/// The semantic tokens for radius +abstract interface class ZetaRadius { + /// Primitives used to construct semantic radius ZetaPrimitives get primitives; /// None radius @@ -328,64 +356,82 @@ abstract interface class ZetaRadiiSemantics { BorderRadius get full; } -/// The semantic colors for AA -class ZetaSemanticColorsAA implements ZetaSemanticColors { - /// Constructor for ZetaSemanticColorsAA - const ZetaSemanticColorsAA({required this.primitives}); +/// The semantic colors for AAA +class ZetaColorsAAA extends Equatable implements ZetaColors { + /// Constructor for [ZetaColorsAAA] + const ZetaColorsAAA({required this.primitives}); @override final ZetaPrimitives primitives; @override - Color get mainDefault => primitives.cool.shade90; + Color get mainDefault => primitives.cool.shade100; @override - Color get mainSubtle => primitives.cool.shade70; + Color get mainSubtle => primitives.cool.shade90; @override - Color get mainPrimary => primitives.primary.shade60; + Color get mainPrimary => primitives.primary.shade80; @override - Color get mainSecondary => primitives.secondary.shade60; + Color get mainSecondary => primitives.secondary.shade80; @override - Color get mainPositive => primitives.green.shade60; + Color get mainPositive => primitives.green.shade80; @override - Color get mainWarning => primitives.orange.shade60; + Color get mainWarning => primitives.orange.shade80; @override - Color get mainNegative => primitives.red.shade60; + Color get mainNegative => primitives.red.shade80; @override - Color get mainInfo => primitives.purple.shade60; + Color get mainInfo => primitives.purple.shade80; @override - Color get mainDisabled => primitives.cool.shade50; + Color get mainDisabled => primitives.cool.shade60; @override - Color get mainLight => primitives.cool.shade30; + Color get mainLight => primitives.pure.shade0; @override - Color get mainInverse => primitives.cool.shade20; + Color get mainInverse => primitives.pure.shade0; @override - Color get borderDefault => primitives.cool.shade40; + Color get textDefault => primitives.cool.shade100; + @override + Color get iconSubtle => primitives.cool.shade80; + @override + Color get iconInverse => primitives.pure.shade0; + @override + Color get iconDisabled => primitives.cool.shade60; + @override + Color get iconFlavorPrimary => primitives.primary.shade80; + @override + Color get iconFlavorPositive => primitives.green.shade80; + @override + Color get iconFlavorWarning => primitives.orange.shade80; + @override + Color get iconFlavorNegative => primitives.red.shade80; + @override + Color get iconFlavorInfo => primitives.purple.shade80; + @override + Color get borderDefault => primitives.cool.shade100; @override Color get borderSelected => primitives.cool.shade90; @override Color get borderHover => primitives.cool.shade90; @override - Color get borderSubtle => primitives.cool.shade30; + Color get borderSubtle => primitives.cool.shade80; @override Color get borderDisabled => primitives.cool.shade20; @override Color get borderPure => primitives.pure.shade0; @override - Color get borderPrimaryMain => primitives.primary.shade60; + Color get borderPrimaryMain => primitives.primary.shade80; @override - Color get borderPrimary => primitives.primary.shade50; + Color get borderPrimary => primitives.primary.shade70; @override - Color get borderSecondary => primitives.secondary.shade50; + Color get borderSecondary => primitives.secondary.shade70; @override - Color get borderPositive => primitives.green.shade50; + Color get borderPositive => primitives.green.shade70; @override - Color get borderWarning => primitives.orange.shade50; + Color get borderWarning => primitives.orange.shade70; @override - Color get borderNegative => primitives.red.shade50; + Color get borderNegative => primitives.red.shade70; @override - Color get borderInfo => primitives.purple.shade50; + Color get borderInfo => primitives.purple.shade70; @override Color get surfaceDefault => primitives.pure.shade0; @override - Color get surfaceDefaultInverse => primitives.warm.shade100; + Color get surfaceDefaultInverse => primitives.pure.shade1000; @override Color get surfaceHover => primitives.cool.shade20; @override @@ -399,11 +445,11 @@ class ZetaSemanticColorsAA implements ZetaSemanticColors { @override Color get surfaceWarm => primitives.warm.shade10; @override - Color get surfacePrimary => primitives.primary.shade60; + Color get surfacePrimary => primitives.primary.shade80; @override Color get surfacePrimarySubtle => primitives.primary.shade10; @override - Color get surfaceSecondary => primitives.secondary.shade60; + Color get surfaceSecondary => primitives.secondary.shade80; @override Color get surfaceAvatarBlue => primitives.blue.shade80; @override @@ -421,19 +467,19 @@ class ZetaSemanticColorsAA implements ZetaSemanticColors { @override Color get surfaceSecondarySubtle => primitives.secondary.shade10; @override - Color get surfacePositive => primitives.green.shade60; + Color get surfacePositive => primitives.green.shade80; @override Color get surfacePositiveSubtle => primitives.green.shade10; @override - Color get surfaceWarning => primitives.orange.shade60; + Color get surfaceWarning => primitives.orange.shade80; @override Color get surfaceWarningSubtle => primitives.orange.shade10; @override - Color get surfaceNegative => primitives.red.shade60; + Color get surfaceNegative => primitives.red.shade80; @override Color get surfaceNegativeSubtle => primitives.red.shade10; @override - Color get surfaceInfo => primitives.purple.shade60; + Color get surfaceInfo => primitives.purple.shade80; @override Color get surfaceInfoSubtle => primitives.purple.shade10; @override @@ -447,113 +493,223 @@ class ZetaSemanticColorsAA implements ZetaSemanticColors { @override Color get stateDefaultFocus => primitives.pure.shade0; @override - Color get statePrimaryEnabled => primitives.primary.shade60; + Color get statePrimaryEnabled => primitives.primary.shade80; @override - Color get statePrimaryHover => primitives.primary.shade50; + Color get statePrimaryHover => primitives.primary.shade70; @override - Color get statePrimarySelected => primitives.primary.shade70; + Color get statePrimarySelected => primitives.primary.shade90; @override - Color get statePrimaryFocus => primitives.primary.shade60; + Color get statePrimaryFocus => primitives.primary.shade80; @override - Color get stateSecondaryEnabled => primitives.secondary.shade40; + Color get stateSecondaryEnabled => primitives.secondary.shade80; @override - Color get stateSecondaryHover => primitives.secondary.shade30; + Color get stateSecondaryHover => primitives.secondary.shade70; @override - Color get stateSecondarySelected => primitives.secondary.shade50; + Color get stateSecondarySelected => primitives.secondary.shade90; @override - Color get stateSecondaryFocus => primitives.secondary.shade40; + Color get stateSecondaryFocus => primitives.secondary.shade80; @override - Color get stateNegativeEnabled => primitives.red.shade60; + Color get stateNegativeEnabled => primitives.red.shade80; @override - Color get stateNegativeHover => primitives.red.shade50; + Color get stateNegativeHover => primitives.red.shade70; @override - Color get stateNegativeSelected => primitives.red.shade70; + Color get stateNegativeSelected => primitives.red.shade90; @override - Color get stateNegativeFocus => primitives.red.shade60; + Color get stateNegativeFocus => primitives.red.shade80; @override - Color get stateInfoEnabled => primitives.purple.shade60; + Color get stateInfoEnabled => primitives.purple.shade80; @override - Color get stateInfoHover => primitives.purple.shade50; + Color get stateInfoHover => primitives.purple.shade70; @override - Color get stateInfoSelected => primitives.purple.shade70; + Color get stateInfoSelected => primitives.purple.shade90; @override - Color get stateInfoFocus => primitives.purple.shade60; + Color get stateInfoFocus => primitives.purple.shade80; @override - Color get stateInverseEnabled => primitives.cool.shade100; + Color get stateInverseEnabled => primitives.pure.shade1000; @override Color get stateInverseHover => primitives.cool.shade90; @override - Color get stateInverseSelected => primitives.cool.shade100; + Color get stateInverseSelected => primitives.pure.shade1000; @override - Color get stateInverseFocus => primitives.cool.shade100; + Color get stateInverseFocus => primitives.pure.shade1000; @override - Color get statePositiveEnabled => primitives.green.shade60; + Color get statePositiveEnabled => primitives.green.shade80; @override - Color get statePositiveHover => primitives.green.shade50; + Color get statePositiveHover => primitives.green.shade70; @override - Color get statePositiveSelected => primitives.green.shade70; + Color get statePositiveSelected => primitives.green.shade90; @override - Color get statePositiveFocus => primitives.green.shade60; + Color get statePositiveFocus => primitives.green.shade80; + @override + List get props => [ + mainDefault, + mainSubtle, + mainPrimary, + mainSecondary, + mainPositive, + mainWarning, + mainNegative, + mainInfo, + mainDisabled, + mainLight, + mainInverse, + textDefault, + iconSubtle, + iconInverse, + iconDisabled, + iconFlavorPrimary, + iconFlavorPositive, + iconFlavorWarning, + iconFlavorNegative, + iconFlavorInfo, + borderDefault, + borderSelected, + borderHover, + borderSubtle, + borderDisabled, + borderPure, + borderPrimaryMain, + borderPrimary, + borderSecondary, + borderPositive, + borderWarning, + borderNegative, + borderInfo, + surfaceDefault, + surfaceDefaultInverse, + surfaceHover, + surfaceSelected, + surfaceSelectedHover, + surfaceDisabled, + surfaceCool, + surfaceWarm, + surfacePrimary, + surfacePrimarySubtle, + surfaceSecondary, + surfaceAvatarBlue, + surfaceAvatarGreen, + surfaceAvatarOrange, + surfaceAvatarPink, + surfaceAvatarPurple, + surfaceAvatarTeal, + surfaceAvatarYellow, + surfaceSecondarySubtle, + surfacePositive, + surfacePositiveSubtle, + surfaceWarning, + surfaceWarningSubtle, + surfaceNegative, + surfaceNegativeSubtle, + surfaceInfo, + surfaceInfoSubtle, + stateDisabledDisabled, + stateDefaultEnabled, + stateDefaultHover, + stateDefaultSelected, + stateDefaultFocus, + statePrimaryEnabled, + statePrimaryHover, + statePrimarySelected, + statePrimaryFocus, + stateSecondaryEnabled, + stateSecondaryHover, + stateSecondarySelected, + stateSecondaryFocus, + stateNegativeEnabled, + stateNegativeHover, + stateNegativeSelected, + stateNegativeFocus, + stateInfoEnabled, + stateInfoHover, + stateInfoSelected, + stateInfoFocus, + stateInverseEnabled, + stateInverseHover, + stateInverseSelected, + stateInverseFocus, + statePositiveEnabled, + statePositiveHover, + statePositiveSelected, + statePositiveFocus, + ]; } -/// The semantic colors for AAA -class ZetaSemanticColorsAAA implements ZetaSemanticColors { - /// Constructor for ZetaSemanticColorsAAA - const ZetaSemanticColorsAAA({required this.primitives}); +/// The semantic colors for AA +class ZetaColorsAA extends Equatable implements ZetaColors { + /// Constructor for [ZetaColorsAA] + const ZetaColorsAA({required this.primitives}); @override final ZetaPrimitives primitives; @override - Color get mainDefault => primitives.cool.shade100; + Color get mainDefault => primitives.cool.shade90; @override - Color get mainSubtle => primitives.cool.shade90; + Color get mainSubtle => primitives.cool.shade70; @override - Color get mainPrimary => primitives.primary.shade80; + Color get mainPrimary => primitives.primary.shade60; @override - Color get mainSecondary => primitives.secondary.shade80; + Color get mainSecondary => primitives.secondary.shade60; @override - Color get mainPositive => primitives.green.shade80; + Color get mainPositive => primitives.green.shade60; @override - Color get mainWarning => primitives.orange.shade80; + Color get mainWarning => primitives.orange.shade60; @override - Color get mainNegative => primitives.red.shade80; + Color get mainNegative => primitives.red.shade60; @override - Color get mainInfo => primitives.purple.shade80; + Color get mainInfo => primitives.purple.shade60; @override - Color get mainDisabled => primitives.cool.shade60; + Color get mainDisabled => primitives.cool.shade50; @override - Color get mainLight => primitives.pure.shade0; + Color get mainLight => primitives.cool.shade30; @override - Color get mainInverse => primitives.pure.shade0; + Color get mainInverse => primitives.cool.shade20; @override - Color get borderDefault => primitives.cool.shade100; + Color get textDefault => primitives.cool.shade90; + @override + Color get iconSubtle => primitives.cool.shade70; + @override + Color get iconInverse => primitives.cool.shade20; + @override + Color get iconDisabled => primitives.cool.shade50; + @override + Color get iconFlavorPrimary => primitives.primary.shade60; + @override + Color get iconFlavorPositive => primitives.green.shade60; + @override + Color get iconFlavorWarning => primitives.orange.shade60; + @override + Color get iconFlavorNegative => primitives.red.shade60; + @override + Color get iconFlavorInfo => primitives.purple.shade60; + @override + Color get borderDefault => primitives.cool.shade40; @override Color get borderSelected => primitives.cool.shade90; @override Color get borderHover => primitives.cool.shade90; @override - Color get borderSubtle => primitives.cool.shade80; + Color get borderSubtle => primitives.cool.shade30; @override Color get borderDisabled => primitives.cool.shade20; @override Color get borderPure => primitives.pure.shade0; @override - Color get borderPrimaryMain => primitives.primary.shade80; + Color get borderPrimaryMain => primitives.primary.shade60; @override - Color get borderPrimary => primitives.primary.shade70; + Color get borderPrimary => primitives.primary.shade50; @override - Color get borderSecondary => primitives.secondary.shade70; + Color get borderSecondary => primitives.secondary.shade50; @override - Color get borderPositive => primitives.green.shade70; + Color get borderPositive => primitives.green.shade50; @override - Color get borderWarning => primitives.orange.shade70; + Color get borderWarning => primitives.orange.shade50; @override - Color get borderNegative => primitives.red.shade70; + Color get borderNegative => primitives.red.shade50; @override - Color get borderInfo => primitives.purple.shade70; + Color get borderInfo => primitives.purple.shade50; @override Color get surfaceDefault => primitives.pure.shade0; @override - Color get surfaceDefaultInverse => primitives.pure.shade1000; + Color get surfaceDefaultInverse => primitives.warm.shade100; @override Color get surfaceHover => primitives.cool.shade20; @override @@ -567,11 +723,11 @@ class ZetaSemanticColorsAAA implements ZetaSemanticColors { @override Color get surfaceWarm => primitives.warm.shade10; @override - Color get surfacePrimary => primitives.primary.shade80; + Color get surfacePrimary => primitives.primary.shade60; @override Color get surfacePrimarySubtle => primitives.primary.shade10; @override - Color get surfaceSecondary => primitives.secondary.shade80; + Color get surfaceSecondary => primitives.secondary.shade60; @override Color get surfaceAvatarBlue => primitives.blue.shade80; @override @@ -589,19 +745,19 @@ class ZetaSemanticColorsAAA implements ZetaSemanticColors { @override Color get surfaceSecondarySubtle => primitives.secondary.shade10; @override - Color get surfacePositive => primitives.green.shade80; + Color get surfacePositive => primitives.green.shade60; @override Color get surfacePositiveSubtle => primitives.green.shade10; @override - Color get surfaceWarning => primitives.orange.shade80; + Color get surfaceWarning => primitives.orange.shade60; @override Color get surfaceWarningSubtle => primitives.orange.shade10; @override - Color get surfaceNegative => primitives.red.shade80; + Color get surfaceNegative => primitives.red.shade60; @override Color get surfaceNegativeSubtle => primitives.red.shade10; @override - Color get surfaceInfo => primitives.purple.shade80; + Color get surfaceInfo => primitives.purple.shade60; @override Color get surfaceInfoSubtle => primitives.purple.shade10; @override @@ -615,299 +771,368 @@ class ZetaSemanticColorsAAA implements ZetaSemanticColors { @override Color get stateDefaultFocus => primitives.pure.shade0; @override - Color get statePrimaryEnabled => primitives.primary.shade80; + Color get statePrimaryEnabled => primitives.primary.shade60; @override - Color get statePrimaryHover => primitives.primary.shade70; + Color get statePrimaryHover => primitives.primary.shade50; @override - Color get statePrimarySelected => primitives.primary.shade90; + Color get statePrimarySelected => primitives.primary.shade70; @override - Color get statePrimaryFocus => primitives.primary.shade80; + Color get statePrimaryFocus => primitives.primary.shade60; @override - Color get stateSecondaryEnabled => primitives.secondary.shade80; + Color get stateSecondaryEnabled => primitives.secondary.shade40; @override - Color get stateSecondaryHover => primitives.secondary.shade70; + Color get stateSecondaryHover => primitives.secondary.shade30; @override - Color get stateSecondarySelected => primitives.secondary.shade90; + Color get stateSecondarySelected => primitives.secondary.shade50; @override - Color get stateSecondaryFocus => primitives.secondary.shade80; + Color get stateSecondaryFocus => primitives.secondary.shade40; @override - Color get stateNegativeEnabled => primitives.red.shade80; + Color get stateNegativeEnabled => primitives.red.shade60; @override - Color get stateNegativeHover => primitives.red.shade70; + Color get stateNegativeHover => primitives.red.shade50; @override - Color get stateNegativeSelected => primitives.red.shade90; + Color get stateNegativeSelected => primitives.red.shade70; @override - Color get stateNegativeFocus => primitives.red.shade80; + Color get stateNegativeFocus => primitives.red.shade60; @override - Color get stateInfoEnabled => primitives.purple.shade80; + Color get stateInfoEnabled => primitives.purple.shade60; @override - Color get stateInfoHover => primitives.purple.shade70; + Color get stateInfoHover => primitives.purple.shade50; @override - Color get stateInfoSelected => primitives.purple.shade90; + Color get stateInfoSelected => primitives.purple.shade70; @override - Color get stateInfoFocus => primitives.purple.shade80; + Color get stateInfoFocus => primitives.purple.shade60; @override - Color get stateInverseEnabled => primitives.pure.shade1000; + Color get stateInverseEnabled => primitives.cool.shade100; @override Color get stateInverseHover => primitives.cool.shade90; @override - Color get stateInverseSelected => primitives.pure.shade1000; + Color get stateInverseSelected => primitives.cool.shade100; @override - Color get stateInverseFocus => primitives.pure.shade1000; + Color get stateInverseFocus => primitives.cool.shade100; @override - Color get statePositiveEnabled => primitives.green.shade80; + Color get statePositiveEnabled => primitives.green.shade60; @override - Color get statePositiveHover => primitives.green.shade70; + Color get statePositiveHover => primitives.green.shade50; @override - Color get statePositiveSelected => primitives.green.shade90; + Color get statePositiveSelected => primitives.green.shade70; @override - Color get statePositiveFocus => primitives.green.shade80; + Color get statePositiveFocus => primitives.green.shade60; + @override + List get props => [ + mainDefault, + mainSubtle, + mainPrimary, + mainSecondary, + mainPositive, + mainWarning, + mainNegative, + mainInfo, + mainDisabled, + mainLight, + mainInverse, + textDefault, + iconSubtle, + iconInverse, + iconDisabled, + iconFlavorPrimary, + iconFlavorPositive, + iconFlavorWarning, + iconFlavorNegative, + iconFlavorInfo, + borderDefault, + borderSelected, + borderHover, + borderSubtle, + borderDisabled, + borderPure, + borderPrimaryMain, + borderPrimary, + borderSecondary, + borderPositive, + borderWarning, + borderNegative, + borderInfo, + surfaceDefault, + surfaceDefaultInverse, + surfaceHover, + surfaceSelected, + surfaceSelectedHover, + surfaceDisabled, + surfaceCool, + surfaceWarm, + surfacePrimary, + surfacePrimarySubtle, + surfaceSecondary, + surfaceAvatarBlue, + surfaceAvatarGreen, + surfaceAvatarOrange, + surfaceAvatarPink, + surfaceAvatarPurple, + surfaceAvatarTeal, + surfaceAvatarYellow, + surfaceSecondarySubtle, + surfacePositive, + surfacePositiveSubtle, + surfaceWarning, + surfaceWarningSubtle, + surfaceNegative, + surfaceNegativeSubtle, + surfaceInfo, + surfaceInfoSubtle, + stateDisabledDisabled, + stateDefaultEnabled, + stateDefaultHover, + stateDefaultSelected, + stateDefaultFocus, + statePrimaryEnabled, + statePrimaryHover, + statePrimarySelected, + statePrimaryFocus, + stateSecondaryEnabled, + stateSecondaryHover, + stateSecondarySelected, + stateSecondaryFocus, + stateNegativeEnabled, + stateNegativeHover, + stateNegativeSelected, + stateNegativeFocus, + stateInfoEnabled, + stateInfoHover, + stateInfoSelected, + stateInfoFocus, + stateInverseEnabled, + stateInverseHover, + stateInverseSelected, + stateInverseFocus, + statePositiveEnabled, + statePositiveHover, + statePositiveSelected, + statePositiveFocus, + ]; } -/// The semantic sizes for AA -final class ZetaSpacingAA implements ZetaSpacingSemantics { - /// Constructor for ZetaSpacingAA - const ZetaSpacingAA({required this.primitives}); - - /// The primitives for this sizes +/// The semantic spacing for AAA +class ZetaSpacingAAA extends Equatable implements ZetaSpacing { + /// Constructor for [ZetaSpacingAAA] + const ZetaSpacingAAA({required this.primitives}); @override final ZetaPrimitives primitives; - - /// None space @override double get none => primitives.x0; - - /// Minimum space @override double get minimum => primitives.x1; - - /// Small space @override double get small => primitives.x2; - - /// Medium space @override double get medium => primitives.x3; - - /// Large space @override double get large => primitives.x4; - - /// Xl space @override double get xl => primitives.x5; - - /// Xl_2 space @override double get xl_2 => primitives.x6; - - /// Xl_3 space @override double get xl_3 => primitives.x7; - - /// Xl_4 space @override double get xl_4 => primitives.x8; - - /// Xl_5 space @override double get xl_5 => primitives.x9; - - /// Xl_6 space @override double get xl_6 => primitives.x10; - - /// Xl_7 space @override double get xl_7 => primitives.x11; - - /// Xl_8 space @override double get xl_8 => primitives.x12; - - /// Xl_9 space @override double get xl_9 => primitives.x13; - - /// Xl_10 space @override double get xl_10 => primitives.x14; - - /// Xl_11 space @override double get xl_11 => primitives.x15; + @override + List get props => [ + none, + minimum, + small, + medium, + large, + xl, + xl_2, + xl_3, + xl_4, + xl_5, + xl_6, + xl_7, + xl_8, + xl_9, + xl_10, + xl_11, + ]; } -/// The semantic sizes for AAA -final class ZetaSpacingAAA implements ZetaSpacingSemantics { - /// Constructor for ZetaSpacingAAA - const ZetaSpacingAAA({required this.primitives}); - - /// The primitives for this sizes +/// The semantic spacing for AA +class ZetaSpacingAA extends Equatable implements ZetaSpacing { + /// Constructor for [ZetaSpacingAA] + const ZetaSpacingAA({required this.primitives}); @override final ZetaPrimitives primitives; - - /// None space @override double get none => primitives.x0; - - /// Minimum space @override double get minimum => primitives.x1; - - /// Small space @override double get small => primitives.x2; - - /// Medium space @override double get medium => primitives.x3; - - /// Large space @override double get large => primitives.x4; - - /// Xl space @override double get xl => primitives.x5; - - /// Xl_2 space @override double get xl_2 => primitives.x6; - - /// Xl_3 space @override double get xl_3 => primitives.x7; - - /// Xl_4 space @override double get xl_4 => primitives.x8; - - /// Xl_5 space @override double get xl_5 => primitives.x9; - - /// Xl_6 space @override double get xl_6 => primitives.x10; - - /// Xl_7 space @override double get xl_7 => primitives.x11; - - /// Xl_8 space @override double get xl_8 => primitives.x12; - - /// Xl_9 space @override double get xl_9 => primitives.x13; - - /// Xl_10 space @override double get xl_10 => primitives.x14; - - /// Xl_11 space @override double get xl_11 => primitives.x15; + @override + List get props => [ + none, + minimum, + small, + medium, + large, + xl, + xl_2, + xl_3, + xl_4, + xl_5, + xl_6, + xl_7, + xl_8, + xl_9, + xl_10, + xl_11, + ]; } -/// The semantic radii for AA -final class ZetaRadiiAA implements ZetaRadiiSemantics { - /// Constructor for ZetaRadiiAA - const ZetaRadiiAA({required this.primitives}); - - /// The primitives for this radii +/// The semantic radius for AAA +class ZetaRadiusAAA extends Equatable implements ZetaRadius { + /// Constructor for [ZetaRadiusAAA] + const ZetaRadiusAAA({required this.primitives}); @override final ZetaPrimitives primitives; - @override BorderRadius get none => BorderRadius.circular(0); @override - BorderRadius get minimal => BorderRadius.all(primitives.s); + BorderRadius get minimal => BorderRadius.circular(0); @override - BorderRadius get rounded => BorderRadius.all(primitives.m); + BorderRadius get rounded => BorderRadius.circular(0); @override - BorderRadius get large => BorderRadius.all(primitives.l); + BorderRadius get large => BorderRadius.circular(0); @override - BorderRadius get xl => BorderRadius.all(primitives.xl); + BorderRadius get xl => BorderRadius.circular(0); @override - BorderRadius get full => BorderRadius.all(primitives.xl_4); + BorderRadius get full => BorderRadius.circular(0); + @override + List get props => [ + none, + minimal, + rounded, + large, + xl, + full, + ]; } -/// The semantic radii for AAA -final class ZetaRadiiAAA implements ZetaRadiiSemantics { - /// Constructor for ZetaRadiiAAA - const ZetaRadiiAAA({required this.primitives}); - - /// The primitives for this radii +/// The semantic radius for AA +class ZetaRadiusAA extends Equatable implements ZetaRadius { + /// Constructor for [ZetaRadiusAA] + const ZetaRadiusAA({required this.primitives}); @override final ZetaPrimitives primitives; - @override BorderRadius get none => BorderRadius.circular(0); @override - BorderRadius get minimal => BorderRadius.circular(0); + BorderRadius get minimal => BorderRadius.all(primitives.s); @override - BorderRadius get rounded => BorderRadius.circular(0); + BorderRadius get rounded => BorderRadius.all(primitives.m); @override - BorderRadius get large => BorderRadius.circular(0); + BorderRadius get large => BorderRadius.all(primitives.l); @override - BorderRadius get xl => BorderRadius.circular(0); + BorderRadius get xl => BorderRadius.all(primitives.xl); @override - BorderRadius get full => BorderRadius.circular(0); + BorderRadius get full => BorderRadius.all(primitives.xl_4); + @override + List get props => [ + none, + minimal, + rounded, + large, + xl, + full, + ]; } -/// Zeta Semantic colors object. -/// -/// Note: This typedef is used to make object generation easier. -typedef ZetaColorSemantics = ZetaSemanticColors; - /// The semantic tokens for Zeta abstract interface class ZetaSemantics { /// Semantic colors - ZetaColorSemantics get colors; + ZetaColors get colors; /// Semantic sizes - ZetaSpacingSemantics get size; + ZetaSpacing get spacing; - /// Semantic Radii - ZetaRadiiSemantics get radii; + /// Semantic Radius + ZetaRadius get radius; /// Primitives for this semantics ZetaPrimitives get primitives; } -/// The semantic tokens for AA -class ZetaSemanticsAA implements ZetaSemantics { - /// Constructor for [ZetaSemanticsAA] - ZetaSemanticsAA({required this.primitives}) - : colors = ZetaSemanticColorsAA(primitives: primitives), - size = ZetaSpacingAA(primitives: primitives), - radii = ZetaRadiiAA(primitives: primitives); +/// The semantic tokens for AAA +class ZetaSemanticsAAA implements ZetaSemantics { + /// Constructor for [ZetaSemanticsAAA] + ZetaSemanticsAAA({required this.primitives}) + : colors = ZetaColorsAAA(primitives: primitives), + spacing = ZetaSpacingAAA(primitives: primitives), + radius = ZetaRadiusAAA(primitives: primitives); @override final ZetaPrimitives primitives; @override - final ZetaColorSemantics colors; + final ZetaColors colors; @override - final ZetaSpacingSemantics size; + final ZetaSpacing spacing; @override - final ZetaRadiiSemantics radii; + final ZetaRadius radius; } -/// The semantic tokens for AAA -class ZetaSemanticsAAA implements ZetaSemantics { - /// Constructor for [ZetaSemanticsAAA] - ZetaSemanticsAAA({required this.primitives}) - : colors = ZetaSemanticColorsAAA(primitives: primitives), - size = ZetaSpacingAAA(primitives: primitives), - radii = ZetaRadiiAAA(primitives: primitives); +/// The semantic tokens for AA +class ZetaSemanticsAA implements ZetaSemantics { + /// Constructor for [ZetaSemanticsAA] + ZetaSemanticsAA({required this.primitives}) + : colors = ZetaColorsAA(primitives: primitives), + spacing = ZetaSpacingAA(primitives: primitives), + radius = ZetaRadiusAA(primitives: primitives); @override final ZetaPrimitives primitives; @override - final ZetaColorSemantics colors; + final ZetaColors colors; @override - final ZetaSpacingSemantics size; + final ZetaSpacing spacing; @override - final ZetaRadiiSemantics radii; + final ZetaRadius radius; } diff --git a/lib/src/components/accordion/accordion.dart b/lib/src/components/accordion/accordion.dart index db0e0180..834b0f18 100644 --- a/lib/src/components/accordion/accordion.dart +++ b/lib/src/components/accordion/accordion.dart @@ -101,8 +101,9 @@ class _ZetaAccordionState extends State with TickerProviderStateM Widget build(BuildContext context) { final zetaColors = Zeta.of(context).colors; final borderColor = _disabled ? zetaColors.borderDisabled : zetaColors.borderSubtle; - final childTextStyle = ZetaTextStyles.h5.apply(color: zetaColors.textDefault); + final childTextStyle = ZetaTextStyles.h5.apply(color: zetaColors.mainDefault); final rounded = context.rounded; + final Color color = _disabled ? zetaColors.mainDisabled : zetaColors.mainDefault; return ZetaRoundedScope( rounded: rounded, child: DecoratedBox( @@ -124,10 +125,10 @@ class _ZetaAccordionState extends State with TickerProviderStateM ), overlayColor: WidgetStateProperty.resolveWith((states) { if (states.contains(WidgetState.hovered)) { - return zetaColors.cool.shade20; + return zetaColors.surfaceHover; } if (states.contains(WidgetState.pressed)) { - return zetaColors.cool.shade30; + return zetaColors.surfaceSelectedHover; } if (states.contains(WidgetState.focused)) { @@ -138,7 +139,7 @@ class _ZetaAccordionState extends State with TickerProviderStateM }), side: WidgetStateProperty.resolveWith((states) { if (states.contains(WidgetState.focused)) { - return BorderSide(color: zetaColors.blue.shade50, width: 2); + return BorderSide(color: zetaColors.borderPrimary, width: 2); } return null; }), @@ -161,7 +162,7 @@ class _ZetaAccordionState extends State with TickerProviderStateM children: [ DefaultTextStyle( style: ZetaTextStyles.titleMedium.apply( - color: _disabled ? zetaColors.textDisabled : zetaColors.textDefault, + color: color, ), child: Flexible(child: Text(widget.title)), ), @@ -169,7 +170,7 @@ class _ZetaAccordionState extends State with TickerProviderStateM padding: EdgeInsets.only(left: Zeta.of(context).spacing.large), child: ZetaIcon( _isOpen ? ZetaIcons.remove : ZetaIcons.add, - color: _disabled ? zetaColors.iconDisabled : zetaColors.iconDefault, + color: color, ), ), ], diff --git a/lib/src/components/avatars/avatar.dart b/lib/src/components/avatars/avatar.dart index 0e99d5af..2f54449d 100644 --- a/lib/src/components/avatars/avatar.dart +++ b/lib/src/components/avatars/avatar.dart @@ -271,7 +271,7 @@ class ZetaAvatar extends ZetaStatelessWidget { border: borderColor != null ? Border.all(color: borderColor!, width: 0) : null, borderRadius: Zeta.of(context).radius.full, color: backgroundColor ?? - (_showPlaceholder ? zetaColors.surfacePrimary : zetaColors.cool.shade20), + (_showPlaceholder ? zetaColors.surfacePrimary : zetaColors.primitives.cool.shade20), ), child: borderColor != null ? Container( @@ -328,7 +328,7 @@ class ZetaAvatar extends ZetaStatelessWidget { label!, style: labelTextStyle ?? size.labelStyle(context).copyWith( - color: zetaColors.textSubtle, + color: zetaColors.mainSubtle, ), maxLines: labelMaxLines, overflow: TextOverflow.ellipsis, @@ -546,7 +546,7 @@ class ZetaAvatarBadge extends StatelessWidget { Widget build(BuildContext context) { final colors = Zeta.of(context).colors; final Color backgroundColor = - type == ZetaAvatarBadgeType.notification ? colors.surfaceNegative : (color ?? colors.primary); + type == ZetaAvatarBadgeType.notification ? colors.surfaceNegative : (color ?? colors.mainPrimary); final badgeSize = _getContainerSize(context); final borderSize = _getBorderSize(context); final paddedSize = badgeSize + Zeta.of(context).spacing.minimum; diff --git a/lib/src/components/badges/indicator.dart b/lib/src/components/badges/indicator.dart index efbb3d4e..f61008f9 100644 --- a/lib/src/components/badges/indicator.dart +++ b/lib/src/components/badges/indicator.dart @@ -108,8 +108,9 @@ class ZetaIndicator extends ZetaStatelessWidget { @override Widget build(BuildContext context) { final zetaColors = Zeta.of(context).colors; - final Color backgroundColor = (type == ZetaIndicatorType.icon ? zetaColors.blue : zetaColors.surfaceNegative); - final Color foregroundColor = backgroundColor.onColor; + final Color backgroundColor = + (type == ZetaIndicatorType.icon ? zetaColors.mainPrimary : zetaColors.surfaceNegative); + final Color foregroundColor = zetaColors.mainInverse; final sizePixels = _getSizePixels(size, type, context); return Semantics( @@ -122,7 +123,7 @@ class ZetaIndicator extends ZetaStatelessWidget { ? BoxDecoration( border: Border.all( width: ZetaBorders.medium, - color: Zeta.of(context).colors.borderSubtle, + color: zetaColors.mainInverse, ), color: (inverse ? foregroundColor : Colors.transparent), borderRadius: Zeta.of(context).radius.full, diff --git a/lib/src/components/badges/label.dart b/lib/src/components/badges/label.dart index 95f0b379..53f7f02d 100644 --- a/lib/src/components/badges/label.dart +++ b/lib/src/components/badges/label.dart @@ -43,6 +43,7 @@ class ZetaLabel extends ZetaStatelessWidget { @override Widget build(BuildContext context) { final Color backgroundColor = status.labelBackgroundColor(context); + final Color foregroundColor = status.labelForegroundColor(context); return Semantics( label: semanticLabel ?? label, @@ -54,7 +55,7 @@ class ZetaLabel extends ZetaStatelessWidget { ), child: Text( label, - style: ZetaTextStyles.labelSmall.apply(color: backgroundColor.onColor), + style: ZetaTextStyles.labelSmall.apply(color: foregroundColor), overflow: TextOverflow.ellipsis, ), ), @@ -81,11 +82,24 @@ extension on ZetaWidgetStatus { case ZetaWidgetStatus.positive: return colors.surfacePositive; case ZetaWidgetStatus.warning: - return colors.surfaceWarning.shade40; + return colors.surfaceWarning; case ZetaWidgetStatus.negative: return colors.surfaceNegative; case ZetaWidgetStatus.neutral: - return colors.cool.shade30; + return colors.mainLight; + } + } + + Color labelForegroundColor(BuildContext context) { + final colors = Zeta.of(context).colors; + switch (this) { + case ZetaWidgetStatus.info: + case ZetaWidgetStatus.positive: + case ZetaWidgetStatus.warning: + case ZetaWidgetStatus.negative: + return colors.mainInverse; + case ZetaWidgetStatus.neutral: + return colors.mainDefault; } } } diff --git a/lib/src/components/badges/priority_pill.dart b/lib/src/components/badges/priority_pill.dart index 1d94500a..6e107e42 100644 --- a/lib/src/components/badges/priority_pill.dart +++ b/lib/src/components/badges/priority_pill.dart @@ -30,17 +30,31 @@ enum ZetaPriorityPillSize { } extension on ZetaPriorityPillType { - ZetaColorSwatch color(BuildContext context) { + Color badgeColor(BuildContext context) { final colors = Zeta.of(context).colors; switch (this) { case ZetaPriorityPillType.urgent: - return colors.red; + return colors.mainNegative; case ZetaPriorityPillType.high: - return colors.orange; + return colors.mainWarning; case ZetaPriorityPillType.medium: - return colors.blue; + return colors.mainPrimary; case ZetaPriorityPillType.low: - return colors.green; + return colors.mainPositive; + } + } + + Color lozengeColor(BuildContext context) { + final colors = Zeta.of(context).colors; + switch (this) { + case ZetaPriorityPillType.urgent: + return colors.surfaceNegativeSubtle; + case ZetaPriorityPillType.high: + return colors.surfaceWarningSubtle; + case ZetaPriorityPillType.medium: + return colors.surfacePrimarySubtle; + case ZetaPriorityPillType.low: + return colors.surfacePositiveSubtle; } } } @@ -109,7 +123,9 @@ class ZetaPriorityPill extends ZetaStatelessWidget { @override Widget build(BuildContext context) { - final ZetaColorSwatch color = customColor ?? type.color(context); + final Color badgeColor = customColor?.shade60 ?? type.badgeColor(context); + final Color lozengeColor = customColor?.shade10 ?? type.lozengeColor(context); + final size = this.size == ZetaPriorityPillSize.small ? Zeta.of(context).spacing.xl : Zeta.of(context).spacing.xl_3; final label = (this.label ?? priority) ?? type.name.capitalize(); final rounded = context.rounded; @@ -119,7 +135,7 @@ class ZetaPriorityPill extends ZetaStatelessWidget { child: DecoratedBox( decoration: BoxDecoration( borderRadius: rounded ? Zeta.of(context).radius.full : Zeta.of(context).radius.none, - color: color.shade10, + color: lozengeColor, ), child: Row( mainAxisSize: MainAxisSize.min, @@ -130,7 +146,7 @@ class ZetaPriorityPill extends ZetaStatelessWidget { width: size, decoration: BoxDecoration( shape: rounded ? BoxShape.circle : BoxShape.rectangle, - color: color, + color: badgeColor, ), child: Text( (index?.isEmpty ?? true) @@ -142,9 +158,9 @@ class ZetaPriorityPill extends ZetaStatelessWidget { ? ZetaTextStyles.labelSmall.copyWith( fontSize: 10, height: 13 / 10, - color: color.onColor, + color: Zeta.of(context).colors.mainInverse, ) - : ZetaTextStyles.labelMedium.apply(color: color.onColor), + : ZetaTextStyles.labelMedium.apply(color: Zeta.of(context).colors.mainInverse), ), ), if (!isBadge) diff --git a/lib/src/components/badges/status_label.dart b/lib/src/components/badges/status_label.dart index 6ba61e3e..5cde97a0 100644 --- a/lib/src/components/badges/status_label.dart +++ b/lib/src/components/badges/status_label.dart @@ -38,14 +38,19 @@ class ZetaStatusLabel extends ZetaStatelessWidget { @override Widget build(BuildContext context) { - final ZetaColorSwatch colors = status.colorSwatch(context); + final colors = Zeta.of(context).colors; + + final Color backgroundColor = status.backgroundColor(colors); + final Color borderColor = status.borderColor(colors); + final Color iconColor = status.foregroundColor(colors); + final Color textColor = colors.mainDefault; return Semantics( value: semanticLabel ?? label, child: DecoratedBox( decoration: BoxDecoration( - color: colors.shade10, - border: Border.all(color: colors.border), + color: backgroundColor, + border: Border.all(color: borderColor), borderRadius: context.rounded ? Zeta.of(context).radius.full : Zeta.of(context).radius.none, ), child: Padding( @@ -59,12 +64,12 @@ class ZetaStatusLabel extends ZetaStatelessWidget { Icon( customIcon ?? Icons.circle, size: customIcon != null ? Zeta.of(context).spacing.xl : Zeta.of(context).spacing.small, - color: colors.icon, + color: iconColor, ), SizedBox(width: Zeta.of(context).spacing.small), Text( label, - style: ZetaTextStyles.bodyMedium.apply(color: colors.shade10.onColor), + style: ZetaTextStyles.bodyMedium.apply(color: textColor), overflow: TextOverflow.ellipsis, ), ], @@ -85,3 +90,54 @@ class ZetaStatusLabel extends ZetaStatelessWidget { ..add(StringProperty('semanticLabel', semanticLabel)); } } + +/// Extensions on [ZetaWidgetStatus]. +extension on ZetaWidgetStatus { + /// Gets background color from [ZetaWidgetStatus]. + Color backgroundColor(ZetaColors colors) { + switch (this) { + case ZetaWidgetStatus.info: + return colors.surfaceInfoSubtle; + case ZetaWidgetStatus.positive: + return colors.surfacePositiveSubtle; + case ZetaWidgetStatus.warning: + return colors.surfaceWarningSubtle; + case ZetaWidgetStatus.negative: + return colors.surfaceNegativeSubtle; + case ZetaWidgetStatus.neutral: + return colors.mainLight; + } + } + + /// Gets foreground color from [ZetaWidgetStatus]. + Color foregroundColor(ZetaColors colors) { + switch (this) { + case ZetaWidgetStatus.info: + return colors.mainInfo; + case ZetaWidgetStatus.positive: + return colors.mainPositive; + case ZetaWidgetStatus.warning: + return colors.mainWarning; + case ZetaWidgetStatus.negative: + return colors.mainNegative; + case ZetaWidgetStatus.neutral: + return colors.mainSubtle; + } + } + + /// Gets border color from [ZetaWidgetStatus]. + Color borderColor(ZetaColors colors) { + switch (this) { + case ZetaWidgetStatus.info: + return colors.borderInfo; + case ZetaWidgetStatus.positive: + return colors.borderPositive; + case ZetaWidgetStatus.warning: + return colors.borderWarning; + case ZetaWidgetStatus.negative: + return colors.borderNegative; + case ZetaWidgetStatus.neutral: + return colors.borderDefault; + } + } +} diff --git a/lib/src/components/badges/tag.dart b/lib/src/components/badges/tag.dart index d0fd8238..c6ecea98 100644 --- a/lib/src/components/badges/tag.dart +++ b/lib/src/components/badges/tag.dart @@ -63,7 +63,7 @@ class ZetaTag extends ZetaStatelessWidget { if (direction == ZetaTagDirection.left) _buildCustomPaint(context), Container( decoration: BoxDecoration( - color: Zeta.of(context).colors.surfaceHover, + color: Zeta.of(context).colors.mainLight, borderRadius: _getBorderRadius(context), ), height: containerSize.height, @@ -101,7 +101,7 @@ class ZetaTag extends ZetaStatelessWidget { return CustomPaint( size: Size(Zeta.of(context).spacing.medium, Zeta.of(context).spacing.xl_3), painter: _TagPainter( - color: Zeta.of(context).colors.surfaceHover, + color: Zeta.of(context).colors.mainLight, direction: direction, rounded: context.rounded, ), diff --git a/lib/src/components/banner/banner.dart b/lib/src/components/banner/banner.dart index ab4c37f3..6f74dde4 100644 --- a/lib/src/components/banner/banner.dart +++ b/lib/src/components/banner/banner.dart @@ -3,14 +3,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import '../../../zeta_flutter.dart'; -/// [ZetaBanner] type. -@Deprecated('Use ZetaBannerStatus instead. ' 'This widget has been renamed as of 0.11.0') -typedef ZetaSystemBannerStatus = ZetaBannerStatus; - -/// Zeta Banner. Extends [MaterialBanner]. -@Deprecated('Use ZetaBanner instead. ' 'This widget has been renamed as of 0.11.0') -typedef ZetaSystemBanner = ZetaBanner; - /// [ZetaBanner] type enum ZetaBannerStatus { /// Primary background. @@ -69,7 +61,7 @@ class ZetaBanner extends MaterialBanner { content: Builder( builder: (context) { final backgroundColor = _backgroundColorFromType(context, type); - final foregroundColor = backgroundColor.onColor; + final foregroundColor = Zeta.of(context).colors.mainInverse; if (!kIsWeb && PlatformIs.android && context.mounted) { // ignore: invalid_use_of_visible_for_testing_member final statusBarColor = SystemChrome.latestStyle?.statusBarColor; @@ -115,7 +107,7 @@ class ZetaBanner extends MaterialBanner { child: Text( title, style: ZetaTextStyles.labelLarge.copyWith( - color: Zeta.of(context).colors.textInverse, + color: foregroundColor, ), ), ), @@ -123,7 +115,7 @@ class ZetaBanner extends MaterialBanner { Positioned( right: 0, child: IconTheme( - data: IconThemeData(color: _backgroundColorFromType(context, type).onColor), + data: IconThemeData(color: foregroundColor), child: trailing, ), ), @@ -143,13 +135,13 @@ class ZetaBanner extends MaterialBanner { switch (type) { case ZetaBannerStatus.primary: - return zeta.colors.primary; + return zeta.colors.primitives.primary; case ZetaBannerStatus.positive: - return zeta.colors.surfacePositive; + return zeta.colors.primitives.green; case ZetaBannerStatus.warning: - return zeta.colors.orange; + return zeta.colors.primitives.orange; case ZetaBannerStatus.negative: - return zeta.colors.surfaceNegative; + return zeta.colors.primitives.red; } } } diff --git a/lib/src/components/bottom sheets/bottom_sheet.dart b/lib/src/components/bottom sheets/bottom_sheet.dart index 7bd11867..fcde59a8 100644 --- a/lib/src/components/bottom sheets/bottom_sheet.dart +++ b/lib/src/components/bottom sheets/bottom_sheet.dart @@ -37,35 +37,37 @@ class ZetaBottomSheet extends ZetaStatelessWidget { @override Widget build(BuildContext context) { final colors = Zeta.of(context).colors; + final spacing = Zeta.of(context).spacing; + final radius = Zeta.of(context).radius; return ZetaRoundedScope( rounded: context.rounded, child: Container( padding: EdgeInsets.fromLTRB( - Zeta.of(context).spacing.xl, - Zeta.of(context).spacing.none, - Zeta.of(context).spacing.xl, - Zeta.of(context).spacing.xl, + spacing.xl, + spacing.none, + spacing.xl, + spacing.xl, ), decoration: BoxDecoration( - color: colors.surfaceSecondary, + color: colors.surfaceDefault, borderRadius: BorderRadius.only( - topLeft: Radius.circular(Zeta.of(context).spacing.xl_2), - topRight: Radius.circular(Zeta.of(context).spacing.xl_2), + topLeft: Radius.circular(spacing.xl_2), + topRight: Radius.circular(spacing.xl_2), ), ), child: Column( mainAxisSize: MainAxisSize.min, children: [ Align( - child: SizedBox( - height: Zeta.of(context).spacing.xl_5, - child: Padding( - padding: EdgeInsets.only(top: Zeta.of(context).spacing.small), - child: ZetaIcon( - Icons.maximize, - size: Zeta.of(context).spacing.xl_9, + child: Padding( + padding: EdgeInsets.only(top: spacing.small), + child: Container( + width: 40, + height: 4, + decoration: BoxDecoration( color: colors.surfaceDisabled, + borderRadius: radius.full, ), ), ), @@ -73,8 +75,8 @@ class ZetaBottomSheet extends ZetaStatelessWidget { if (title != null) Padding( padding: EdgeInsets.symmetric( - horizontal: Zeta.of(context).spacing.medium, - vertical: Zeta.of(context).spacing.xl_2, + horizontal: spacing.medium, + vertical: spacing.xl_2, ), child: Align( alignment: centerTitle ? Alignment.center : Alignment.centerLeft, @@ -85,7 +87,7 @@ class ZetaBottomSheet extends ZetaStatelessWidget { ), ), Material( - color: colors.surfaceSecondary, + color: colors.surfaceDefault, child: body ?? const Nothing(), ), ], diff --git a/lib/src/components/bottom sheets/menu_items.dart b/lib/src/components/bottom sheets/menu_items.dart index d433f0c3..4fa96e20 100644 --- a/lib/src/components/bottom sheets/menu_items.dart +++ b/lib/src/components/bottom sheets/menu_items.dart @@ -85,9 +85,10 @@ class ZetaMenuItem extends ZetaStatelessWidget { rounded: context.rounded, child: () { final colors = Zeta.of(context).colors; + final radius = Zeta.of(context).radius; final Widget text = DefaultTextStyle( - style: ZetaTextStyles.labelLarge.apply(color: _enabled ? colors.textDefault : colors.textDisabled), + style: ZetaTextStyles.labelLarge.apply(color: _enabled ? colors.mainDefault : colors.mainDisabled), child: label, ); @@ -96,6 +97,7 @@ class ZetaMenuItem extends ZetaStatelessWidget { return ConstrainedBox( constraints: BoxConstraints(minHeight: Zeta.of(context).spacing.xl_8), child: InkWell( + borderRadius: radius.rounded, onTap: _onTap, child: Padding( padding: EdgeInsets.symmetric( @@ -111,7 +113,10 @@ class ZetaMenuItem extends ZetaStatelessWidget { if (leading != null) Padding( padding: EdgeInsets.only(right: Zeta.of(context).spacing.small), - child: leading, + child: IconTheme( + data: _iconThemeData(colors, _enabled, Zeta.of(context).spacing.xl_2), + child: leading!, + ), ), Expanded(child: text), ], @@ -130,6 +135,7 @@ class ZetaMenuItem extends ZetaStatelessWidget { case ZetaMenuItemType.vertical: return InkWell( onTap: _onTap, + borderRadius: radius.rounded, child: Padding( padding: EdgeInsets.symmetric( horizontal: Zeta.of(context).spacing.large, @@ -156,7 +162,7 @@ class ZetaMenuItem extends ZetaStatelessWidget { } static IconThemeData _iconThemeData(ZetaColors colors, bool enabled, double size) => IconThemeData( - color: enabled ? colors.iconSubtle : colors.iconDisabled, + color: enabled ? colors.mainSubtle : colors.mainDisabled, size: size, ); diff --git a/lib/src/components/breadcrumb/breadcrumb.dart b/lib/src/components/breadcrumb/breadcrumb.dart index f52f6184..eb78c105 100644 --- a/lib/src/components/breadcrumb/breadcrumb.dart +++ b/lib/src/components/breadcrumb/breadcrumb.dart @@ -82,7 +82,7 @@ class _ZetaBreadcrumbsState extends State { ZetaIcons.chevron_right, size: Zeta.of(context).spacing.xl, rounded: rounded, - color: Zeta.of(context).colors.textSubtle, + color: Zeta.of(context).colors.mainSubtle, ), SizedBox(width: Zeta.of(context).spacing.small), ], @@ -221,10 +221,10 @@ class ZetaBreadcrumbItem extends ZetaStatelessWidget { /// Get color of breadcrumb based on state. Color getColor(Set states, ZetaColors colors) { if (states.contains(WidgetState.hovered)) { - return colors.blue; + return colors.primitives.blue; } - if (isSelected) return colors.black; - return colors.textSubtle; + if (isSelected) return colors.primitives.pure.shade1000; + return colors.mainSubtle; } @override @@ -302,18 +302,18 @@ class _TruncatedItemState extends State<_TruncatedItem> { return colors.surfaceHover; } if (states.contains(WidgetState.pressed)) { - return colors.primary.shade10; + return colors.surfaceSelected; } if (states.contains(WidgetState.disabled)) { return colors.surfaceDisabled; } - return colors.warm.shade10; + return colors.surfaceWarm; }), foregroundColor: WidgetStateProperty.resolveWith((states) { if (states.contains(WidgetState.disabled)) { - return colors.textDisabled; + return colors.mainDisabled; } - return colors.textDefault; + return colors.mainDefault; }), shape: WidgetStatePropertyAll( RoundedRectangleBorder( @@ -324,7 +324,7 @@ class _TruncatedItemState extends State<_TruncatedItem> { if (states.contains(WidgetState.focused)) { return BorderSide( width: ZetaBorders.medium, - color: colors.primary.shade100, + color: colors.borderPrimary, ); } if (states.isEmpty) { @@ -355,7 +355,7 @@ class _TruncatedItemState extends State<_TruncatedItem> { ZetaIcon( ZetaIcons.chevron_right, size: Zeta.of(context).spacing.xl, - color: Zeta.of(context).colors.textSubtle, + color: Zeta.of(context).colors.mainSubtle, ), SizedBox(width: Zeta.of(context).spacing.small), ], diff --git a/lib/src/components/button_group/button_group.dart b/lib/src/components/button_group/button_group.dart index 944d4ac5..b4facbef 100644 --- a/lib/src/components/button_group/button_group.dart +++ b/lib/src/components/button_group/button_group.dart @@ -241,11 +241,12 @@ class _ZetaGroupButtonState extends State { ZetaColors colors, bool finalButton, ) { + // TODO(UX-1200): Focus border does not work as expected. if (_controller.value.contains(WidgetState.focused)) { - return BorderSide(color: colors.blue.shade50, width: ZetaBorders.medium); + return BorderSide(color: colors.borderPrimary, width: ZetaBorders.medium); } if (_controller.value.contains(WidgetState.disabled)) { - return BorderSide(color: colors.cool.shade40); + return BorderSide(color: colors.borderDisabled); } return BorderSide( color: finalButton ? colors.borderDefault : colors.borderSubtle, @@ -293,6 +294,7 @@ class _ZetaGroupButtonState extends State { leadingIcon = IconTheme( data: IconThemeData( size: iconSize, + color: widget.isInverse ? colors.mainInverse : colors.mainDefault, ), child: selectedItem!.icon!, ); @@ -307,7 +309,7 @@ class _ZetaGroupButtonState extends State { left: borderSide, bottom: borderSide, right: _controller.value.contains(WidgetState.focused) - ? BorderSide(color: colors.blue.shade50, width: 2) + ? BorderSide(color: colors.borderPrimary, width: 2) : (widget.isFinal) ? borderSide : BorderSide.none, @@ -330,21 +332,21 @@ class _ZetaGroupButtonState extends State { return colors.surfaceDisabled; } if (states.contains(WidgetState.pressed)) { - return widget.isInverse ? colors.cool.shade100 : colors.primary.shade10; + return widget.isInverse ? colors.stateInverseSelected : colors.stateDefaultSelected; } if (states.contains(WidgetState.hovered)) { - return widget.isInverse ? colors.cool.shade90 : colors.cool.shade20; + return widget.isInverse ? colors.stateInverseHover : colors.surfaceHover; } - if (widget.isInverse) return colors.cool.shade100; + if (widget.isInverse) return colors.stateInverseEnabled; - return colors.surfacePrimary; + return colors.surfaceDefault; }), foregroundColor: WidgetStateProperty.resolveWith((states) { if (states.contains(WidgetState.disabled)) { - return colors.textDisabled; + return colors.mainDisabled; } - if (widget.isInverse) return colors.cool.shade100.onColor; - return colors.textDefault; + if (widget.isInverse) return colors.mainInverse; + return colors.mainDefault; }), elevation: WidgetStatePropertyAll(Zeta.of(context).spacing.none), padding: WidgetStateProperty.all(EdgeInsets.zero), diff --git a/lib/src/components/buttons/button.dart b/lib/src/components/buttons/button.dart index 63acbfb9..a32b954f 100644 --- a/lib/src/components/buttons/button.dart +++ b/lib/src/components/buttons/button.dart @@ -190,7 +190,6 @@ class ZetaButton extends ZetaStatelessWidget { context, borderType ?? (context.rounded ? ZetaWidgetBorder.rounded : ZetaWidgetBorder.sharp), type, - null, ), child: SelectionContainer.disabled( child: Row( @@ -252,7 +251,7 @@ class ZetaButton extends ZetaStatelessWidget { return Zeta.of(context).spacing.medium; case ZetaWidgetSize.small: - return Zeta.of(context).spacing.minimum; + return Zeta.of(context).spacing.small; } } diff --git a/lib/src/components/buttons/button_style.dart b/lib/src/components/buttons/button_style.dart index 03aeaa7e..029d3193 100644 --- a/lib/src/components/buttons/button_style.dart +++ b/lib/src/components/buttons/button_style.dart @@ -36,21 +36,57 @@ enum ZetaButtonType { /// Button utility functions for styling extension ButtonFunctions on ZetaButtonType { - /// Returns color based on [ZetaButtonType] - ZetaColorSwatch color(ZetaColors colors) { + /// Returns background color based on [ZetaButtonType] + Color backgroundColor(ZetaColors colors) { switch (this) { + case ZetaButtonType.primary: + return colors.statePrimaryEnabled; case ZetaButtonType.secondary: - return colors.secondary; + return colors.stateSecondaryEnabled; case ZetaButtonType.positive: - return colors.surfacePositive; + return colors.statePositiveEnabled; case ZetaButtonType.negative: - return colors.surfaceNegative; + return colors.stateNegativeEnabled; case ZetaButtonType.outline: + case ZetaButtonType.outlineSubtle: + case ZetaButtonType.text: + return colors.stateDefaultEnabled; + } + } + + /// Returns hover color based on [ZetaButtonType] + Color hoverColor(ZetaColors colors) { + switch (this) { case ZetaButtonType.primary: - return colors.primary; + return colors.statePrimaryHover; + case ZetaButtonType.secondary: + return colors.stateSecondaryHover; + case ZetaButtonType.positive: + return colors.statePositiveHover; + case ZetaButtonType.negative: + return colors.stateNegativeHover; + case ZetaButtonType.outline: case ZetaButtonType.outlineSubtle: case ZetaButtonType.text: - return colors.cool; + return colors.stateDefaultHover; + } + } + + /// Returns pressed color based on [ZetaButtonType] + Color pressedColor(ZetaColors colors) { + switch (this) { + case ZetaButtonType.primary: + return colors.statePrimarySelected; + case ZetaButtonType.secondary: + return colors.stateSecondarySelected; + case ZetaButtonType.positive: + return colors.statePositiveSelected; + case ZetaButtonType.negative: + return colors.stateNegativeSelected; + case ZetaButtonType.outline: + case ZetaButtonType.outlineSubtle: + case ZetaButtonType.text: + return colors.stateDefaultSelected; } } @@ -81,13 +117,11 @@ ButtonStyle buttonStyle( BuildContext context, ZetaWidgetBorder borderType, ZetaButtonType type, - Color? backgroundColor, ) { final ZetaColors colors = Zeta.of(context).colors; - final ZetaColorSwatch color = - backgroundColor != null ? ZetaColorSwatch.fromColor(backgroundColor) : type.color(colors); - - final bool isSolid = type.solid || backgroundColor != null; + final Color backgroundColor = type.backgroundColor(colors); + final Color backgroundColorHover = type.hoverColor(colors); + final Color backgroundColorPressed = type.pressedColor(colors); return ButtonStyle( minimumSize: WidgetStateProperty.all(Size.square(Zeta.of(context).spacing.xl_4)), @@ -97,34 +131,33 @@ ButtonStyle buttonStyle( backgroundColor: WidgetStateProperty.resolveWith( (states) { if (states.contains(WidgetState.disabled)) { - return colors.surfaceDisabled; + return colors.stateDisabledDisabled; } if (states.contains(WidgetState.pressed)) { - return isSolid ? color.shade70 : colors.primary.shade10; + return backgroundColorPressed; } if (states.contains(WidgetState.hovered)) { - return isSolid ? color.shade50 : colors.cool.shade20; + return backgroundColorHover; } - if (backgroundColor != null) return backgroundColor; - return isSolid ? color : colors.surfacePrimary; + return backgroundColor; }, ), foregroundColor: WidgetStateProperty.resolveWith( (states) { if (states.contains(WidgetState.disabled)) { - return colors.textDisabled; + return colors.mainDisabled; } switch (type) { case ZetaButtonType.outline: case ZetaButtonType.text: - return colors.primary; + return colors.mainPrimary; case ZetaButtonType.outlineSubtle: - return colors.textDefault; + return colors.mainDefault; case ZetaButtonType.primary: case ZetaButtonType.secondary: case ZetaButtonType.positive: case ZetaButtonType.negative: - return color.onColor; + return colors.mainInverse; } }, ), @@ -137,11 +170,11 @@ ButtonStyle buttonStyle( } // TODO(UX-1134): This removes a defualt border when focused, rather than adding a second border when focused. if (states.contains(WidgetState.focused)) { - return BorderSide(color: colors.blue, width: ZetaBorders.medium); + return BorderSide(color: colors.borderPrimary, width: ZetaBorders.medium); } if (type.border) { return BorderSide( - color: type == ZetaButtonType.outline ? colors.primary.border : colors.borderSubtle, + color: type == ZetaButtonType.outline ? colors.borderPrimaryMain : colors.borderSubtle, ); } diff --git a/lib/src/components/buttons/icon_button.dart b/lib/src/components/buttons/icon_button.dart index c0a2df3d..16ec30cd 100644 --- a/lib/src/components/buttons/icon_button.dart +++ b/lib/src/components/buttons/icon_button.dart @@ -133,7 +133,6 @@ class ZetaIconButton extends ZetaStatelessWidget { context, borderType ?? (context.rounded ? ZetaWidgetBorder.rounded : ZetaWidgetBorder.sharp), type, - null, ), child: SelectionContainer.disabled( child: ZetaIcon(icon, size: _iconSize(context)).paddingAll(_iconPadding(context)), diff --git a/lib/src/components/buttons/input_icon_button.dart b/lib/src/components/buttons/input_icon_button.dart index 4c6695a4..08fed6d0 100644 --- a/lib/src/components/buttons/input_icon_button.dart +++ b/lib/src/components/buttons/input_icon_button.dart @@ -66,7 +66,7 @@ class InputIconButton extends StatelessWidget { minHeight: iconSize * 2, minWidth: iconSize * 2, ), - color: !disabled ? color : colors.iconDisabled, + color: !disabled ? color : colors.mainDisabled, onPressed: disabled ? null : onTap, iconSize: iconSize, icon: ZetaIcon(icon), diff --git a/lib/src/components/chat_item/chat_item.dart b/lib/src/components/chat_item/chat_item.dart index 50746183..391ca631 100644 --- a/lib/src/components/chat_item/chat_item.dart +++ b/lib/src/components/chat_item/chat_item.dart @@ -176,7 +176,7 @@ class ZetaChatItem extends ZetaStatelessWidget { : actions, ), child: ColoredBox( - color: highlighted ? colors.blue.shade10 : colors.surfacePrimary, + color: highlighted ? colors.primitives.blue.shade10 : colors.surfaceDefault, child: Material( color: Colors.transparent, child: InkWell( @@ -205,7 +205,8 @@ class ZetaChatItem extends ZetaStatelessWidget { margin: EdgeInsets.only(right: Zeta.of(context).spacing.minimum), height: Zeta.of(context).spacing.small, width: Zeta.of(context).spacing.small, - decoration: BoxDecoration(color: colors.primary, shape: BoxShape.circle), + decoration: + BoxDecoration(color: colors.mainPrimary, shape: BoxShape.circle), ), Flexible( child: Row( @@ -243,7 +244,7 @@ class ZetaChatItem extends ZetaStatelessWidget { ), child: ZetaIcon( ZetaIcons.error, - color: colors.cool.shade70, + color: colors.primitives.cool.shade70, ), ), if (enabledWarningIcon) @@ -265,13 +266,13 @@ class ZetaChatItem extends ZetaStatelessWidget { horizontal: Zeta.of(context).spacing.small, ), decoration: BoxDecoration( - color: colors.primary, + color: colors.mainPrimary, borderRadius: Zeta.of(context).radius.full, ), child: Text( _count!, style: ZetaTextStyles.labelSmall.copyWith( - color: colors.textInverse, + color: colors.mainInverse, ), ), ), @@ -295,7 +296,7 @@ class ZetaChatItem extends ZetaStatelessWidget { maxLines: 2, overflow: TextOverflow.ellipsis, style: ZetaTextStyles.bodySmall.copyWith( - color: colors.textSubtle, + color: colors.mainSubtle, ), child: subtitle!, ), @@ -307,7 +308,7 @@ class ZetaChatItem extends ZetaStatelessWidget { ), child: ZetaIcon( starred! ? ZetaIcons.star : ZetaIcons.star_outline, - color: starred! ? colors.yellow.shade60 : null, + color: starred! ? colors.primitives.yellow.shade60 : null, ), ), ], @@ -359,15 +360,15 @@ extension on _ZetaSlidableActionType { final colors = Zeta.of(context).colors; switch (this) { case _ZetaSlidableActionType.menuMore: - return colors.purple; + return colors.primitives.purple; case _ZetaSlidableActionType.call: - return colors.green; + return colors.primitives.green; case _ZetaSlidableActionType.ptt: - return colors.blue; + return colors.primitives.blue; case _ZetaSlidableActionType.delete: - return colors.red; + return colors.primitives.red; case _ZetaSlidableActionType.custom: - return colors.primary; + return colors.primitives.primary; } } } @@ -379,15 +380,16 @@ class ZetaSlidableAction extends StatelessWidget { super.key, this.onPressed, required this.icon, - this.color = ZetaColorBase.blue, + this.color, this.customForegroundColor, this.customBackgroundColor, this.semanticLabel, this.paleColor = false, }) : _type = _ZetaSlidableActionType.custom, assert( - color != null || (customForegroundColor != null && customBackgroundColor != null), - 'Ensure either color, or both customForegroundColor and customBackgroundColor are provided.', + (customForegroundColor == null && customBackgroundColor == null) || + (customForegroundColor != null && customBackgroundColor != null), + 'Ensure both customForegroundColor and customBackgroundColor are either both null or both not null.', ); const ZetaSlidableAction._({ diff --git a/lib/src/components/checkbox/checkbox.dart b/lib/src/components/checkbox/checkbox.dart index 400820a2..1eec21c4 100644 --- a/lib/src/components/checkbox/checkbox.dart +++ b/lib/src/components/checkbox/checkbox.dart @@ -223,7 +223,7 @@ class _CheckboxState extends State { ? const Nothing() : ZetaIcon( widget.useIndeterminate ? ZetaIcons.remove : ZetaIcons.check_mark, - color: widget.disabled ? theme.colors.iconDisabled : theme.colors.white, + color: widget.disabled ? theme.colors.mainDisabled : theme.colors.mainInverse, size: 14, // TODO(UX-1202): ZetaSpacingBase ); @@ -239,7 +239,7 @@ class _CheckboxState extends State { BoxShadow( spreadRadius: 2, blurStyle: BlurStyle.solid, - color: theme.colors.blue.shade50, + color: theme.colors.borderPrimary, ), ], color: _getBackground(theme), @@ -262,12 +262,11 @@ class _CheckboxState extends State { } Color _getBackground(Zeta theme) { - final ZetaColorSwatch color = widget.error ? theme.colors.error : theme.colors.primary; if (widget.disabled) return theme.colors.surfaceDisabled; - if (!_checked) return theme.colors.surfacePrimary; - if (_isHovered) return theme.colors.borderHover; + if (!_checked) return theme.colors.surfaceDefault; + if (_isHovered) return theme.colors.mainDefault; - return color; + return theme.colors.mainPrimary; } Color _getBorderColor(Zeta theme) { @@ -275,9 +274,9 @@ class _CheckboxState extends State { return _getBackground(theme); } if (_isHovered) { - return theme.colors.cool.shade90; + return theme.colors.borderHover; } - return theme.colors.cool.shade70; + return theme.colors.mainSubtle; } } diff --git a/lib/src/components/chips/chip.dart b/lib/src/components/chips/chip.dart index b6cb8449..9b3ed550 100644 --- a/lib/src/components/chips/chip.dart +++ b/lib/src/components/chips/chip.dart @@ -191,12 +191,12 @@ class _ZetaChipState extends State { Color _foregroundColor(ZetaColors colors, bool disabled) { if (!disabled) { if (selected) { - return colors.textInverse; + return colors.mainInverse; } else { - return colors.textDefault; + return colors.mainDefault; } } else { - return colors.textDisabled; + return colors.mainDisabled; } } @@ -251,13 +251,13 @@ class _ZetaChipState extends State { if (states.contains(WidgetState.hovered)) { return colors.surfaceHover; } - return colors.surfacePrimary; + return colors.surfaceDefault; } }(), borderRadius: rounded ? Zeta.of(context).radius.full : Zeta.of(context).radius.none, border: Border.fromBorderSide( BorderSide( - color: _controller.value.contains(WidgetState.focused) ? colors.blue.shade50 : colors.borderDefault, + color: _controller.value.contains(WidgetState.focused) ? colors.borderPrimary : colors.borderDefault, width: _controller.value.contains(WidgetState.focused) ? ZetaBorders.medium : !selected @@ -276,7 +276,7 @@ class _ZetaChipState extends State { child: (selected ? ZetaIcon( ZetaIcons.check_mark, - color: disabled ? colors.iconDisabled : colors.iconInverse, + color: disabled ? colors.mainDisabled : colors.mainInverse, ) : const Nothing()), ) diff --git a/lib/src/components/chips/status_chip.dart b/lib/src/components/chips/status_chip.dart index cdd205dd..1e1b5f0a 100644 --- a/lib/src/components/chips/status_chip.dart +++ b/lib/src/components/chips/status_chip.dart @@ -109,7 +109,7 @@ class _Child extends StatelessWidget { child: Text( label, style: ZetaTextStyles.bodyXSmall.copyWith( - color: Zeta.of(context).colors.textDefault, + color: Zeta.of(context).colors.mainDefault, ), ), ); diff --git a/lib/src/components/comms_button/comms_button.dart b/lib/src/components/comms_button/comms_button.dart index 36ff0e4e..cfd4afdf 100644 --- a/lib/src/components/comms_button/comms_button.dart +++ b/lib/src/components/comms_button/comms_button.dart @@ -361,9 +361,9 @@ class _ZetaCommsButtonState extends State { case ZetaCommsButtonType.negative: return Zeta.of(context).colors.surfaceNegative; case ZetaCommsButtonType.off: - return Zeta.of(context).colors.textDefault; + return Zeta.of(context).colors.mainDefault; case ZetaCommsButtonType.on: - return Zeta.of(context).colors.textInverse; + return Zeta.of(context).colors.mainInverse; case ZetaCommsButtonType.warning: return Zeta.of(context).colors.surfaceDefault; } @@ -375,9 +375,9 @@ class _ZetaCommsButtonState extends State { case ZetaCommsButtonType.positive: case ZetaCommsButtonType.negative: case ZetaCommsButtonType.off: - return Zeta.of(context).colors.iconInverse; + return Zeta.of(context).colors.mainInverse; case ZetaCommsButtonType.on: - return Zeta.of(context).colors.iconDefault; + return Zeta.of(context).colors.mainDefault; case ZetaCommsButtonType.warning: return Zeta.of(context).colors.surfaceNegative; } diff --git a/lib/src/components/contact_item/contact_item.dart b/lib/src/components/contact_item/contact_item.dart index 3fcdc420..72f7dd05 100644 --- a/lib/src/components/contact_item/contact_item.dart +++ b/lib/src/components/contact_item/contact_item.dart @@ -49,7 +49,7 @@ class ZetaContactItem extends ZetaStatelessWidget { button: true, child: SelectionContainer.disabled( child: Material( - color: colors.surfacePrimary, + color: colors.surfaceDefault, child: DecoratedBox( decoration: BoxDecoration( border: enabledDivider ? Border(bottom: BorderSide(color: colors.borderDisabled)) : null, @@ -76,7 +76,7 @@ class ZetaContactItem extends ZetaStatelessWidget { children: [ DefaultTextStyle( style: ZetaTextStyles.bodyMedium.copyWith( - color: colors.textDefault, + color: colors.mainDefault, ), maxLines: 1, overflow: TextOverflow.ellipsis, @@ -84,7 +84,7 @@ class ZetaContactItem extends ZetaStatelessWidget { ), DefaultTextStyle( style: ZetaTextStyles.bodySmall.copyWith( - color: colors.textSubtle, + color: colors.mainSubtle, ), maxLines: 1, overflow: TextOverflow.ellipsis, diff --git a/lib/src/components/date_input/date_input.dart b/lib/src/components/date_input/date_input.dart index 88f45768..fabad949 100644 --- a/lib/src/components/date_input/date_input.dart +++ b/lib/src/components/date_input/date_input.dart @@ -70,7 +70,7 @@ class ZetaDateInput extends ZetaFormField { onTap: state.clear, disabled: disabled, size: size, - color: colors.iconSubtle, + color: colors.mainSubtle, semanticLabel: clearSemanticLabel, ), InputIconButton( @@ -78,7 +78,7 @@ class ZetaDateInput extends ZetaFormField { onTap: state.pickDate, disabled: disabled, size: size, - color: colors.iconDefault, + color: colors.mainDefault, semanticLabel: datePickerSemanticLabel, ), ], diff --git a/lib/src/components/dial_pad/dial_pad.dart b/lib/src/components/dial_pad/dial_pad.dart index 812ab478..992abaee 100644 --- a/lib/src/components/dial_pad/dial_pad.dart +++ b/lib/src/components/dial_pad/dial_pad.dart @@ -201,7 +201,7 @@ class ZetaDialPadButton extends StatelessWidget { height: Zeta.of(context).spacing.xl_9, decoration: ShapeDecoration( shape: const CircleBorder(), - color: colors.warm.shade10, + color: colors.surfaceWarm, shadows: [BoxShadow(color: Colors.black.withOpacity(0.15), blurRadius: 4, offset: const Offset(0, 2))], ), child: Material( diff --git a/lib/src/components/dialog/dialog.dart b/lib/src/components/dialog/dialog.dart index e5ac4f5e..c0db0391 100644 --- a/lib/src/components/dialog/dialog.dart +++ b/lib/src/components/dialog/dialog.dart @@ -105,7 +105,7 @@ class _ZetaDialog extends ZetaStatelessWidget { return ZetaRoundedScope( rounded: context.rounded, child: AlertDialog( - surfaceTintColor: zeta.colors.surfacePrimary, + surfaceTintColor: zeta.colors.surfaceDefault, insetPadding: EdgeInsets.symmetric( horizontal: Zeta.of(context).spacing.xl, vertical: Zeta.of(context).spacing.xl_2, @@ -143,7 +143,7 @@ class _ZetaDialog extends ZetaStatelessWidget { top: Zeta.of(context).spacing.xl_2, ), titleTextStyle: zetaTextTheme.headlineSmall?.copyWith( - color: zeta.colors.textDefault, + color: zeta.colors.mainDefault, ), content: Text(message), contentPadding: context.deviceType == DeviceType.mobilePortrait @@ -155,8 +155,8 @@ class _ZetaDialog extends ZetaStatelessWidget { bottom: Zeta.of(context).spacing.xl_2, ), contentTextStyle: context.deviceType == DeviceType.mobilePortrait - ? zetaTextTheme.bodySmall?.copyWith(color: zeta.colors.textDefault) - : zetaTextTheme.bodyMedium?.copyWith(color: zeta.colors.textDefault), + ? zetaTextTheme.bodySmall?.copyWith(color: zeta.colors.mainDefault) + : zetaTextTheme.bodyMedium?.copyWith(color: zeta.colors.mainDefault), actions: [ if (context.deviceType == DeviceType.mobilePortrait) Column( diff --git a/lib/src/components/dropdown/dropdown.dart b/lib/src/components/dropdown/dropdown.dart index a1f12a85..cf788bd1 100644 --- a/lib/src/components/dropdown/dropdown.dart +++ b/lib/src/components/dropdown/dropdown.dart @@ -496,7 +496,7 @@ class _DropdownItemState extends State<_DropdownItem> { Expanded( child: Text( widget.value.label, - style: ZetaTextStyles.bodyMedium.copyWith(color: colors.textDefault, height: 1.5), + style: ZetaTextStyles.bodyMedium.copyWith(color: colors.mainDefault, height: 1.5), ), ), ], @@ -526,7 +526,7 @@ class _DropdownItemState extends State<_DropdownItem> { }, ); case ZetaDropdownMenuType.standard: - return widget.value.icon ?? SizedBox(width: Zeta.of(context).spacing.xl_2); + return widget.value.icon ?? SizedBox(width: Zeta.of(context).spacing.xl); } } @@ -546,13 +546,13 @@ class _DropdownItemState extends State<_DropdownItem> { return colors.surfaceHover; } - return colors.surfacePrimary; + return colors.surfaceDefault; }), foregroundColor: WidgetStateProperty.resolveWith((states) { if (states.contains(WidgetState.disabled)) { - return colors.textDisabled; + return colors.mainDisabled; } - return colors.textDefault; + return colors.mainDefault; }), shape: WidgetStateProperty.all( RoundedRectangleBorder( diff --git a/lib/src/components/fabs/fab.dart b/lib/src/components/fabs/fab.dart index d8e554da..2fb14fb4 100644 --- a/lib/src/components/fabs/fab.dart +++ b/lib/src/components/fabs/fab.dart @@ -114,8 +114,11 @@ class ZetaFAB extends StatefulWidget { class _ZetaFABState extends State { @override Widget build(BuildContext context) { - final colors = widget.type.colors(context); - final backgroundColor = widget.type == ZetaFabType.inverse ? colors.shade80 : colors.shade60; + final colors = Zeta.of(context).colors; + final Color backgroundColor = widget.type.backgroundColor(colors); + final Color foregroundColor = widget.type.foregroundColor(colors); + final Color backgroundColorHover = widget.type.hoverColor(colors); + final Color backgroundColorSelected = widget.type.selectedColor(colors); return Column( mainAxisSize: MainAxisSize.min, @@ -130,13 +133,13 @@ class _ZetaFABState extends State { ), backgroundColor: WidgetStateProperty.resolveWith((states) { if (states.contains(WidgetState.disabled)) { - return Zeta.of(context).colors.surfaceDisabled; + return colors.stateDisabledDisabled; } if (states.contains(WidgetState.pressed)) { - return colors.selected; + return backgroundColorSelected; } if (states.contains(WidgetState.hovered)) { - return colors.hover; + return backgroundColorHover; } return backgroundColor; }), @@ -144,7 +147,7 @@ class _ZetaFABState extends State { (Set states) { if (states.contains(WidgetState.focused)) { // TODO(UX-1134): This removes a defualt border when focused, rather than adding a second border when focused. - return BorderSide(color: Zeta.of(context).colors.blue.shade50, width: ZetaBorders.medium); + return BorderSide(color: Zeta.of(context).colors.borderPrimary, width: ZetaBorders.medium); } return null; }, @@ -167,7 +170,7 @@ class _ZetaFABState extends State { size: widget.size.iconSize(context), color: widget.onPressed != null ? widget.type.iconColors(context) - : Zeta.of(context).colors.iconDisabled, + : Zeta.of(context).colors.mainDisabled, ), if (widget.expanded && widget.label != null) Row( @@ -175,7 +178,7 @@ class _ZetaFABState extends State { children: [ Text( widget.label!, - style: ZetaTextStyles.labelLarge, + style: ZetaTextStyles.labelLarge.apply(color: foregroundColor), ), ], ), @@ -201,15 +204,46 @@ class _ZetaFABState extends State { } extension on ZetaFabType { - ZetaColorSwatch colors(BuildContext context) { - final zetaColors = Zeta.of(context).colors; + Color backgroundColor(ZetaColors colors) { + switch (this) { + case ZetaFabType.primary: + return colors.statePrimaryEnabled; + case ZetaFabType.secondary: + return colors.stateSecondaryEnabled; + case ZetaFabType.inverse: + return colors.stateInverseEnabled; + } + } + + Color foregroundColor(ZetaColors colors) { + switch (this) { + case ZetaFabType.secondary: + return colors.mainDefault; + case ZetaFabType.primary: + case ZetaFabType.inverse: + return colors.mainInverse; + } + } + + Color hoverColor(ZetaColors colors) { + switch (this) { + case ZetaFabType.primary: + return colors.statePrimaryHover; + case ZetaFabType.secondary: + return colors.stateSecondaryHover; + case ZetaFabType.inverse: + return colors.stateInverseHover; + } + } + + Color selectedColor(ZetaColors colors) { switch (this) { case ZetaFabType.primary: - return zetaColors.primary; + return colors.statePrimarySelected; case ZetaFabType.secondary: - return zetaColors.secondary; + return colors.stateSecondarySelected; case ZetaFabType.inverse: - return zetaColors.cool; + return colors.stateInverseSelected; } } @@ -218,9 +252,9 @@ extension on ZetaFabType { switch (this) { case ZetaFabType.primary: case ZetaFabType.inverse: - return zetaColors.iconInverse; + return zetaColors.mainInverse; case ZetaFabType.secondary: - return zetaColors.iconDefault; + return zetaColors.mainDefault; } } } diff --git a/lib/src/components/global_header/global_header.dart b/lib/src/components/global_header/global_header.dart index f2362c2c..c34d3049 100644 --- a/lib/src/components/global_header/global_header.dart +++ b/lib/src/components/global_header/global_header.dart @@ -114,7 +114,7 @@ class _GlobalHeaderState extends State { vertical: Zeta.of(context).spacing.medium, horizontal: Zeta.of(context).spacing.large, ), - decoration: BoxDecoration(color: colors.surfacePrimary), + decoration: BoxDecoration(color: colors.surfaceDefault), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -205,11 +205,11 @@ class _GlobalHeaderState extends State { child.copyWith( active: _selectedIndex == index, dropdown: child.dropdown, - handlePress: () { + onTap: () { setState(() { _selectedIndex = index; }); - child.handlePress?.call(); + child.onTap?.call(); }, ), ); diff --git a/lib/src/components/global_header/header_tab_item.dart b/lib/src/components/global_header/header_tab_item.dart index cd04413e..0e0499fb 100644 --- a/lib/src/components/global_header/header_tab_item.dart +++ b/lib/src/components/global_header/header_tab_item.dart @@ -16,7 +16,7 @@ class ZetaGlobalHeaderItem extends ZetaStatefulWidget { super.rounded, this.dropdown, this.active, - this.handlePress, + this.onTap, required this.label, }); @@ -27,7 +27,7 @@ class ZetaGlobalHeaderItem extends ZetaStatefulWidget { final bool? active; /// Handle press of tab item - final VoidCallback? handlePress; + final VoidCallback? onTap; /// Content displayed on tab. final String label; @@ -39,13 +39,13 @@ class ZetaGlobalHeaderItem extends ZetaStatefulWidget { ZetaGlobalHeaderItem copyWith({ Widget? dropdown, bool? active, - VoidCallback? handlePress, + VoidCallback? onTap, String? label, }) { return ZetaGlobalHeaderItem( dropdown: dropdown ?? this.dropdown, active: active ?? this.active, - handlePress: handlePress ?? this.handlePress, + onTap: onTap ?? this.onTap, label: label ?? this.label, ); } @@ -55,7 +55,7 @@ class ZetaGlobalHeaderItem extends ZetaStatefulWidget { super.debugFillProperties(properties); properties ..add(DiagnosticsProperty('active', active)) - ..add(ObjectFlagProperty.has('handlePress', handlePress)) + ..add(ObjectFlagProperty.has('handlePress', onTap)) ..add(StringProperty('label', label)); } } @@ -64,15 +64,17 @@ class _ZetaGlobalHeaderItemState extends State { @override Widget build(BuildContext context) { final colors = Zeta.of(context).colors; + final radius = Zeta.of(context).radius; - final foregroundColor = widget.active! ? colors.primary : colors.textSubtle; + final foregroundColor = widget.active! ? colors.mainPrimary : colors.mainSubtle; return ZetaRoundedScope( rounded: context.rounded, child: Material( color: Colors.transparent, child: InkWell( - onTap: widget.handlePress, + onTap: widget.onTap, + borderRadius: context.rounded ? radius.rounded : radius.none, child: Row( children: [ Text(widget.label, style: TextStyle(color: foregroundColor)), diff --git a/lib/src/components/in_page_banner/in_page_banner.dart b/lib/src/components/in_page_banner/in_page_banner.dart index 6da34fa7..6993ad7d 100644 --- a/lib/src/components/in_page_banner/in_page_banner.dart +++ b/lib/src/components/in_page_banner/in_page_banner.dart @@ -47,16 +47,18 @@ class ZetaInPageBanner extends ZetaStatelessWidget { @override Widget build(BuildContext context) { final theme = Zeta.of(context); - final colors = status.colorSwatch(context); final hasTitle = title != null; final rounded = context.rounded; + final Color backgroundColor = status.backgroundColor(theme.colors); + final Color borderColor = status.borderColor(theme.colors); + final Color iconColor = status.foregroundColor(theme.colors); return ZetaRoundedScope( rounded: rounded, child: Container( decoration: BoxDecoration( - color: colors.surface, - border: Border.all(color: colors.border), + color: backgroundColor, + border: Border.all(color: borderColor), borderRadius: rounded ? Zeta.of(context).radius.minimal : Zeta.of(context).radius.none, ), padding: EdgeInsetsDirectional.only( @@ -77,7 +79,7 @@ class ZetaInPageBanner extends ZetaStatelessWidget { ZetaIcon( customIcon ?? status.icon, size: Zeta.of(context).spacing.xl, - color: status == ZetaWidgetStatus.neutral ? theme.colors.textDefault : colors.icon, + color: iconColor, ), SizedBox(width: Zeta.of(context).spacing.small), Expanded( @@ -90,7 +92,7 @@ class ZetaInPageBanner extends ZetaStatelessWidget { style: ZetaTextStyles.labelLarge.copyWith(height: 20 / 16), ).paddingBottom(Zeta.of(context).spacing.minimum), DefaultTextStyle( - style: ZetaTextStyles.bodySmall.apply(color: theme.colors.textDefault), + style: ZetaTextStyles.bodySmall.apply(color: theme.colors.mainDefault), child: content, ), if (actions.isNotEmpty) @@ -149,3 +151,54 @@ extension on ZetaWidgetStatus { } } } + +/// Extensions on [ZetaWidgetStatus]. +extension on ZetaWidgetStatus { + /// Gets background color from [ZetaWidgetStatus]. + Color backgroundColor(ZetaColors colors) { + switch (this) { + case ZetaWidgetStatus.info: + return colors.surfaceInfoSubtle; + case ZetaWidgetStatus.positive: + return colors.surfacePositiveSubtle; + case ZetaWidgetStatus.warning: + return colors.surfaceWarningSubtle; + case ZetaWidgetStatus.negative: + return colors.surfaceNegativeSubtle; + case ZetaWidgetStatus.neutral: + return colors.surfaceDefault; + } + } + + /// Gets foreground color from [ZetaWidgetStatus]. + Color foregroundColor(ZetaColors colors) { + switch (this) { + case ZetaWidgetStatus.info: + return colors.mainInfo; + case ZetaWidgetStatus.positive: + return colors.mainPositive; + case ZetaWidgetStatus.warning: + return colors.mainWarning; + case ZetaWidgetStatus.negative: + return colors.mainNegative; + case ZetaWidgetStatus.neutral: + return colors.mainDefault; + } + } + + /// Gets border color from [ZetaWidgetStatus]. + Color borderColor(ZetaColors colors) { + switch (this) { + case ZetaWidgetStatus.info: + return colors.borderInfo; + case ZetaWidgetStatus.positive: + return colors.borderPositive; + case ZetaWidgetStatus.warning: + return colors.borderWarning; + case ZetaWidgetStatus.negative: + return colors.borderNegative; + case ZetaWidgetStatus.neutral: + return colors.borderDefault; + } + } +} diff --git a/lib/src/components/list_item/dropdown_list_item.dart b/lib/src/components/list_item/dropdown_list_item.dart index 8b8d508e..1ec49467 100644 --- a/lib/src/components/list_item/dropdown_list_item.dart +++ b/lib/src/components/list_item/dropdown_list_item.dart @@ -172,7 +172,7 @@ class _ZetaDropdownListItemState extends State with Single duration: ZetaAnimationLength.fast, child: ZetaIcon( ZetaIcons.expand_more, - color: colors.iconSubtle, + color: colors.mainSubtle, ), ), onPressed: _onTap, diff --git a/lib/src/components/list_item/notification_list_item.dart b/lib/src/components/list_item/notification_list_item.dart index 61a36434..2a687839 100644 --- a/lib/src/components/list_item/notification_list_item.dart +++ b/lib/src/components/list_item/notification_list_item.dart @@ -159,7 +159,7 @@ class ZetaNotificationListItem extends ZetaStatelessWidget { children: [ if (!notificationRead) ZetaIndicator.icon( - color: ZetaColors().primary, + color: colors.mainPrimary, size: ZetaWidgetSize.small, ), SizedBox( @@ -178,7 +178,7 @@ class ZetaNotificationListItem extends ZetaStatelessWidget { Text( notificationTime!, style: ZetaTextStyles.bodySmall.apply( - color: colors.textDisabled, + color: colors.mainDisabled, ), ), if (showBellIcon ?? false) @@ -190,7 +190,7 @@ class ZetaNotificationListItem extends ZetaStatelessWidget { ), child: ZetaIcon( ZetaIcons.important_notification, - color: colors.white, + color: colors.mainInverse, size: Zeta.of(context).spacing.large, ), ), @@ -209,10 +209,10 @@ class ZetaNotificationListItem extends ZetaStatelessWidget { ZetaIcon( ZetaIcons.attachment, size: Zeta.of(context).spacing.medium, - color: colors.primary, + color: colors.mainPrimary, ), DefaultTextStyle( - style: ZetaTextStyles.bodyXSmall.apply(color: colors.primary), + style: ZetaTextStyles.bodyXSmall.apply(color: colors.mainPrimary), child: attachment!, ), ], @@ -239,12 +239,12 @@ class ZetaNotificationListItem extends ZetaStatelessWidget { final colors = Zeta.of(context).colors; return BoxDecoration( - color: notificationRead ? colors.surfacePrimary : colors.surfaceSelected, + color: notificationRead ? colors.surfaceDefault : colors.surfaceSelected, borderRadius: Zeta.of(context).radius.rounded, boxShadow: (showDivider ?? false) ? [ BoxShadow( - color: colors.primary, + color: colors.mainPrimary, offset: Offset(0, Zeta.of(context).spacing.minimum), ), ] diff --git a/lib/src/components/navigation bar/navigation_bar.dart b/lib/src/components/navigation bar/navigation_bar.dart index e8f16866..108f8020 100644 --- a/lib/src/components/navigation bar/navigation_bar.dart +++ b/lib/src/components/navigation bar/navigation_bar.dart @@ -188,7 +188,7 @@ class ZetaNavigationBar extends ZetaStatelessWidget { return Container( padding: EdgeInsets.symmetric(horizontal: Zeta.of(context).spacing.large), decoration: BoxDecoration( - color: colors.surfacePrimary, + color: colors.surfaceDefault, border: Border(top: BorderSide(color: colors.borderSubtle)), ), child: Semantics(child: useSafeArea ? SafeArea(child: child) : child), @@ -262,10 +262,10 @@ class NavigationItem extends ZetaStatelessWidget { @override Widget build(BuildContext context) { final colors = Zeta.of(context).colors; - final elementColor = selected ? colors.primary : colors.textSubtle; + final elementColor = selected ? colors.surfacePrimary : colors.mainSubtle; return Material( - color: colors.surfacePrimary, + color: colors.surfaceDefault, child: InkResponse( borderRadius: context.rounded ? Zeta.of(context).radius.rounded : Zeta.of(context).radius.none, onTap: onTap, diff --git a/lib/src/components/navigation_rail/navigation_rail.dart b/lib/src/components/navigation_rail/navigation_rail.dart index ce65619a..6b7834cc 100644 --- a/lib/src/components/navigation_rail/navigation_rail.dart +++ b/lib/src/components/navigation_rail/navigation_rail.dart @@ -191,11 +191,11 @@ class _ZetaNavigationRailItemContentState extends State<_ZetaNavigationRailItemC color: widget.disabled ? null : widget.selected - ? zeta.colors.blue.shade10 + ? zeta.colors.stateDefaultSelected : _hovered ? zeta.colors.surfaceHover : null, - border: _focused ? Border.all(color: zeta.colors.blue, width: 2) : null, + border: _focused ? Border.all(color: zeta.colors.borderPrimary, width: 2) : null, borderRadius: context.rounded ? Zeta.of(context).radius.rounded : null, ), child: ConstrainedBox( @@ -217,10 +217,10 @@ class _ZetaNavigationRailItemContentState extends State<_ZetaNavigationRailItemC IconTheme( data: IconThemeData( color: widget.disabled - ? zeta.colors.cool.shade50 + ? zeta.colors.mainDisabled : widget.selected || _hovered - ? zeta.colors.textDefault - : zeta.colors.cool.shade70, + ? zeta.colors.mainDefault + : zeta.colors.mainSubtle, size: Zeta.of(context).spacing.xl_2, ), child: widget.icon!, @@ -230,10 +230,10 @@ class _ZetaNavigationRailItemContentState extends State<_ZetaNavigationRailItemC textAlign: TextAlign.center, style: ZetaTextStyles.titleSmall.copyWith( color: widget.disabled - ? zeta.colors.cool.shade50 + ? zeta.colors.mainDisabled : widget.selected || _hovered - ? zeta.colors.textDefault - : zeta.colors.cool.shade70, + ? zeta.colors.mainDefault + : zeta.colors.mainSubtle, ), ), ], diff --git a/lib/src/components/pagination/pagination.dart b/lib/src/components/pagination/pagination.dart index b2edf86d..872fdcc3 100644 --- a/lib/src/components/pagination/pagination.dart +++ b/lib/src/components/pagination/pagination.dart @@ -231,7 +231,9 @@ class _ZetaPaginationState extends State { value: _currentPage, icon: const ZetaIcon(ZetaIcons.expand_more).paddingStart(Zeta.of(context).spacing.small), underline: const Nothing(), - style: Theme.of(context).textTheme.bodyLarge?.copyWith(color: colors.textSubtle), + style: Theme.of(context).textTheme.bodyLarge?.copyWith( + color: colors.mainSubtle, + ), padding: EdgeInsets.symmetric( horizontal: Zeta.of(context).spacing.medium, ), @@ -320,16 +322,16 @@ class _PaginationItem extends ZetaStatelessWidget { maxLines: 1, style: Theme.of(context).textTheme.bodyMedium?.copyWith( color: disabled - ? colors.textDisabled + ? colors.mainDisabled : selected - ? colors.textInverse - : colors.textDefault, + ? colors.mainInverse + : colors.mainDefault, ), ); } else if (icon != null) { child = ZetaIcon( icon, - color: disabled ? colors.textDisabled : colors.textDefault, + color: disabled ? colors.mainDisabled : colors.mainDefault, semanticLabel: semanticLabel, ); } @@ -349,15 +351,14 @@ class _PaginationItem extends ZetaStatelessWidget { child: Material( borderRadius: rounded ? Zeta.of(context).radius.minimal : Zeta.of(context).radius.none, color: disabled - ? colors.surfaceDisabled + ? colors.stateDisabledDisabled : selected - ? colors.cool[100] - : colors.surfacePrimary, + ? colors.stateInverseSelected + : colors.stateDefaultEnabled, child: InkWell( onTap: disabled ? null : onPressed, borderRadius: rounded ? Zeta.of(context).radius.minimal : Zeta.of(context).radius.none, - highlightColor: selected ? colors.cool[100] : colors.surfaceSelected, - hoverColor: selected ? colors.cool[100] : colors.surfaceHover, + hoverColor: selected ? colors.stateInverseHover : colors.stateDefaultHover, enableFeedback: false, child: Container( alignment: Alignment.center, diff --git a/lib/src/components/phone_input/phone_input.dart b/lib/src/components/phone_input/phone_input.dart index f4fa2773..8dff36ad 100644 --- a/lib/src/components/phone_input/phone_input.dart +++ b/lib/src/components/phone_input/phone_input.dart @@ -132,7 +132,7 @@ class ZetaPhoneInput extends ZetaFormField { ), ZetaIcon( !dropdowncontroller.isOpen ? ZetaIcons.expand_more : ZetaIcons.expand_less, - color: !disabled ? colors.iconDefault : colors.iconDisabled, + color: !disabled ? colors.mainDefault : colors.mainDisabled, size: Zeta.of(context).spacing.xl, ), ], diff --git a/lib/src/components/progress/progress_bar.dart b/lib/src/components/progress/progress_bar.dart index 4a0cc22b..1b533a97 100644 --- a/lib/src/components/progress/progress_bar.dart +++ b/lib/src/components/progress/progress_bar.dart @@ -29,7 +29,7 @@ class ZetaProgressBar extends ZetaProgress { super.key, super.rounded, required super.progress, - required this.type, + this.type = ZetaProgressBarType.standard, this.isThin = false, this.label, }); diff --git a/lib/src/components/progress/progress_circle.dart b/lib/src/components/progress/progress_circle.dart index 6847e401..b9f025e0 100644 --- a/lib/src/components/progress/progress_circle.dart +++ b/lib/src/components/progress/progress_circle.dart @@ -98,14 +98,15 @@ class _ZetaProgressCircleState extends ZetaProgressState { textVal, style: _getTextSize(), ); + final size = _getSize(context); return ConstrainedBox( - constraints: BoxConstraints.tight(_getSize()), + constraints: BoxConstraints.tight(size), child: AnimatedBuilder( animation: controller, builder: (_, child) { return CustomPaint( - size: _getSize(), + size: size, painter: _CirclePainter( progress: animation.value, rounded: context.rounded, @@ -159,7 +160,7 @@ class _ZetaProgressCircleState extends ZetaProgressState { ); } - Size _getSize() { + Size _getSize(BuildContext context) { switch (widget.size) { case ZetaCircleSizes.xs: return Size(Zeta.of(context).spacing.xl_2, Zeta.of(context).spacing.xl_2); @@ -230,7 +231,7 @@ class _CirclePainter extends CustomPainter { _paint ..strokeWidth = Zeta.of(context).spacing.minimum ..style = PaintingStyle.stroke - ..color = Zeta.of(context).colors.primary; + ..color = Zeta.of(context).colors.mainPrimary; const double fullCircle = 2 * math.pi; diff --git a/lib/src/components/radio/radio.dart b/lib/src/components/radio/radio.dart index 472bbe8a..75cde7d9 100644 --- a/lib/src/components/radio/radio.dart +++ b/lib/src/components/radio/radio.dart @@ -86,23 +86,23 @@ class _ZetaRadioState extends State> with TickerProviderStateMix ..inactiveReactionColor = Colors.transparent ..reactionColor = Colors.transparent ..hoverColor = Colors.transparent - ..focusColor = zetaColors.blue.shade50 + ..focusColor = zetaColors.mainPrimary ..splashRadius = Zeta.of(context).spacing.medium ..downPosition = downPosition ..isFocused = states.contains(WidgetState.focused) ..isHovered = states.contains(WidgetState.hovered) ..activeColor = states.contains(WidgetState.hovered) - ? zetaColors.cool.shade90 + ? zetaColors.borderHover : states.contains(WidgetState.disabled) - ? zetaColors.cool.shade30 - : zetaColors.blue.shade60 + ? zetaColors.surfaceDisabled + : zetaColors.mainPrimary ..inactiveColor = states.contains(WidgetState.hovered) - ? zetaColors.cool.shade90 + ? zetaColors.borderHover : states.contains(WidgetState.disabled) - ? zetaColors.cool.shade30 + ? zetaColors.mainDisabled : states.contains(WidgetState.focused) - ? zetaColors.blue.shade50 - : zetaColors.cool.shade70, + ? zetaColors.borderPrimary + : zetaColors.mainSubtle, mouseCursor: WidgetStateProperty.all( states.contains(WidgetState.disabled) ? SystemMouseCursors.forbidden : SystemMouseCursors.click, ), @@ -111,7 +111,7 @@ class _ZetaRadioState extends State> with TickerProviderStateMix DefaultTextStyle( style: ZetaTextStyles.bodyMedium.copyWith( color: - states.contains(WidgetState.disabled) ? zetaColors.textDisabled : zetaColors.textDefault, + states.contains(WidgetState.disabled) ? zetaColors.mainDisabled : zetaColors.mainDefault, height: 4 / 3, ), child: widget.label!, @@ -184,7 +184,7 @@ class _RadioPainter extends ToggleablePainter { // Outer circle paint ..color = isHovered - ? colors.black + ? colors.borderHover : position.isDismissed ? inactiveColor : activeColor diff --git a/lib/src/components/range_selector/range_selector.dart b/lib/src/components/range_selector/range_selector.dart index de14fe8e..4765a88a 100644 --- a/lib/src/components/range_selector/range_selector.dart +++ b/lib/src/components/range_selector/range_selector.dart @@ -108,9 +108,9 @@ class _ZetaRangeSelectorState extends State { Color get _activeColor { final colors = Zeta.of(context).colors; if (widget.onChange == null) { - return colors.textDisabled; + return colors.mainDisabled; } - return _selected ? colors.primary : colors.surfaceDefaultInverse; + return _selected ? colors.mainPrimary : colors.surfaceDefaultInverse; } void _onSubmit(TextEditingController controller, {bool lower = true}) { @@ -181,7 +181,7 @@ class _ZetaRangeSelectorState extends State { Text( widget.label!, style: ZetaTextStyles.bodySmall.copyWith( - color: disabled ? colors.textDisabled : colors.textDefault, + color: disabled ? colors.mainDisabled : colors.mainDefault, ), ), Row( @@ -289,7 +289,7 @@ class _ValueField extends StatelessWidget { return Zeta.of(context).colors; } - ZetaSpacingSemantics get _spacing { + ZetaSpacing get _spacing { return Zeta.of(context).spacing; } @@ -332,7 +332,7 @@ class _ValueField extends StatelessWidget { textAlign: TextAlign.center, inputFormatters: [FilteringTextInputFormatter.digitsOnly], style: Theme.of(context).textTheme.bodyMedium?.copyWith( - color: disabled ? _colors.textDisabled : _colors.textSubtle, + color: disabled ? _colors.mainDisabled : _colors.mainSubtle, ), decoration: _inputDecoration, ), diff --git a/lib/src/components/search_bar/search_bar.dart b/lib/src/components/search_bar/search_bar.dart index fc536ede..8735983a 100644 --- a/lib/src/components/search_bar/search_bar.dart +++ b/lib/src/components/search_bar/search_bar.dart @@ -82,7 +82,7 @@ class ZetaSearchBar extends ZetaTextFormField { onChange: state.onChange, prefix: ZetaIcon( ZetaIcons.search, - color: !disabled ? zeta.colors.iconSubtle : zeta.colors.iconDisabled, + color: !disabled ? zeta.colors.mainSubtle : zeta.colors.mainDisabled, size: iconSize, ), suffix: Row( @@ -95,14 +95,14 @@ class ZetaSearchBar extends ZetaTextFormField { disabled: disabled, size: size, semanticLabel: clearSemanticLabel, - color: zeta.colors.iconSubtle, + color: zeta.colors.mainSubtle, key: const ValueKey('search-clear-btn'), ), if (showSpeechToText) SizedBox( height: iconSize, child: VerticalDivider( - color: zeta.colors.cool.shade40, + color: zeta.colors.mainSubtle, width: 5, thickness: 1, ), @@ -116,7 +116,7 @@ class ZetaSearchBar extends ZetaTextFormField { disabled: disabled, semanticLabel: microphoneSemanticLabel, size: size, - color: zeta.colors.iconDefault, + color: zeta.colors.mainDefault, ), ], ), diff --git a/lib/src/components/segmented_control/segmented_control.dart b/lib/src/components/segmented_control/segmented_control.dart index bdb6734f..24355f12 100644 --- a/lib/src/components/segmented_control/segmented_control.dart +++ b/lib/src/components/segmented_control/segmented_control.dart @@ -152,7 +152,7 @@ class _ZetaSegmentedControlState extends State> builder: (BuildContext context, Widget? child) { return _SegmentedControlRenderWidget( highlightedIndex: highlightedIndex, - thumbColor: colors.surfacePrimary, + thumbColor: colors.surfaceDefault, thumbScale: _thumbScaleAnimation.value, rounded: rounded, state: this, @@ -232,7 +232,7 @@ class _SegmentState extends State<_Segment> with TickerProviderStateMixin< data: IconThemeData(size: Zeta.of(context).spacing.xl), child: DefaultTextStyle( style: ZetaTextStyles.labelMedium.copyWith( - color: colors.textDefault, + color: colors.mainDefault, ), child: Padding( padding: EdgeInsets.symmetric( diff --git a/lib/src/components/select_input/select_input.dart b/lib/src/components/select_input/select_input.dart index f2c18f3c..df9401bf 100644 --- a/lib/src/components/select_input/select_input.dart +++ b/lib/src/components/select_input/select_input.dart @@ -74,7 +74,7 @@ class ZetaSelectInput extends ZetaFormField { icon: controller.isOpen ? ZetaIcons.expand_less : ZetaIcons.expand_more, disabled: disabled, size: size, - color: colors.iconSubtle, + color: colors.mainSubtle, onTap: () => state.onIconTapped(controller), ), ); diff --git a/lib/src/components/slider/slider.dart b/lib/src/components/slider/slider.dart index 954a0cbc..9df25cb1 100644 --- a/lib/src/components/slider/slider.dart +++ b/lib/src/components/slider/slider.dart @@ -126,7 +126,7 @@ class _ZetaSliderState extends State { if (widget.onChange == null) { return colors.surfaceDisabled; } - return _selected ? colors.primary : colors.surfaceDefaultInverse; + return _selected ? colors.mainPrimary : colors.surfaceDefaultInverse; } } diff --git a/lib/src/components/snack_bar/snack_bar.dart b/lib/src/components/snack_bar/snack_bar.dart index 1815cb2f..82fbf86e 100644 --- a/lib/src/components/snack_bar/snack_bar.dart +++ b/lib/src/components/snack_bar/snack_bar.dart @@ -136,12 +136,12 @@ class ZetaSnackBar extends SnackBar { final colors = Zeta.of(context).colors; return switch (type) { - ZetaSnackBarType.positive => colors.green.shade10, - ZetaSnackBarType.info => colors.purple.shade10, - ZetaSnackBarType.warning => colors.orange.shade10, - ZetaSnackBarType.deletion || ZetaSnackBarType.error => colors.red.shade10, - ZetaSnackBarType.view => colors.blue.shade10, - _ => colors.warm.shade100, + ZetaSnackBarType.positive => colors.surfacePositiveSubtle, + ZetaSnackBarType.info => colors.surfaceInfoSubtle, + ZetaSnackBarType.warning => colors.surfaceWarningSubtle, + ZetaSnackBarType.deletion || ZetaSnackBarType.error => colors.surfaceNegativeSubtle, + ZetaSnackBarType.view => colors.surfacePrimarySubtle, + _ => colors.surfaceDefaultInverse, }; } } @@ -171,8 +171,8 @@ class _Content extends StatelessWidget { ZetaSnackBarType.deletion || ZetaSnackBarType.error || ZetaSnackBarType.view => - colors.textDefault, - _ => colors.textInverse, + colors.mainDefault, + _ => colors.mainInverse, }; } @@ -241,7 +241,7 @@ class _Action extends StatelessWidget { return switch (type) { ZetaSnackBarType.defaultType => _IconButton( onPressed: () => ScaffoldMessenger.of(context).removeCurrentSnackBar(), - color: colors.iconInverse, + color: colors.surfaceDefaultInverse, ), ZetaSnackBarType.action => _ActionButton( onPressed: onPressed, @@ -254,22 +254,22 @@ class _Action extends StatelessWidget { ZetaSnackBarType.error => _IconButton( onPressed: () => ScaffoldMessenger.of(context).removeCurrentSnackBar(), - color: colors.cool.shade90, + color: colors.mainDefault, ), ZetaSnackBarType.deletion => _ActionButton( onPressed: onPressed, label: label, - color: colors.cool.shade90, + color: colors.mainDefault, ), ZetaSnackBarType.view => _ActionButton( onPressed: onPressed, label: label, - color: colors.cool.shade90, + color: colors.mainDefault, ), _ => _ActionButton( onPressed: onPressed, label: label, - color: colors.blue.shade50, + color: colors.borderPrimaryMain, ), }; }(), @@ -376,8 +376,8 @@ class _LeadingIcon extends StatelessWidget { ZetaSnackBarType.info => colors.surfaceInfo, ZetaSnackBarType.warning => colors.surfaceWarning, ZetaSnackBarType.error || ZetaSnackBarType.deletion => colors.surfaceNegative, - ZetaSnackBarType.view => colors.primary, - _ => colors.iconInverse, + ZetaSnackBarType.view => colors.mainPrimary, + _ => colors.mainInverse, }; } diff --git a/lib/src/components/stepper/stepper.dart b/lib/src/components/stepper/stepper.dart index 069f8307..c6bf2670 100644 --- a/lib/src/components/stepper/stepper.dart +++ b/lib/src/components/stepper/stepper.dart @@ -148,10 +148,10 @@ class _ZetaStepperState extends State with TickerProviderStateMixin Color _getElementColor(BuildContext context, bool disabled, bool completed) { final colors = Zeta.of(context).colors; - Color boxColor = colors.primary; + Color boxColor = colors.mainPrimary; if (disabled) { - boxColor = colors.iconDisabled; + boxColor = colors.mainDisabled; } else if (completed) { boxColor = colors.surfacePositive; } @@ -206,12 +206,12 @@ class StepIcon extends StatelessWidget { child: completed && !disabled ? ZetaIcon( ZetaIcons.check_mark, - color: colors.textInverse, + color: colors.mainInverse, ) : Text( (index + 1).toString(), style: ZetaTextStyles.labelLarge.copyWith( - color: colors.textInverse, + color: colors.mainInverse, ), ), ), @@ -357,7 +357,7 @@ class HorizontalStep extends StatelessWidget { ), DefaultTextStyle( style: ZetaTextStyles.bodySmall.copyWith( - color: step.disabled ? colors.textDisabled : colors.textDefault, + color: step.disabled ? colors.mainDisabled : colors.mainDefault, ), child: step.title, ), @@ -460,7 +460,7 @@ class VerticalStep extends StatelessWidget { ), DefaultTextStyle( style: ZetaTextStyles.titleLarge.copyWith( - color: step.disabled ? colors.textDisabled : colors.textDefault, + color: step.disabled ? colors.mainDisabled : colors.mainDefault, ), maxLines: 1, child: step.title, diff --git a/lib/src/components/stepper_input/stepper_input.dart b/lib/src/components/stepper_input/stepper_input.dart index b05907c4..34e7e843 100644 --- a/lib/src/components/stepper_input/stepper_input.dart +++ b/lib/src/components/stepper_input/stepper_input.dart @@ -201,7 +201,7 @@ class ZetaStepperInputState extends State { textAlign: TextAlign.center, inputFormatters: [FilteringTextInputFormatter.digitsOnly], style: Theme.of(context).textTheme.bodyMedium?.copyWith( - color: disabled ? colors.textDisabled : null, + color: disabled ? colors.mainDisabled : null, ), onTapOutside: (_) { if (_controller.text.isEmpty) { diff --git a/lib/src/components/switch/zeta_switch.dart b/lib/src/components/switch/zeta_switch.dart index 6902298f..76d2433a 100644 --- a/lib/src/components/switch/zeta_switch.dart +++ b/lib/src/components/switch/zeta_switch.dart @@ -88,13 +88,15 @@ class ZetaSwitch extends StatelessWidget { trackOutlineColor: const WidgetStatePropertyAll(Colors.transparent), trackColor: WidgetStateProperty.resolveWith((states) { if (states.contains(WidgetState.disabled)) { - return zetaColors.cool.shade30; + return zetaColors.surfaceDisabled; + } else if (states.contains(WidgetState.selected)) { + return zetaColors.mainPrimary; } else { - return states.contains(WidgetState.selected) ? zetaColors.primary : zetaColors.cool.shade50; + return zetaColors.mainDisabled; } }), thumbColor: WidgetStateProperty.resolveWith( - (states) => states.contains(WidgetState.disabled) ? zetaColors.cool.shade50 : zetaColors.cool.shade20, + (states) => states.contains(WidgetState.disabled) ? zetaColors.mainDisabled : zetaColors.mainInverse, ), value: value ?? false, onChanged: onChanged, diff --git a/lib/src/components/tabs/tab_bar.dart b/lib/src/components/tabs/tab_bar.dart index facb2055..01bf4fc6 100644 --- a/lib/src/components/tabs/tab_bar.dart +++ b/lib/src/components/tabs/tab_bar.dart @@ -13,7 +13,6 @@ class ZetaTabBar extends TabBar { required BuildContext context, required List super.tabs, TabAlignment super.tabAlignment = TabAlignment.center, - @Deprecated('Use disabled instead. ' 'enabled is deprecated as of 0.11.0') bool enabled = true, super.isScrollable, super.enableFeedback, super.dragStartBehavior, @@ -25,17 +24,18 @@ class ZetaTabBar extends TabBar { labelPadding: isScrollable ? null : EdgeInsets.zero, indicator: UnderlineTabIndicator( borderSide: BorderSide( - color: Zeta.of(context).colors.primary, + color: Zeta.of(context).colors.mainPrimary, width: onTap != null ? Zeta.of(context).spacing.minimum : Zeta.of(context).spacing.none, ), borderRadius: Zeta.of(context).radius.none, ), splashFactory: null, labelStyle: ZetaTextStyles.labelLarge.copyWith( - color: onTap != null ? Zeta.of(context).colors.textDefault : Zeta.of(context).colors.textDisabled, + color: onTap != null ? Zeta.of(context).colors.mainDefault : Zeta.of(context).colors.mainDisabled, ), unselectedLabelStyle: ZetaTextStyles.labelLarge.copyWith( - color: onTap != null ? Zeta.of(context).colors.textSubtle : Zeta.of(context).colors.textDisabled, + color: onTap != null ? Zeta.of(context).colors.mainSubtle : Zeta.of(context).colors.mainDisabled, ), + dividerColor: Colors.transparent, ); } diff --git a/lib/src/components/text_input/hint_text.dart b/lib/src/components/text_input/hint_text.dart index 3631b507..d7596725 100644 --- a/lib/src/components/text_input/hint_text.dart +++ b/lib/src/components/text_input/hint_text.dart @@ -30,12 +30,12 @@ class ZetaHintText extends ZetaStatelessWidget { final text = error && !disabled ? errorText : hintText; - Color elementColor = colors.textSubtle; + Color elementColor = colors.mainSubtle; if (disabled) { - elementColor = colors.textDisabled; + elementColor = colors.mainDisabled; } else if (error) { - elementColor = colors.error; + elementColor = colors.mainNegative; } if (text == null || text.isEmpty) { diff --git a/lib/src/components/text_input/input_label.dart b/lib/src/components/text_input/input_label.dart index 6e08b575..79e62a58 100644 --- a/lib/src/components/text_input/input_label.dart +++ b/lib/src/components/text_input/input_label.dart @@ -35,13 +35,13 @@ class ZetaInputLabel extends ZetaStatelessWidget { if (requirementLevel == ZetaFormFieldRequirement.optional) { requirementWidget = Text( '(optional)', // TODO(UX-1003): needs localizing. - style: textStyle.copyWith(color: disabled ? colors.textDisabled : colors.textSubtle), + style: textStyle.copyWith(color: disabled ? colors.mainDisabled : colors.mainSubtle), ); } else if (requirementLevel == ZetaFormFieldRequirement.mandatory) { requirementWidget = Text( '*', style: ZetaTextStyles.labelIndicator.copyWith( - color: disabled ? colors.textDisabled : colors.error, // TODO(mikecoomber): change to textNegative when added + color: disabled ? colors.mainDisabled : colors.mainNegative, ), ); } @@ -51,7 +51,7 @@ class ZetaInputLabel extends ZetaStatelessWidget { Text( label, style: textStyle.copyWith( - color: disabled ? colors.textDisabled : colors.textDefault, + color: disabled ? colors.mainDisabled : colors.mainDefault, ), ), if (requirementWidget != null) requirementWidget.paddingStart(Zeta.of(context).spacing.minimum), diff --git a/lib/src/components/text_input/internal_text_input.dart b/lib/src/components/text_input/internal_text_input.dart index 2c20bba0..00a1ff88 100644 --- a/lib/src/components/text_input/internal_text_input.dart +++ b/lib/src/components/text_input/internal_text_input.dart @@ -183,9 +183,9 @@ class InternalTextInputState extends State { return _colors.surfaceDisabled; } if (widget.errorText != null) { - return _colors.error.shade10; + return _colors.surfaceNegativeSubtle; } - return _colors.surfacePrimary; + return _colors.surfaceDefault; } TextStyle get _baseTextStyle { @@ -213,9 +213,9 @@ class InternalTextInputState extends State { } TextStyle get _affixStyle { - Color color = _colors.textSubtle; + Color color = _colors.mainSubtle; if (widget.disabled) { - color = _colors.textDisabled; + color = _colors.mainDisabled; } return _baseTextStyle.copyWith(color: color); } @@ -348,7 +348,7 @@ class InternalTextInputState extends State { onSubmitted: widget.onSubmit, style: _baseTextStyle, textInputAction: widget.textInputAction, - cursorErrorColor: _colors.error, + cursorErrorColor: _colors.mainNegative, obscureText: widget.obscureText, focusNode: widget.focusNode, decoration: InputDecoration( @@ -372,7 +372,7 @@ class InternalTextInputState extends State { hintText: widget.placeholder, errorText: widget.errorText, hintStyle: _baseTextStyle.copyWith( - color: widget.disabled ? _colors.textDisabled : _colors.textSubtle, + color: widget.disabled ? _colors.mainDisabled : _colors.mainSubtle, ), errorStyle: const TextStyle(height: 0.001, color: Colors.transparent), ), diff --git a/lib/src/components/time_input/time_input.dart b/lib/src/components/time_input/time_input.dart index ee7e49df..cbe22a76 100644 --- a/lib/src/components/time_input/time_input.dart +++ b/lib/src/components/time_input/time_input.dart @@ -72,7 +72,7 @@ class ZetaTimeInput extends ZetaFormField { onTap: state.clear, disabled: disabled, size: size, - color: colors.iconSubtle, + color: colors.mainSubtle, ), InputIconButton( icon: ZetaIcons.clock_outline, @@ -80,7 +80,7 @@ class ZetaTimeInput extends ZetaFormField { onTap: state.pickTime, disabled: disabled, size: size, - color: colors.iconDefault, + color: colors.mainDefault, ), ], ), @@ -238,8 +238,8 @@ class _ZetaTimeInputState extends FormFieldState { return Theme( data: Theme.of(context).copyWith( timePickerTheme: TimePickerThemeData( - dialBackgroundColor: colors.warm.shade30, - dayPeriodColor: colors.primary, + dialBackgroundColor: colors.surfacePrimarySubtle, + dayPeriodColor: colors.mainPrimary, shape: RoundedRectangleBorder( borderRadius: rounded ? Zeta.of(context).radius.rounded : Zeta.of(context).radius.none, ), diff --git a/lib/src/components/tooltip/tooltip.dart b/lib/src/components/tooltip/tooltip.dart index d060ff15..17eced21 100644 --- a/lib/src/components/tooltip/tooltip.dart +++ b/lib/src/components/tooltip/tooltip.dart @@ -54,14 +54,14 @@ class ZetaTooltip extends ZetaStatelessWidget { final EdgeInsets? padding; /// The color of the tooltip. - /// Default is `zeta.colors.textDefault`. + /// Default is `zeta.colors.mainDefault`. final Color? color; /// The text style of the tooltip. /// Default is: /// ``` /// ZetaTextStyles.bodyXSmall.copyWith( - /// color: zeta.colors.textInverse, + /// color: zeta.colors.mainInverse, /// fontWeight: FontWeight.w500, /// ), /// ``` @@ -77,7 +77,7 @@ class ZetaTooltip extends ZetaStatelessWidget { @override Widget build(BuildContext context) { final zeta = Zeta.of(context); - final color = this.color ?? zeta.colors.textDefault; + final color = this.color ?? zeta.colors.mainDefault; final horizontalArrowWidth = [ZetaTooltipArrowDirection.left, ZetaTooltipArrowDirection.right].contains(arrowDirection) ? _horizontalArrowSize.width @@ -135,7 +135,7 @@ class ZetaTooltip extends ZetaStatelessWidget { child: DefaultTextStyle( style: textStyle ?? ZetaTextStyles.bodyXSmall.copyWith( - color: zeta.colors.textInverse, + color: zeta.colors.mainInverse, fontWeight: FontWeight.w500, ), child: child, diff --git a/lib/src/components/top_app_bar/extended_top_app_bar.dart b/lib/src/components/top_app_bar/extended_top_app_bar.dart index c6a8d289..54fa3f7a 100644 --- a/lib/src/components/top_app_bar/extended_top_app_bar.dart +++ b/lib/src/components/top_app_bar/extended_top_app_bar.dart @@ -55,7 +55,7 @@ class ZetaExtendedAppBarDelegate extends SliverPersistentHeaderDelegate { return ConstrainedBox( constraints: BoxConstraints(minHeight: spacing.xl_9, maxHeight: maxExtent), child: ColoredBox( - color: Zeta.of(context).colors.surfacePrimary, + color: Zeta.of(context).colors.surfaceDefault, child: Stack( children: [ Positioned( diff --git a/lib/src/components/top_app_bar/search_top_app_bar.dart b/lib/src/components/top_app_bar/search_top_app_bar.dart index 7507541f..2be1f15e 100644 --- a/lib/src/components/top_app_bar/search_top_app_bar.dart +++ b/lib/src/components/top_app_bar/search_top_app_bar.dart @@ -160,13 +160,13 @@ class _ZetaTopAppBarSearchFieldState extends State wit controller: widget.searchController?.textEditingController, focusNode: _textFocusNode, style: ZetaTextStyles.bodyMedium, - cursorColor: colors.cool.shade90, + cursorColor: colors.mainDefault, decoration: InputDecoration( - iconColor: colors.cool.shade90, + iconColor: colors.mainDefault, filled: true, border: InputBorder.none, hintStyle: ZetaTextStyles.bodyMedium.copyWith( - color: colors.textDisabled, + color: colors.mainDisabled, ), hintText: widget.hintText, ), diff --git a/lib/src/components/top_app_bar/top_app_bar.dart b/lib/src/components/top_app_bar/top_app_bar.dart index 107caf1d..feb7dfa8 100644 --- a/lib/src/components/top_app_bar/top_app_bar.dart +++ b/lib/src/components/top_app_bar/top_app_bar.dart @@ -223,7 +223,7 @@ class _ZetaTopAppBarState extends State { } return DefaultTextStyle( - style: (widget.titleTextStyle ?? ZetaTextStyles.bodyLarge).copyWith(color: colors.textDefault), + style: (widget.titleTextStyle ?? ZetaTextStyles.bodyLarge).copyWith(color: colors.mainDefault), child: title ?? const Text(' '), ); } @@ -238,7 +238,7 @@ class _ZetaTopAppBarState extends State { label: widget.clearSemanticLabel, button: true, child: IconButton( - color: colors.cool.shade50, + color: colors.mainDefault, onPressed: () => _searchController.clearText(), icon: ZetaIcon( ZetaIcons.cancel, @@ -249,7 +249,7 @@ class _ZetaTopAppBarState extends State { if (widget.onSearchMicrophoneIconPressed != null) ...[ SizedBox( height: Zeta.of(context).spacing.xl_2, - child: VerticalDivider(width: ZetaBorders.medium, color: colors.cool.shade70), + child: VerticalDivider(width: ZetaBorders.medium, color: colors.mainSubtle), ), Semantics( label: widget.microphoneSemanticLabel, @@ -336,16 +336,16 @@ class _ZetaTopAppBarState extends State { child: AppBar( elevation: 0, scrolledUnderElevation: 0, - backgroundColor: colors.surfacePrimary, - iconTheme: IconThemeData(color: colors.iconDefault), + backgroundColor: colors.surfaceDefault, + iconTheme: IconThemeData(color: colors.mainDefault), leading: leading, toolbarHeight: spacing.xl_9, automaticallyImplyLeading: widget.automaticallyImplyLeading, surfaceTintColor: Colors.transparent, centerTitle: widget.type == ZetaTopAppBarType.centered, titleTextStyle: widget.titleTextStyle == null - ? ZetaTextStyles.bodyLarge.copyWith(color: colors.textDefault) - : widget.titleTextStyle!.copyWith(color: colors.textDefault), + ? ZetaTextStyles.bodyLarge.copyWith(color: colors.mainDefault) + : widget.titleTextStyle!.copyWith(color: colors.mainDefault), title: title, actions: actions, ), diff --git a/lib/src/theme/color_extensions.dart b/lib/src/theme/color_extensions.dart index 51f96968..2fc7a87a 100644 --- a/lib/src/theme/color_extensions.dart +++ b/lib/src/theme/color_extensions.dart @@ -1,10 +1,8 @@ import 'dart:math' as math; import 'package:flutter/material.dart'; -import 'color_swatch.dart'; -import 'colors_base.dart'; -import 'constants.dart'; -import 'contrast.dart'; +import 'package:flutter/scheduler.dart'; +import '../../zeta_flutter.dart'; /// Extensions on [Color] to brighten, lighten, darken and blend colors and /// can get a shade for gradients. @@ -70,9 +68,9 @@ extension ZetaColorExtensions on Color { /// It will return a color chosen according to the brightness of this color. /// /// * The [Color] instance on which this getter is called is used to determine the brightness based on [ThemeData.estimateBrightnessForColor] method. - /// * If the estimated brightness is light, it will return a color [ZetaColorBase.cool].shade90. - /// * If the estimated brightness is not light (meaning it's dark), it will return [ZetaColorBase.white]. - Color get onColor => isLight ? ZetaColorBase.cool.shade90 : ZetaColorBase.white; + /// * If the estimated brightness is light, it will return a color [Colors.black87]. + /// * If the estimated brightness is not light (meaning it's dark), it will return [Colors.white]. + Color get onColor => isLight ? Colors.black87 : Colors.white; /// Returns true if the color's brightness is [Brightness.light], else false. bool get isLight => ThemeData.estimateBrightnessForColor(this) == Brightness.light; @@ -247,14 +245,14 @@ extension ZetaColorExtensions on Color { /// /// * [primary] (Default = [kZetaSwatchPrimaryIndex]) - The primary color index for the swatch. This number should be a key in the swatch map. /// * [targetContrasts] (Default = [kZetaSwatchTargetContrasts]) - Map of target contrast values for each color index. - /// * [background] (Default = [ZetaColorBase.white]) - The color used to determine the contrast of the colors in the swatch. Generally, this should be the background color that the color swatch will be displayed on. + /// * [background] (Default = [Colors.white]) - The color used to determine the contrast of the colors in the swatch. Generally, this should be the background color that the color swatch will be displayed on. /// * [adjustPrimary] (Default = true) - Determines whether to adjust the contrast of the primary color on the background color. Useful in cases the brand color is being used. /// /// Returns a Map object. Map generateSwatch({ int primary = kZetaSwatchPrimaryIndex, Map targetContrasts = kZetaSwatchTargetContrasts, - Color background = ZetaColorBase.white, + Color background = Colors.white, bool adjustPrimary = true, }) { assert( @@ -305,3 +303,59 @@ extension ZetaColorExtensions on Color { return adjustContrast(on: on, target: standard.targetContrast); } } + +/// Extensions on [ZetaColors] to provide additional functionality. +/// +/// ZetaColors is a generated class, and so should not be manually edited. +/// Hence, any functions or properties needed should be added in this extension instead. +extension ZetaSemanticColorExtension on ZetaColors { + /// List of colorful colors. + List get rainbow => [ + primitives.red, + primitives.orange, + primitives.yellow, + primitives.green, + primitives.blue, + primitives.teal, + primitives.pink, + ]; + + /// Map of colorful colors. + Map get rainbowMap => { + 'red': primitives.red, + 'orange': primitives.orange, + 'yellow': primitives.yellow, + 'green': primitives.green, + 'blue': primitives.blue, + 'teal': primitives.teal, + 'pink': primitives.pink, + }; + + /// Creates a [ColorScheme] based on the current semantic colors. + ColorScheme get toColorScheme => ColorScheme( + brightness: primitives.brightness, + primary: mainPrimary, + onPrimary: mainPrimary.onColor, + secondary: mainSecondary, + onSecondary: mainSecondary.onColor, + error: mainNegative, + onError: mainNegative.onColor, + surface: surfaceDefault, + onSurface: mainDefault, + ); +} + +/// Extensions on [ThemeMode] to provide additional functionality. +extension ZetaThemeModeExtension on ThemeMode { + /// Returns true if the theme mode is dark. + bool get isDark => this == ThemeMode.system + ? SchedulerBinding.instance.platformDispatcher.platformBrightness.isDark + : this == ThemeMode.dark; + + /// Returns the brightness value based on the theme mode. + Brightness get brightness => isDark ? Brightness.dark : Brightness.light; +} + +extension on Brightness { + bool get isDark => this == Brightness.dark; +} diff --git a/lib/src/theme/color_scheme.dart b/lib/src/theme/color_scheme.dart deleted file mode 100644 index 3626ea52..00000000 --- a/lib/src/theme/color_scheme.dart +++ /dev/null @@ -1,220 +0,0 @@ -import 'package:flutter/foundation.dart'; -import 'package:flutter/material.dart'; - -import 'colors.dart'; -import 'constants.dart'; - -/// Easily craft stunning Flutter themes using pre-set color patterns or your own -/// choices. -/// -/// While Flutter's [ThemeData.from] offers a starting point for [ColorScheme]-based -/// themes, it sometimes defaults to the standard [ThemeData] factory, leading to inconsistencies, -/// particularly in dark themes. [ZetaColorScheme] addresses this by ensuring a seamless theme creation -/// with the [ColorScheme] approach. -/// -/// Themes can be formed using a default [ColorScheme], or by inputting select color values. If both a -/// [ColorScheme] and individual colors are provided, the individual colors will prevail. -/// -/// These factory constructors enable the creation of color-toned themes from a singular color. Additionally, -/// [ZetaColorScheme] simplifies theme crafting with color-branded backgrounds, blending different color degrees, primarily -/// the primary color. -/// -/// Adjusting the themed background of the [AppBar] is straightforward with [ZetaColorScheme], ensuring it aligns with themed colors. -/// {@category Theme} -@immutable -class ZetaColorScheme extends ColorScheme with Diagnosticable { - /// Default constructor with no required properties. - /// - /// Creates a light theme by default using the M2 colors as its default - /// theme. - const ZetaColorScheme({ - required this.zetaColors, - - /// If null, defaults to [kZetaFontFamily]; - this.fontFamily = kZetaFontFamily, - required super.brightness, - @Deprecated('Use surface instead. ' 'This feature was deprecated after v3.18.0-0.1.pre.') super.background, - required super.error, - @Deprecated('Use onSurface instead. ' 'This feature was deprecated after v3.18.0-0.1.pre.') super.onBackground, - required super.onError, - required super.onPrimary, - required super.onSecondary, - required super.onSurface, - required super.primary, - required super.secondary, - required super.surface, - super.errorContainer, - super.inversePrimary, - super.inverseSurface, - super.onErrorContainer, - super.onInverseSurface, - super.onPrimaryContainer, - super.onSecondaryContainer, - super.onSurfaceVariant, - super.onTertiary, - super.onTertiaryContainer, - super.outline, - super.outlineVariant, - super.primaryContainer, - super.scrim, - super.secondaryContainer, - super.shadow, - super.surfaceTint, - @Deprecated('Use surfaceContainerHighest instead. ' 'This feature was deprecated after v3.18.0-0.1.pre.') - super.surfaceVariant, - super.tertiary, - super.tertiaryContainer, - super.primaryFixed, - super.primaryFixedDim, - super.onPrimaryFixed, - super.onPrimaryFixedVariant, - super.secondaryFixed, - super.secondaryFixedDim, - super.onSecondaryFixed, - super.onSecondaryFixedVariant, - super.surfaceDim, - super.surfaceBright, - super.surfaceContainerLowest, - super.surfaceContainerLow, - super.surfaceContainer, - super.surfaceContainerHigh, - super.surfaceContainerHighest, - }); - - /// Current instance of the [ZetaColors] - final ZetaColors zetaColors; - - /// Name of the font family to use as default font for the text theme in - /// created theme. - /// - /// Same feature as in [ThemeData] factory. Used to apply the font family - /// name to default text theme and primary text theme, also passed along - /// to [ThemeData], - final String? fontFamily; - - /// Creates the copy of the current scheme from the provided values. - @override - ZetaColorScheme copyWith({ - ZetaColors? zetaColors, - String? fontFamily, - Brightness? brightness, - Color? primary, - Color? onPrimary, - Color? primaryContainer, - Color? onPrimaryContainer, - Color? primaryFixed, - Color? primaryFixedDim, - Color? onPrimaryFixed, - Color? onPrimaryFixedVariant, - Color? secondary, - Color? onSecondary, - Color? secondaryContainer, - Color? onSecondaryContainer, - Color? secondaryFixed, - Color? secondaryFixedDim, - Color? onSecondaryFixed, - Color? onSecondaryFixedVariant, - Color? tertiary, - Color? onTertiary, - Color? tertiaryContainer, - Color? onTertiaryContainer, - Color? tertiaryFixed, - Color? tertiaryFixedDim, - Color? onTertiaryFixed, - Color? onTertiaryFixedVariant, - Color? error, - Color? onError, - Color? errorContainer, - Color? onErrorContainer, - @Deprecated('Use surface instead. ' 'This feature was deprecated after v3.18.0-0.1.pre.') Color? background, - @Deprecated('Use onSurface instead. ' 'This feature was deprecated after v3.18.0-0.1.pre.') Color? onBackground, - Color? surface, - Color? onSurface, - @Deprecated('Use surfaceContainerHighest instead. ' 'This feature was deprecated after v3.18.0-0.1.pre.') - Color? surfaceVariant, - Color? surfaceDim, - Color? surfaceBright, - Color? surfaceContainerLowest, - Color? surfaceContainerLow, - Color? surfaceContainer, - Color? surfaceContainerHigh, - Color? surfaceContainerHighest, - Color? onSurfaceVariant, - Color? outline, - Color? outlineVariant, - Color? shadow, - Color? scrim, - Color? inverseSurface, - Color? onInverseSurface, - Color? inversePrimary, - Color? surfaceTint, - }) { - return ZetaColorScheme( - zetaColors: zetaColors ?? this.zetaColors, - fontFamily: fontFamily ?? this.fontFamily, - brightness: brightness ?? this.brightness, - primary: primary ?? this.primary, - onPrimary: onPrimary ?? this.onPrimary, - primaryFixed: primaryFixed ?? this.primaryFixed, - primaryFixedDim: primaryFixedDim ?? this.primaryFixedDim, - onPrimaryFixed: onPrimaryFixed ?? this.onPrimaryFixed, - onPrimaryFixedVariant: onPrimaryFixedVariant ?? this.onPrimaryFixedVariant, - primaryContainer: primaryContainer ?? this.primaryContainer, - onPrimaryContainer: onPrimaryContainer ?? this.onPrimaryContainer, - secondary: secondary ?? this.secondary, - onSecondary: onSecondary ?? this.onSecondary, - secondaryFixed: secondaryFixed ?? this.secondaryFixed, - secondaryFixedDim: secondaryFixedDim ?? this.secondaryFixedDim, - onSecondaryFixed: onSecondaryFixed ?? this.onSecondaryFixed, - onSecondaryFixedVariant: onSecondaryFixedVariant ?? this.onSecondaryFixedVariant, - secondaryContainer: secondaryContainer ?? this.secondaryContainer, - onSecondaryContainer: onSecondaryContainer ?? this.onSecondaryContainer, - tertiary: tertiary ?? this.tertiary, - onTertiary: onTertiary ?? this.onTertiary, - tertiaryContainer: tertiaryContainer ?? this.tertiaryContainer, - onTertiaryContainer: onTertiaryContainer ?? this.onTertiaryContainer, - error: error ?? this.error, - onError: onError ?? this.onError, - errorContainer: errorContainer ?? this.errorContainer, - onErrorContainer: onErrorContainer ?? this.onErrorContainer, - surface: surface ?? this.surface, - onSurface: onSurface ?? this.onSurface, - surfaceDim: surfaceDim ?? this.surfaceDim, - surfaceBright: surfaceBright ?? this.surfaceBright, - surfaceContainerLowest: surfaceContainerLowest ?? this.surfaceContainerLowest, - surfaceContainerLow: surfaceContainerLow ?? this.surfaceContainerLow, - surfaceContainer: surfaceContainer ?? this.surfaceContainer, - surfaceContainerHigh: surfaceContainerHigh ?? this.surfaceContainerHigh, - surfaceContainerHighest: surfaceContainerHighest ?? this.surfaceContainerHighest, - onSurfaceVariant: onSurfaceVariant ?? this.onSurfaceVariant, - outline: outline ?? this.outline, - outlineVariant: outlineVariant ?? this.outlineVariant, - shadow: shadow ?? this.shadow, - scrim: scrim ?? this.scrim, - inverseSurface: inverseSurface ?? this.inverseSurface, - onInverseSurface: onInverseSurface ?? this.onInverseSurface, - inversePrimary: inversePrimary ?? this.inversePrimary, - surfaceTint: surfaceTint ?? this.surfaceTint, - ); - } - - @override - void debugFillProperties(DiagnosticPropertiesBuilder properties) { - super.debugFillProperties(properties); - properties - ..add(DiagnosticsProperty('zetaColors', zetaColors)) - ..add(StringProperty('fontFamily', fontFamily)); - } - - @override - bool operator ==(Object other) => - identical(this, other) || - super == other && - other is ZetaColorScheme && - runtimeType == other.runtimeType && - zetaColors == other.zetaColors && - fontFamily == other.fontFamily; - - @override - int get hashCode => super.hashCode ^ zetaColors.hashCode ^ fontFamily.hashCode; -} diff --git a/lib/src/theme/color_swatch.dart b/lib/src/theme/color_swatch.dart index 529ecf8b..df2b649f 100644 --- a/lib/src/theme/color_swatch.dart +++ b/lib/src/theme/color_swatch.dart @@ -2,14 +2,13 @@ import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; import 'color_extensions.dart'; -import 'colors_base.dart'; import 'contrast.dart'; -/// {@template zeta-color-swatch} -/// A swatch of colors with values from 10 (light) to 100 (dark). +/// {@template zeta-colors-swatch} +/// Contains shades from 10 (light) to 100 (dark). /// /// See also: -/// * [MaterialColor]. +/// * [ColorSwatch]. /// {@endtemplate} /// /// {@category Theme} @@ -17,11 +16,10 @@ import 'contrast.dart'; class ZetaColorSwatch extends ColorSwatch with EquatableMixin { /// Constructs a [ZetaColorSwatch]. /// + /// /// See also: /// * [MaterialColor]. const ZetaColorSwatch({ - this.brightness = Brightness.light, - this.contrast = ZetaContrast.aa, required int primary, required Map swatch, }) : super(primary, swatch); @@ -33,13 +31,11 @@ class ZetaColorSwatch extends ColorSwatch with EquatableMixin { /// This factory constructor creates a color swatch based on a provided primary color. /// The darker and lighter shades are determined by predefined percentage values. /// - /// It ensures that the 60th and 80th shades from swatch are abide by the AA and AAA accessibility standards on `background`, respectively. - /// `background` color defaults to [ZetaColorBase.warm] shade10. + /// It ensures that the 60th and 80th shades from swatch abide by AA and AAA accessibility standards on `background`, respectively. /// {@endtemplate} + // TODO(UX-1144): Find a way to make this better factory ZetaColorSwatch.fromColor( Color primary, { - Brightness brightness = Brightness.light, - ZetaContrast contrast = ZetaContrast.aa, Color background = Colors.white, }) { /// Returns a map of colors shades with their respective indexes. @@ -49,30 +45,54 @@ class ZetaColorSwatch extends ColorSwatch with EquatableMixin { /// - 100, 90, 80, and 70 are darker shades of the primary color. /// - 60 is the primary color itself. /// - 50, 40, 30, 20, and 10 are progressively lighter shades of the primary color. + if (primary is ZetaColorSwatch) { + return primary; + } else if (primary is MaterialColor) { + return ZetaColorSwatch.fromMaterialColor(primary); + } return ZetaColorSwatch( - contrast: contrast, - brightness: brightness, primary: primary.value, swatch: primary.generateSwatch(background: background), - ).apply(brightness: brightness); + ); } - /// Selected contrast level of the system - final Brightness brightness; - - /// Selected contrast level of the system - final ZetaContrast contrast; + /// Creates a [ZetaColorSwatch] from a [MaterialColor] swatch. + factory ZetaColorSwatch.fromMaterialColor(MaterialColor swatch) { + return ZetaColorSwatch( + primary: swatch.value, + swatch: { + 10: swatch.shade50, + 20: swatch.shade100, + 30: swatch.shade200, + 40: swatch.shade300, + 50: swatch.shade400, + 60: swatch.shade500, + 70: swatch.shade600, + 80: swatch.shade700, + 90: swatch.shade800, + 100: swatch.shade900, + }, + ); + } - /// This method is an override of the index operator. - /// - /// If the requested index is not in the table (i.e., it results in `null`), the method returns `this`, - /// presumably the default color. - /// - /// [index] The index of the color swatch to return. Must be a non-negative integer. - /// - /// Returns the color at the specified swatch index, or the default color if the index is not in the table. - @override - Color? operator [](int index) => super[brightness == Brightness.dark ? 110 - index : index] ?? this; + /// Creates a [ZetaColorSwatch] from a [ZetaColorSwatch] with inverted shades. + factory ZetaColorSwatch.inverse(ZetaColorSwatch swatch) { + return ZetaColorSwatch( + primary: swatch.shade40.value, + swatch: { + 10: swatch.shade100, + 20: swatch.shade90, + 30: swatch.shade80, + 40: swatch.shade70, + 50: swatch.shade60, + 60: swatch.shade50, + 70: swatch.shade40, + 80: swatch.shade30, + 90: swatch.shade20, + 100: swatch.shade10, + }, + ); + } /// The lightest shade. Color get shade10 => this[10]!; @@ -112,53 +132,6 @@ class ZetaColorSwatch extends ColorSwatch with EquatableMixin { /// Color shade(int number) => this[number]!; - /// Returns the color shade for a surface depending on the ZetaContrast value. - /// - /// For [ZetaContrast.aa], it returns 60. - /// For [ZetaContrast.aaa], it returns 80. - Color get text => shade(contrast.text); - - /// Returns the color shade for an icon depending on the ZetaContrast value. - /// - /// For [ZetaContrast.aa], it returns 60. - /// For [ZetaContrast.aaa], it returns 80. - Color get icon => shade(contrast.icon); - - /// Returns the color shade for a hover state depending on the ZetaContrast value. - /// - /// For [ZetaContrast.aa], it returns 70. - /// For [ZetaContrast.aaa], it returns 90. - Color get hover => shade(contrast.hover); - - /// Returns the color shade for a selected state depending on the ZetaContrast value. - /// - /// For [ZetaContrast.aa], it returns 80. - /// For [ZetaContrast.aaa], it returns 100. - Color get selected => shade(contrast.selected); - - /// Returns the color shade for a focus state depending on the ZetaContrast value. - /// - /// For [ZetaContrast.aa], it returns 80. - /// For [ZetaContrast.aaa], it returns 100. - Color get focus => shade(contrast.focus); - - /// Returns the color shade for a border depending on the ZetaContrast value. - /// - /// For [ZetaContrast.aa], it returns 60. - /// For [ZetaContrast.aaa], it returns 80. - Color get border => shade(contrast.border); - - /// Returns the color shade for a subtle visual element depending on the ZetaContrast value. - /// - /// For [ZetaContrast.aa], it returns 40. - /// For [ZetaContrast.aaa], it returns 60. - Color get subtle => shade(contrast.subtle); - - /// Returns the color shade for a surface depending on the ZetaContrast value. - /// - /// For both [ZetaContrast.aa] and [ZetaContrast.aaa], it returns 10. - Color get surface => shade(contrast.surface); - /// Creates a copy of the current [ZetaColorSwatch] with potential modifications /// based on the provided [contrast] and [brightness]. /// @@ -173,8 +146,6 @@ class ZetaColorSwatch extends ColorSwatch with EquatableMixin { ZetaContrast contrast = ZetaContrast.aa, Brightness brightness = Brightness.light, }) { - if (this.contrast == contrast && this.brightness == brightness) return this; - // Generate a list of indices based on brightness level final indices = List.generate(10, (index) => (index + 1) * 10); @@ -186,8 +157,6 @@ class ZetaColorSwatch extends ColorSwatch with EquatableMixin { // Return a new ZetaColorSwatch object with the new primaryIndex color and swatch return ZetaColorSwatch( - contrast: contrast, - brightness: brightness, primary: swatch[primaryIndex]!.value, swatch: swatch, ); @@ -196,8 +165,6 @@ class ZetaColorSwatch extends ColorSwatch with EquatableMixin { @override List get props => [ super.value, - brightness, - contrast, shade10, shade20, shade30, diff --git a/lib/src/theme/colors.dart b/lib/src/theme/colors.dart deleted file mode 100644 index 801b8f4e..00000000 --- a/lib/src/theme/colors.dart +++ /dev/null @@ -1,1052 +0,0 @@ -import 'package:equatable/equatable.dart'; -import 'package:flutter/material.dart'; - -import 'color_extensions.dart'; -import 'color_scheme.dart'; -import 'color_swatch.dart'; -import 'colors_base.dart'; -import 'contrast.dart'; - -/// A customizable, token-based color palette, adapting Zeta colors to Flutter's colorScheme. -/// {@category Theme} -@immutable -class ZetaColors extends Equatable { - /// Default constructor for instance of [ZetaColors]. - ZetaColors({ - this.brightness = Brightness.light, - this.contrast = ZetaContrast.aa, - this.white = ZetaColorBase.white, - this.black = ZetaColorBase.black, - ZetaColorSwatch? primary, - ZetaColorSwatch? secondary, - ZetaColorSwatch? error, - ZetaColorSwatch? cool, - ZetaColorSwatch? warm, - ZetaColorSwatch? pure, - Color? surfacePrimary, - Color? surfaceSecondary, - Color? surfaceTertiary, - bool adjust = true, - @Deprecated('This color has been deprecated as of v0.10.0') link, - @Deprecated('This color has been deprecated as of v0.10.0') linkVisited, - @Deprecated('This color has been deprecated as of v0.10.0') shadow, - }) : primary = _adjustedValue(primary, ZetaColorBase.blue, adjust, brightness, contrast), - secondary = _adjustedValue(secondary, primary ?? ZetaColorBase.yellow, adjust, brightness, contrast), - error = _adjustedValue(error, ZetaColorBase.red, adjust, brightness, contrast), - cool = _adjustedValue(cool, ZetaColorBase.cool, adjust, brightness, ZetaContrast.aa), - warm = _adjustedValue(warm, ZetaColorBase.warm, adjust, brightness, ZetaContrast.aa), - pure = _adjustedValue(pure, ZetaColorBase.pure, adjust, brightness, ZetaContrast.aa), - surfacePrimary = surfacePrimary ?? white, - surfaceSecondary = surfaceSecondary ?? - _adjustedValue( - cool, - ZetaColorBase.cool, - adjust, - brightness, - ZetaContrast.aa, - ).shade10, - surfaceTertiary = surfaceTertiary ?? - _adjustedValue( - warm, - ZetaColorBase.warm, - adjust, - brightness, - ZetaContrast.aa, - ).shade10, - blue = _adjustedBase(ZetaColorBase.blue, adjust, brightness, contrast), - green = _adjustedBase(ZetaColorBase.green, adjust, brightness, contrast), - red = _adjustedBase(ZetaColorBase.red, adjust, brightness, contrast), - orange = _adjustedBase(ZetaColorBase.orange, adjust, brightness, contrast), - purple = _adjustedBase(ZetaColorBase.purple, adjust, brightness, contrast), - yellow = _adjustedBase(ZetaColorBase.yellow, adjust, brightness, contrast), - teal = _adjustedBase(ZetaColorBase.teal, adjust, brightness, contrast), - pink = _adjustedBase(ZetaColorBase.pink, adjust, brightness, contrast); - - /// Factory constructor for a light theme for [ZetaColors]. - /// - /// All color options are nullable and default to a pre-defined contrast color if null. - /// - /// [contrast] The primary contrast color. If not supplied, defaults to [ZetaContrast.aa]. - /// [primary] A color swatch for primary color accent. Defaults to null. - /// [secondary] A color swatch for secondary color accent. Defaults to null. - /// [error] A color swatch for error states. Defaults to null. - /// [cool] A color swatch for cooler color tones. Defaults to null. - /// [warm] A color swatch for warmer color tones. Defaults to null. - /// [white] A color option for white color. Defaults to null. - /// [black] A color option for black color. Defaults to null. - factory ZetaColors.light({ - ZetaContrast contrast = ZetaContrast.aa, - ZetaColorSwatch? primary, - ZetaColorSwatch? secondary, - ZetaColorSwatch? error, - ZetaColorSwatch? cool, - ZetaColorSwatch? warm, - Color? white, - Color? black, - @Deprecated('This color has been deprecated as of v0.10.0') link, - @Deprecated('This color has been deprecated as of v0.10.0') linkVisited, - @Deprecated('This color has been deprecated as of v0.10.0') shadow, - }) { - return ZetaColors( - white: white ?? ZetaColorBase.white, - black: black ?? ZetaColorBase.black, - cool: cool, - warm: warm, - error: error, - primary: primary, - contrast: contrast, - secondary: secondary, - surfaceTertiary: warm?.shade10, - surfaceSecondary: cool?.shade10, - surfacePrimary: white ?? ZetaColorBase.white, - ); - } - - /// Factory constructor for a dark theme for [ZetaColors]. - /// - /// All color options are nullable and default to a pre-defined contrast color if null. - /// - /// [contrast] The primary contrast color. If not supplied, defaults to [ZetaContrast.aa]. - /// [primary] A color swatch for primary color accent. Defaults to null. - /// [secondary] A color swatch for secondary color accent. Defaults to null. - /// [error] A color swatch for error states. Defaults to null. - /// [cool] A color swatch for cooler color tones. Defaults to null. - /// [warm] A color swatch for warmer color tones. Defaults to null. - /// [white] A color option for white color. Defaults to null. - /// [black] A color option for black color. Defaults to null. - factory ZetaColors.dark({ - ZetaContrast contrast = ZetaContrast.aa, - ZetaColorSwatch? primary, - ZetaColorSwatch? secondary, - ZetaColorSwatch? error, - ZetaColorSwatch? cool, - ZetaColorSwatch? warm, - Color? white, - Color? black, - @Deprecated('This color has been deprecated as of v0.10.0') link, - @Deprecated('This color has been deprecated as of v0.10.0') linkVisited, - @Deprecated('This color has been deprecated as of v0.10.0') shadow, - }) { - return ZetaColors( - cool: cool, - warm: warm, - white: white ?? ZetaColorBase.white, - black: black ?? ZetaColorBase.black, - primary: primary, - contrast: contrast, - secondary: secondary, - error: error, - brightness: Brightness.dark, - surfaceTertiary: warm?.shade10, - surfaceSecondary: cool?.shade10, - surfacePrimary: black ?? ZetaColorBase.black, - ); - } - - /// Hover surface color. - @Deprecated('Use surfaceHover instead. ' 'This color has been deprecated as of v0.10.0.') - Color get surfaceHovered => surfaceHover; - - /// Selected hover surface color. - @Deprecated('Use surfaceSelectedHover instead. ' 'This color has been deprecated as of v0.10.0.') - Color get surfaceSelectedHovered => surfaceSelectedHover; - - /// Positive color. - @Deprecated('Use surfacePositive instead. ' 'This color has been deprecated as of v0.10.0.') - ZetaColorSwatch get positive => surfacePositive; - - /// Negative color. - @Deprecated('Use surfaceNegative instead. ' 'This color has been deprecated as of v0.10.0.') - ZetaColorSwatch get negative => surfaceNegative; - - /// Warning color. - @Deprecated('Use surfaceWarning instead. ' 'This color has been deprecated as of v0.10.0.') - ZetaColorSwatch get warning => surfaceWarning; - - /// Info color. - @Deprecated('Use surfaceInfo instead. ' 'This color has been deprecated as of v0.10.0.') - ZetaColorSwatch get info => surfaceInfo; - - /// Shadow color. - @Deprecated('This color has been deprecated as of v0.10.0.') - Color get shadow => const Color(0x1A49505E); - - /// Link color - @Deprecated('This color has been deprecated as of v0.10.0.') - Color get link => ZetaColorBase.linkLight; - - /// Visited link color - @Deprecated('This color has been deprecated as of v0.10.0.') - Color get linkVisited => ZetaColorBase.linkVisitedLight; - - /// Constructor Fields - - /// Represents the brightness value. - final Brightness brightness; - - /// Represents the Zeta accessibility standard. - final ZetaContrast contrast; - - /// Primary color swatch. - /// - /// Defaults to [ZetaColorBase.blue]. - /// - /// {@macro zeta-color-dark} - final ZetaColorSwatch primary; - - /// Secondary color used in app. - /// - /// Defaults to [ZetaColorBase.yellow] - /// - /// Maps to [ColorScheme.secondary]. - final ZetaColorSwatch secondary; - - /// Secondary color used in app. - /// - /// Defaults to `ZetaColors.red.60`. - /// - /// Maps to [ColorScheme.error]. - final ZetaColorSwatch error; - - /// Cool color swatch. - /// - /// Defaults to [ZetaColorBase.cool]. - /// - /// {@macro zeta-color-dark} - final ZetaColorSwatch cool; - - /// Warm color swatch. - /// - /// Defaults to [ZetaColorBase.warm]. - /// - /// {@macro zeta-color-dark} - final ZetaColorSwatch warm; - - /// Pure color swatch. - /// - /// Defaults to [ZetaColorBase.pure]. - /// - /// {@macro zeta-color-dark} - final ZetaColorSwatch pure; - - /// White color. - /// - /// Maps to [ColorScheme.surface]. - /// - /// Defaults to [ZetaColorBase.white]. - final Color white; - - /// Shadow color. - /// - /// Maps to [ColorScheme.surface]. - /// - /// Defaults to [ZetaColorBase.black]. - final Color black; - - /// Surface color. - /// - /// Maps to [ColorScheme.surface]. - /// - /// * Light mode: `ZetaColors.black` - /// * Dark mode: `ZetaColors.white`. - final Color surfacePrimary; - - /// Secondary surface color. - /// - /// * `ZetaColors.cool.10`. - final Color surfaceSecondary; - - /// Tertiary surface color. - /// - /// Maps to [ColorScheme.surface] and [ThemeData.scaffoldBackgroundColor] - /// - /// * `ZetaColors.warm.10`. - final Color surfaceTertiary; - - // Text / icons. - - /// Default text /icon color. - /// - /// Defaults to `ZetaColors.cool.90`. - /// - /// {@template zeta-color-dark} - /// Color swatches are inverted if [ZetaColors.brightness] is Dark. - /// {@endtemplate} - Color get textDefault => cool.shade90; - - /// Subtle text /icon color. - /// - /// Defaults to `ZetaColors.cool.70`. - /// - /// Maps to [ColorScheme.onSurface]. - /// - /// {@macro zeta-color-dark} - Color get textSubtle => cool.shade70; - - /// Disabled text / icon color. - /// - /// Defaults to `ZetaColors.cool.50`. - /// - /// {@macro zeta-color-dark} - Color get textDisabled => cool.shade50; - - /// Inverse text / icon color. - /// - /// Used for text that is not on [ColorScheme.surface] or [ThemeData.scaffoldBackgroundColor]. - /// - /// Defaults to `ZetaColors.cool.20`. - /// - /// {@macro zeta-color-dark} - Color get textInverse => cool.shade20; - - /// Default icon color. - /// - /// Defaults to `ZetaColors.cool.90`. - /// - /// {@macro zeta-color-dark} - Color get iconDefault => cool.shade90; - - /// Subtle icon color. - /// - /// Defaults to `ZetaColors.cool.70`. - /// - /// Maps to [ColorScheme.onSurface]. - /// - /// {@macro zeta-color-dark} - Color get iconSubtle => cool.shade70; - - /// Disabled icon color. - /// - /// Defaults to `ZetaColors.cool.50`. - /// - /// {@macro zeta-color-dark} - Color get iconDisabled => cool.shade50; - - /// Inverse icon color. - /// - /// Used for text that is not on [ColorScheme.surface] or [ThemeData.scaffoldBackgroundColor]. - /// - /// Defaults to `ZetaColors.cool.20`. - /// - /// {@macro zeta-color-dark} - Color get iconInverse => cool.shade20; - - /// Default Surface Color - /// - /// {@macro zeta-color-dark} - Color get surfaceDefault => pure.shade(0); - - /// Default-inverse Surface Color - /// - /// {@macro zeta-color-dark} - Color get surfaceDefaultInverse => warm.shade(100); - - /// Hover Surface Color - /// - /// {@macro zeta-color-dark} - Color get surfaceHover => cool.shade(20); - - /// Selected Surface Color - /// - /// {@macro zeta-color-dark} - Color get surfaceSelected => primary.shade(10); - - /// Selected-hover Surface Color - /// - /// {@macro zeta-color-dark} - Color get surfaceSelectedHover => primary.shade(20); - - /// Disabled Surface Color - /// - /// {@macro zeta-color-dark} - Color get surfaceDisabled => cool.shade(30); - - /// Cool Surface Color - /// - /// {@macro zeta-color-dark} - Color get surfaceCool => cool.shade(10); - - /// Warm Surface Color - /// - /// {@macro zeta-color-dark} - Color get surfaceWarm => warm.shade(10); - - /// Primary-subtle Surface Color - /// - /// {@macro zeta-color-dark} - Color get surfacePrimarySubtle => primary.shade(10); - - /// Avatar Avatar Surface Color - /// - /// {@macro zeta-color-dark} - Color get surfaceAvatarBlue => blue.shade(80); - - /// Avatar Avatar Surface Color - /// - /// {@macro zeta-color-dark} - ZetaColorSwatch get surfaceAvatarGreen => green; - - /// Avatar Avatar Surface Color - /// - /// {@macro zeta-color-dark} - Color get surfaceAvatarOrange => orange.shade(50); - - /// Avatar Avatar Surface Color - /// - /// {@macro zeta-color-dark} - Color get surfaceAvatarPink => pink.shade(80); - - /// Avatar Avatar Surface Color - /// - /// {@macro zeta-color-dark} - Color get surfaceAvatarPurple => purple.shade(80); - - /// Avatar Avatar Surface Color - /// - /// {@macro zeta-color-dark} - Color get surfaceAvatarTeal => teal.shade(80); - - /// Avatar Avatar Surface Color - /// - /// {@macro zeta-color-dark} - Color get surfaceAvatarYellow => yellow.shade(50); - - /// Secondary-subtle Surface Color - /// - /// {@macro zeta-color-dark} - Color get surfaceSecondarySubtle => secondary.shade(10); - - /// Positive Surface Color - /// - /// {@macro zeta-color-dark} - ZetaColorSwatch get surfacePositive => green; - - /// Positive-subtle Surface Color - /// - /// {@macro zeta-color-dark} - Color get surfacePositiveSubtle => green.shade(10); - - /// Warning Surface Color - /// - /// {@macro zeta-color-dark} - ZetaColorSwatch get surfaceWarning => orange; - - /// Warning-subtle Surface Color - /// - /// {@macro zeta-color-dark} - Color get surfaceWarningSubtle => orange.shade(10); - - /// Negative Surface Color - /// - /// {@macro zeta-color-dark} - ZetaColorSwatch get surfaceNegative => red; - - /// Negative-subtle Surface Color - /// - /// {@macro zeta-color-dark} - Color get surfaceNegativeSubtle => red.shade(10); - - /// Info Surface Color - /// - /// {@macro zeta-color-dark} - ZetaColorSwatch get surfaceInfo => purple; - - /// Info-subtle Surface Color - /// - /// {@macro zeta-color-dark} - Color get surfaceInfoSubtle => purple.shade(10); - - /// Default Border Color - /// - /// {@macro zeta-color-dark} - Color get borderDefault => cool.shade(40); - - /// Subtle Border Color - /// - /// {@macro zeta-color-dark} - Color get borderSubtle => cool.shade(30); - - /// Hover Border Color - /// - /// {@macro zeta-color-dark} - Color get borderHover => cool.shade(90); - - /// Selected Border Color - /// - /// {@macro zeta-color-dark} - Color get borderSelected => cool.shade(90); - - /// Disabled Border Color - /// - /// {@macro zeta-color-dark} - Color get borderDisabled => cool.shade(20); - - /// Pure Border Color - /// - /// {@macro zeta-color-dark} - Color get borderPure => pure.shade(0); - - /// Primary-main Border Color - /// - /// {@macro zeta-color-dark} - ZetaColorSwatch get borderPrimaryMain => primary; - - /// Primary Border Color - /// - /// {@macro zeta-color-dark} - Color get borderPrimary => primary.shade(50); - - /// Secondary Border Color - /// - /// {@macro zeta-color-dark} - Color get borderSecondary => secondary.shade(50); - - /// Positive Border Color - /// - /// {@macro zeta-color-dark} - Color get borderPositive => green.shade(50); - - /// Warning Border Color - /// - /// {@macro zeta-color-dark} - Color get borderWarning => orange.shade(50); - - /// Negative Border Color - /// - /// {@macro zeta-color-dark} - Color get borderNegative => red.shade(50); - - /// Info Border Color - /// - /// {@macro zeta-color-dark} - Color get borderInfo => purple.shade(50); - - /// Blue color swatch - /// - /// Defaults to [ZetaColorBase.blue] - /// - /// {@macro zeta-color-dark} - final ZetaColorSwatch blue; - - /// Green color swatch - /// - /// Defaults to [ZetaColorBase.green] - /// - /// {@macro zeta-color-dark} - final ZetaColorSwatch green; - - /// Red color swatch - /// - /// Defaults to [ZetaColorBase.red] - /// - /// {@macro zeta-color-dark} - final ZetaColorSwatch red; - - /// Orange color swatch - /// - /// Defaults to [ZetaColorBase.orange] - /// - /// {@macro zeta-color-dark} - final ZetaColorSwatch orange; - - /// Purple color swatch - /// - /// Defaults to [ZetaColorBase.purple] - /// - /// {@macro zeta-color-dark} - final ZetaColorSwatch purple; - - /// Yellow color swatch - /// - /// Defaults to [ZetaColorBase.yellow] - /// - /// {@macro zeta-color-dark} - final ZetaColorSwatch yellow; - - /// Teal color swatch - /// - /// Defaults to [ZetaColorBase.teal] - /// - /// {@macro zeta-color-dark} - final ZetaColorSwatch teal; - - /// Pink color swatch - /// - /// Defaults to [ZetaColorBase.pink] - /// - /// {@macro zeta-color-dark} - final ZetaColorSwatch pink; - - /// True if current [ZetaColors] object uses dark mode colors. - bool get isDarkMode => brightness == Brightness.dark; - - /// List of colorful colors. - List get rainbow => [red, orange, yellow, green, blue, teal, pink]; - - /// Map of colorful colors. - Map get rainbowMap => { - 'red': red, - 'orange': orange, - 'yellow': yellow, - 'green': green, - 'blue': blue, - 'teal': teal, - 'pink': pink, - }; - - /// Helper function to adjust color swatch values based on brightness and contrast - static ZetaColorSwatch _adjustedValue( - ZetaColorSwatch? value, - ZetaColorSwatch defaultValue, - bool adjust, - Brightness brightness, - ZetaContrast contrast, - ) { - final swatch = value ?? defaultValue; - return adjust ? swatch.apply(brightness: brightness, contrast: contrast) : swatch; - } - - /// Helper function to adjust color base values based on brightness and contrast - static ZetaColorSwatch _adjustedBase( - ZetaColorSwatch baseColor, - bool adjust, - Brightness brightness, - ZetaContrast contrast, - ) { - return adjust ? baseColor.apply(brightness: brightness, contrast: contrast) : baseColor; - } - - /// Applies new property values to [ZetaColors] and returns a new copy. - /// - /// Each property defaults to the previous value if not specified. - ZetaColors copyWith({ - Brightness? brightness, - ZetaContrast? contrast, - ZetaColorSwatch? primary, - ZetaColorSwatch? secondary, - ZetaColorSwatch? error, - ZetaColorSwatch? cool, - ZetaColorSwatch? warm, - Color? white, - Color? black, - Color? surfacePrimary, - Color? surfaceSecondary, - Color? surfaceTertiary, - @Deprecated('This color has been deprecated as of v0.10.0') Color? link, - @Deprecated('This color has been deprecated as of v0.10.0') Color? linkVisited, - @Deprecated('This color has been deprecated as of v0.10.0') Color? shadow, - }) { - return ZetaColors( - white: white ?? this.white, - black: black ?? this.black, - brightness: brightness ?? this.brightness, - contrast: contrast ?? this.contrast, - primary: primary ?? this.primary, - secondary: secondary ?? this.secondary, - error: error ?? this.error, - cool: cool ?? this.cool, - warm: warm ?? this.warm, - surfacePrimary: surfacePrimary ?? this.surfacePrimary, - surfaceSecondary: surfaceSecondary ?? this.surfaceSecondary, - surfaceTertiary: surfaceTertiary ?? this.surfaceTertiary, - adjust: (brightness != null && brightness != this.brightness) || (contrast != null && contrast != this.contrast), - ); - } - - /// Apply the given contrast to the color scheme and return a new color scheme. - /// - /// If the contrast is the same as the current one, this method will return the current color scheme. - ZetaColors apply({ - required ZetaContrast contrast, - }) { - if (contrast == this.contrast) return this; - return copyWith( - contrast: contrast, - ); - } - - /// Returns a [ZetaColorScheme] based on the properties of the current [ZetaColors]. - ZetaColorScheme toScheme() { - final effectivePrimary = primary.shade(contrast.primary); - final effectiveSecondary = secondary.shade(contrast.primary); - final effectiveSurface = surfacePrimary; - final effectiveError = error; - - return ZetaColorScheme( - zetaColors: this, - brightness: brightness, - error: effectiveError, - onError: effectiveError.onColor, - onPrimary: effectivePrimary.onColor, - onSecondary: effectiveSecondary.onColor, - onSurface: textDefault, - primary: effectivePrimary, - secondary: effectiveSecondary, - surface: effectiveSurface, - ); - } - - @override - List get props => [ - brightness, - contrast, - primary, - secondary, - error, - cool, - warm, - white, - black, - surfacePrimary, - surfaceSecondary, - surfaceTertiary, - ]; -} - -enum _ZetaColorProperties { - primarySwatch, - secondarySwatch, - cool, - warm, - textDefault, - textSubtle, - pink, - teal, - yellow, - purple, - orange, - red, - green, - blue, - surfaceSelected, - surfaceSelectedHover, - surfaceHover, - surfaceDisabled, - surfaceTertiary, - surfaceSecondary, - surfacePrimary, - borderSelected, - borderDisabled, - borderSubtle, - borderDefault, - textInverse, - textDisabled, -} - -/// Custom extension on ColorScheme which makes [ZetaColors] available through theme context. -/// -/// A customizable, token-based color palette, adapting Zeta colors to Flutter's colorScheme. -extension ZetaColorGetters on ColorScheme { - ZetaColorScheme? get _resolve => this is ZetaColorScheme ? this as ZetaColorScheme : null; - - /// Represents the Zeta accessibility standard. - ZetaContrast get contrast => _resolve?.zetaColors.contrast ?? ZetaContrast.aa; - - /// Primary color swatch. - /// - /// Defaults to [ZetaColorBase.blue]. - /// - /// {@macro zeta-color-dark} - ZetaColorSwatch get primarySwatch => - _resolve?.zetaColors.primary ?? _resolveDefault(_ZetaColorProperties.primarySwatch); - - /// Secondary color used in app. - /// - /// Defaults to `ZetaColors.cool.90`. - /// - /// Maps to [ColorScheme.secondary]. - ZetaColorSwatch get secondarySwatch => - _resolve?.zetaColors.secondary ?? _resolveDefault(_ZetaColorProperties.secondarySwatch); - - /// Cool color swatch. - /// - /// Defaults to [ZetaColorBase.cool]. - /// - /// {@macro zeta-color-dark} - ZetaColorSwatch get cool => _resolve?.zetaColors.cool ?? _resolveDefault(_ZetaColorProperties.cool); - - /// Warm color swatch. - /// - /// Defaults to [ZetaColorBase.warm]. - /// - /// {@macro zeta-color-dark} - ZetaColorSwatch get warm => _resolve?.zetaColors.warm ?? _resolveDefault(_ZetaColorProperties.warm); - - /// Cool color swatch. - /// - /// Defaults to [ZetaColorBase.cool]. - /// - /// {@macro zeta-color-dark} - Color get textDefault => _resolve?.zetaColors.textDefault ?? _resolveDefault(_ZetaColorProperties.textDefault); - - /// Subtle text /icon color. - /// - /// Defaults to `ZetaColors.cool.70`. - /// - /// Maps to [ColorScheme.onSurface]. - /// - /// {@macro zeta-color-dark} - Color get textSubtle => _resolve?.zetaColors.textSubtle ?? _resolveDefault(_ZetaColorProperties.textSubtle); - - /// Disabled text / icon color. - /// - /// Defaults to `ZetaColors.cool.50`. - /// - /// {@macro zeta-color-dark} - Color get textDisabled => _resolve?.zetaColors.textDisabled ?? _resolveDefault(_ZetaColorProperties.textDisabled); - - /// Inverse text / icon color. - /// - /// Used for text that is not on [ColorScheme.surface] or [ThemeData.scaffoldBackgroundColor]. - /// - /// Defaults to `ZetaColors.cool.20`. - /// - /// {@macro zeta-color-dark} - Color get textInverse => _resolve?.zetaColors.textInverse ?? _resolveDefault(_ZetaColorProperties.textInverse); - - // Border variants. - - /// Default border color. - /// - /// Defaults to `ZetaColors.warm.50`. - /// - /// {@macro zeta-color-dark} - Color get borderDefault => _resolve?.zetaColors.borderDefault ?? _resolveDefault(_ZetaColorProperties.borderDefault); - - /// Subtle border color. - /// - /// `ZetaColors.cool.40`. - /// - /// {@macro zeta-color-dark} - Color get borderSubtle => _resolve?.zetaColors.borderSubtle ?? _resolveDefault(_ZetaColorProperties.borderSubtle); - - /// Disabled border color. - /// - /// Defaults to `ZetaColors.cool.30`. - /// - /// {@macro zeta-color-dark} - Color get borderDisabled => - _resolve?.zetaColors.borderDisabled ?? _resolveDefault(_ZetaColorProperties.borderDisabled); - - /// Selected border color. - /// - /// Defaults to `ZetaColors.cool.90`. - /// - /// {@macro zeta-color-dark} - Color get borderSelected => - _resolve?.zetaColors.borderSelected ?? _resolveDefault(_ZetaColorProperties.borderSelected); - - // Backdrop colors. - - /// Surface color. - /// - /// Maps to [ColorScheme.surface]. - /// - /// * Light mode: `ZetaColors.black` - /// * Dark mode: `ZetaColors.white`. - Color get surfacePrimary => - _resolve?.zetaColors.surfacePrimary ?? _resolveDefault(_ZetaColorProperties.surfacePrimary); - - /// Secondary surface color. - /// - /// - /// * `ZetaColors.cool.10`. - Color get surfaceSecondary => - _resolve?.zetaColors.surfaceSecondary ?? _resolveDefault(_ZetaColorProperties.surfaceSecondary); - - /// Tertiary surface color. - /// - /// Maps to [ThemeData.scaffoldBackgroundColor]. - /// - /// * `ZetaColors.warm.10`. - Color get surfaceTertiary => - _resolve?.zetaColors.surfaceTertiary ?? _resolveDefault(_ZetaColorProperties.surfaceTertiary); - - /// Disabled surface color. - /// - /// Defaults to `ZetaColors.cool.30`. - /// - /// {@macro zeta-color-dark} - Color get surfaceDisabled => - _resolve?.zetaColors.surfaceDisabled ?? _resolveDefault(_ZetaColorProperties.surfaceDisabled); - - /// Hover surface color. - /// - /// Defaults to `ZetaColors.cool.20`. - /// - /// {@macro zeta-color-dark} - Color get surfaceHover => _resolve?.zetaColors.surfaceHover ?? _resolveDefault(_ZetaColorProperties.surfaceHover); - - /// Selected hover surface color. - /// - /// Defaults to: `ZetaColors.blue.20`. - Color get surfaceSelectedHover => - _resolve?.zetaColors.surfaceSelectedHover ?? _resolveDefault(_ZetaColorProperties.surfaceSelectedHover); - - /// Selected surface color. - /// - /// Defaults to: `ZetaColors.blue.10`. - Color get surfaceSelected => - _resolve?.zetaColors.surfaceSelected ?? _resolveDefault(_ZetaColorProperties.surfaceSelected); - - /// Blue color swatch. - /// - /// Defaults to [ZetaColorBase.blue]. - /// - /// {@macro zeta-color-dark} - ZetaColorSwatch get blue => _resolve?.zetaColors.blue ?? _resolveDefault(_ZetaColorProperties.blue); - - /// Green color swatch. - /// - /// Defaults to [ZetaColorBase.green]. - /// - /// {@macro zeta-color-dark} - ZetaColorSwatch get green => _resolve?.zetaColors.green ?? _resolveDefault(_ZetaColorProperties.green); - - /// Red color swatch. - /// - /// Defaults to [ZetaColorBase.red]. - /// - /// {@macro zeta-color-dark} - ZetaColorSwatch get red => _resolve?.zetaColors.red ?? _resolveDefault(_ZetaColorProperties.red); - - /// Orange color swatch. - /// - /// Defaults to [ZetaColorBase.orange]. - /// - /// {@macro zeta-color-dark} - ZetaColorSwatch get orange => _resolve?.zetaColors.orange ?? _resolveDefault(_ZetaColorProperties.orange); - - /// Purple color swatch. - /// - /// Defaults to [ZetaColorBase.purple]. - /// - /// {@macro zeta-color-dark} - ZetaColorSwatch get purple => _resolve?.zetaColors.purple ?? _resolveDefault(_ZetaColorProperties.purple); - - /// Yellow color swatch. - /// - /// Defaults to [ZetaColorBase.yellow]. - /// - /// {@macro zeta-color-dark} - ZetaColorSwatch get yellow => _resolve?.zetaColors.yellow ?? _resolveDefault(_ZetaColorProperties.yellow); - - /// Teal color swatch. - /// - /// Defaults to [ZetaColorBase.teal]. - /// - /// {@macro zeta-color-dark} - ZetaColorSwatch get teal => _resolve?.zetaColors.teal ?? _resolveDefault(_ZetaColorProperties.teal); - - /// Pink color swatch. - /// - /// Defaults to [ZetaColorBase.pink]. - /// - /// {@macro zeta-color-dark} - ZetaColorSwatch get pink => _resolve?.zetaColors.pink ?? _resolveDefault(_ZetaColorProperties.pink); - - // Alert Colors - - /// Green positive color. - /// - /// Defaults to `ZetaColors.green.60` in AA system. - /// Defaults to `ZetaColors.green.80` in AAA system. - /// - /// {@macro zeta-color-dark} - /// - /// {@template zeta-color-aaa} - /// When changing from AA to AAA, the color will increase by 2 stops on the swatch. - /// {@endtemplate} - Color get positive => green; - - /// Red negative color. - /// - /// Defaults to `ZetaColors.red.60` in AA system. - /// Defaults to `ZetaColors.red.80` in AAA system. - /// - /// Maps to [ColorScheme.error]. - /// - /// {@macro zeta-color-dark} - /// - /// {@macro zeta-color-aaa} - Color get negative => red; - - /// Orange warning color. - /// - /// Defaults to `ZetaColors.orange.60` in AA system. - /// Defaults to `ZetaColors.orange.80` in AAA system. - /// - /// {@macro zeta-color-dark} - /// - /// {@macro zeta-color-aaa} - Color get warning => orange; - - /// Purple info color. - /// - /// Defaults to `ZetaColors.purple.60` in AA system. - /// Defaults to `ZetaColors.purple.80` in AAA system. - /// - /// {@macro zeta-color-dark} - /// - /// {@macro zeta-color-aaa} - Color get info => purple; - - T _resolveDefault(_ZetaColorProperties property) { - switch (property) { - case _ZetaColorProperties.primarySwatch: - return ZetaColorBase.blue.apply(brightness: brightness, contrast: contrast) as T; - case _ZetaColorProperties.secondarySwatch: - return ZetaColorBase.yellow.apply(brightness: brightness, contrast: contrast) as T; - case _ZetaColorProperties.cool: - return ZetaColorBase.cool.apply(brightness: brightness, contrast: contrast) as T; - case _ZetaColorProperties.warm: - return ZetaColorBase.warm.apply(brightness: brightness, contrast: contrast) as T; - case _ZetaColorProperties.textDefault: - return ZetaColorBase.cool.apply(brightness: brightness, contrast: contrast).shade90 as T; - case _ZetaColorProperties.textSubtle: - return ZetaColorBase.cool.apply(brightness: brightness, contrast: contrast).shade70 as T; - case _ZetaColorProperties.textInverse: - return ZetaColorBase.cool.apply(brightness: brightness, contrast: contrast).shade20 as T; - case _ZetaColorProperties.textDisabled: - return ZetaColorBase.cool.apply(brightness: brightness, contrast: contrast).shade50 as T; - case _ZetaColorProperties.pink: - return ZetaColorBase.pink.apply(brightness: brightness, contrast: contrast) as T; - case _ZetaColorProperties.teal: - return ZetaColorBase.teal.apply(brightness: brightness, contrast: contrast) as T; - case _ZetaColorProperties.yellow: - return ZetaColorBase.yellow.apply(brightness: brightness, contrast: contrast) as T; - case _ZetaColorProperties.purple: - return ZetaColorBase.purple.apply(brightness: brightness, contrast: contrast) as T; - case _ZetaColorProperties.orange: - return ZetaColorBase.orange.apply(brightness: brightness, contrast: contrast) as T; - case _ZetaColorProperties.red: - return ZetaColorBase.red.apply(brightness: brightness, contrast: contrast) as T; - case _ZetaColorProperties.green: - return ZetaColorBase.green.apply(brightness: brightness, contrast: contrast) as T; - case _ZetaColorProperties.blue: - return ZetaColorBase.blue.apply(brightness: brightness, contrast: contrast) as T; - case _ZetaColorProperties.surfaceSelected: - return ZetaColorBase.blue.apply(brightness: brightness, contrast: contrast).shade10 as T; - case _ZetaColorProperties.surfaceSelectedHover: - return ZetaColorBase.blue.apply(brightness: brightness, contrast: contrast).shade20 as T; - case _ZetaColorProperties.surfaceHover: - return ZetaColorBase.cool.apply(brightness: brightness, contrast: contrast).shade20 as T; - case _ZetaColorProperties.surfaceDisabled: - return ZetaColorBase.cool.apply(brightness: brightness, contrast: contrast).shade30 as T; - case _ZetaColorProperties.surfaceTertiary: - return ZetaColorBase.warm.apply(brightness: brightness, contrast: contrast).shade10 as T; - case _ZetaColorProperties.surfaceSecondary: - return ZetaColorBase.cool.apply(brightness: brightness, contrast: contrast).shade10 as T; - case _ZetaColorProperties.borderSelected: - return ZetaColorBase.cool.apply(brightness: brightness, contrast: contrast).shade90 as T; - case _ZetaColorProperties.borderDisabled: - return ZetaColorBase.cool.apply(brightness: brightness, contrast: contrast).shade30 as T; - case _ZetaColorProperties.borderSubtle: - return ZetaColorBase.cool.apply(brightness: brightness, contrast: contrast).shade40 as T; - case _ZetaColorProperties.borderDefault: - return ZetaColorBase.cool.apply(brightness: brightness, contrast: contrast).shade50 as T; - case _ZetaColorProperties.surfacePrimary: - return (brightness == Brightness.light ? ZetaColorBase.white : ZetaColorBase.black) as T; - } - } -} diff --git a/lib/src/theme/colors_base.dart b/lib/src/theme/colors_base.dart deleted file mode 100644 index b8918412..00000000 --- a/lib/src/theme/colors_base.dart +++ /dev/null @@ -1,267 +0,0 @@ -import 'package:flutter/material.dart'; -import '../../zeta_flutter.dart'; - -/// Default set of Zeta Colors that can be used to make a [ZetaColors] instance. -/// -/// One of more of these can be overridden when constructing a [ZetaColors] instance. -/// -/// * [blue] -/// * [green] -/// * [red] -/// * [orange] -/// * [purple] -/// * [yellow] -/// * [teal] -/// * [pink] -/// * [warm] -/// * [pure] -/// * [cool]. -/// {@category Theme} -abstract final class ZetaColorBase { - /// Link color for light mode. - @Deprecated('This color has been deprecated as of v0.10.0') - static const Color linkLight = Color(0xFF0257AC); - - /// Visited link color for light mode. - @Deprecated('This color has been deprecated as of v0.10.0') - static const Color linkVisitedLight = Color(0xFF205386); - - /// Link color for dark mode. - @Deprecated('This color has been deprecated as of v0.10.0') - static const Color linkDark = Color(0xFF7ABDFF); - - /// Visited link color for dark mode. - @Deprecated('This color has been deprecated as of v0.10.0') - static const Color linkVisitedDark = Color(0xFF47A3FF); - - /// Default shadow color. - @Deprecated('This color has been deprecated as of v0.10.0') - static const Color shadowLight = Color(0x1A49505E); - - /// Default shadow color. - @Deprecated('This color has been deprecated as of v0.10.0') - static const Color shadowDark = Color(0x1A49505E); - - /// Grey warm swatch - @Deprecated('Use warm instead. ' 'This color has been deprecated as of v0.10.0.') - static const ZetaColorSwatch greyWarm = ZetaColorBase.warm; - - /// Grey cool swatch - @Deprecated('Use cool instead. ' 'This color has been deprecated as of v0.10.0.') - static const ZetaColorSwatch greyCool = ZetaColorBase.cool; - - /// Pure - /// - /// {@macro zeta-color-swatch} - static const ZetaColorSwatch pure = ZetaColorSwatch( - primary: 0xFF151519, - swatch: { - 0: Color(0xFFffffff), - 500: Color(0xFF151519), - 1000: Color(0xFF151519), - }, - ); - - /// Cool - /// - /// {@macro zeta-color-swatch} - static const ZetaColorSwatch cool = ZetaColorSwatch( - primary: 0xFF7a8190, - swatch: { - 10: Color(0xFFf8fbff), - 20: Color(0xFFf3f6fa), - 30: Color(0xFFe0e3e9), - 40: Color(0xFFced2db), - 50: Color(0xFF8d95a3), - 60: Color(0xFF7a8190), - 70: Color(0xFF545963), - 80: Color(0xFF2c2f36), - 90: Color(0xFF1d1e23), - 100: Color(0xFF0c0d0e), - }, - ); - - /// Warm - /// - /// {@macro zeta-color-swatch} - static const ZetaColorSwatch warm = ZetaColorSwatch( - primary: 0xFF858585, - swatch: { - 10: Color(0xFFfafafa), - 20: Color(0xFFf6f6f6), - 30: Color(0xFFececec), - 40: Color(0xFFdedede), - 50: Color(0xFFb9b9b9), - 60: Color(0xFF858585), - 70: Color(0xFF585858), - 80: Color(0xFF313131), - 90: Color(0xFF1d1e23), - 100: Color(0xFF151519), - }, - ); - - /// Blue - /// - /// {@macro zeta-color-swatch} - static const ZetaColorSwatch blue = ZetaColorSwatch( - primary: 0xFF0073e6, - swatch: { - 10: Color(0xFFf1f8ff), - 20: Color(0xFFe2f1ff), - 30: Color(0xFFb7dbff), - 40: Color(0xFF7ebeff), - 50: Color(0xFF599fe5), - 60: Color(0xFF0073e6), - 70: Color(0xFF0061c2), - 80: Color(0xFF004d99), - 90: Color(0xFF002c58), - 100: Color(0xFF101b25), - }, - ); - - /// Green - /// - /// {@macro zeta-color-swatch} - static const ZetaColorSwatch green = ZetaColorSwatch( - primary: 0xFF00864f, - swatch: { - 10: Color(0xFFecfff7), - 20: Color(0xFFd8ffef), - 30: Color(0xFFbeefdb), - 40: Color(0xFF84dab6), - 50: Color(0xFF67b796), - 60: Color(0xFF00864f), - 70: Color(0xFF006d3f), - 80: Color(0xFF005f38), - 90: Color(0xFF00331e), - 100: Color(0xFF081711), - }, - ); - - /// Red - /// - /// {@macro zeta-color-swatch} - static const ZetaColorSwatch red = ZetaColorSwatch( - primary: 0xFFd70015, - swatch: { - 10: Color(0xFFfff0f1), - 20: Color(0xFFffe1e4), - 30: Color(0xFFffb3bb), - 40: Color(0xFFf98c97), - 50: Color(0xFFf36170), - 60: Color(0xFFd70015), - 70: Color(0xFFb50012), - 80: Color(0xFF8f000e), - 90: Color(0xFF520008), - 100: Color(0xFF220f11), - }, - ); - - /// Orange - /// - /// {@macro zeta-color-swatch} - static const ZetaColorSwatch orange = ZetaColorSwatch( - primary: 0xFFae6500, - swatch: { - 10: Color(0xFFfef2e2), - 20: Color(0xFFffe7c6), - 30: Color(0xFFffd292), - 40: Color(0xFFffb348), - 50: Color(0xFFf5a230), - 60: Color(0xFFae6500), - 70: Color(0xFF965802), - 80: Color(0xFF764502), - 90: Color(0xFF402600), - 100: Color(0xFF1e1100), - }, - ); - - /// Purple - /// - /// {@macro zeta-color-swatch} - static const ZetaColorSwatch purple = ZetaColorSwatch( - primary: 0xFF7e0cff, - swatch: { - 10: Color(0xFFf7f0ff), - 20: Color(0xFFefe1ff), - 30: Color(0xFFdcc1fb), - 40: Color(0xFFcea4ff), - 50: Color(0xFF9b71df), - 60: Color(0xFF7e0cff), - 70: Color(0xFF6400d6), - 80: Color(0xFF43008f), - 90: Color(0xFF260052), - 100: Color(0xFF180f22), - }, - ); - - /// Yellow - /// - /// {@macro zeta-color-swatch} - static const ZetaColorSwatch yellow = ZetaColorSwatch( - primary: 0xFF8d7400, - swatch: { - 10: Color(0xFFfff7d4), - 20: Color(0xFFffea89), - 30: Color(0xFFf3d961), - 40: Color(0xFFdbb91c), - 50: Color(0xFFc2a728), - 60: Color(0xFF8d7400), - 70: Color(0xFF766200), - 80: Color(0xFF564908), - 90: Color(0xFF352b00), - 100: Color(0xFF181400), - }, - ); - - /// Teal - /// - /// {@macro zeta-color-swatch} - static const ZetaColorSwatch teal = ZetaColorSwatch( - primary: 0xFF1a8080, - swatch: { - 10: Color(0xFFecffff), - 20: Color(0xFFd9ffff), - 30: Color(0xFFbcfbfb), - 40: Color(0xFF91e1e1), - 50: Color(0xFF65c4c4), - 60: Color(0xFF1a8080), - 70: Color(0xFF017474), - 80: Color(0xFF005b5b), - 90: Color(0xFF003535), - 100: Color(0xFF0a1616), - }, - ); - - /// Pink - /// - /// {@macro zeta-color-swatch} - static const ZetaColorSwatch pink = ZetaColorSwatch( - primary: 0xFFd30589, - swatch: { - 10: Color(0xFFfff7fc), - 20: Color(0xFFffe3f5), - 30: Color(0xFFffbee7), - 40: Color(0xFFff94d8), - 50: Color(0xFFee78c3), - 60: Color(0xFFd30589), - 70: Color(0xFFab006d), - 80: Color(0xFF840054), - 90: Color(0xFF640040), - 100: Color(0xFF2e001e), - }, - ); - - /// Pure white. - /// - /// Typically reserved for backgrounds. - static const Color white = Color(0xFFFFFFFF); - - /// Pure black. - /// - /// Sparingly used. - static const Color black = Color(0xFF000000); - - /// Default text color. - static const Color text = Color(0xFF1D1E23); -} diff --git a/lib/src/theme/contrast.dart b/lib/src/theme/contrast.dart index d406dc38..69b2e2ae 100644 --- a/lib/src/theme/contrast.dart +++ b/lib/src/theme/contrast.dart @@ -24,108 +24,6 @@ extension AccessibilityIndices on ZetaContrast { } } - /// Returns the color index value for a surface depending on the ZetaContrast value. - /// - /// For [ZetaContrast.aa], it returns 60. - /// For [ZetaContrast.aaa], it returns 80. - int get text { - switch (this) { - case ZetaContrast.aa: - return 60; - case ZetaContrast.aaa: - return 80; - } - } - - /// Returns the color index value for an icon depending on the ZetaContrast value. - /// - /// For [ZetaContrast.aa], it returns 60. - /// For [ZetaContrast.aaa], it returns 80. - int get icon { - switch (this) { - case ZetaContrast.aa: - return 60; - case ZetaContrast.aaa: - return 80; - } - } - - /// Returns the color index value for a hover state depending on the ZetaContrast value. - /// - /// For [ZetaContrast.aa], it returns 70. - /// For [ZetaContrast.aaa], it returns 90. - int get hover { - switch (this) { - case ZetaContrast.aa: - return 70; - case ZetaContrast.aaa: - return 90; - } - } - - /// Returns the color index value for a selected state depending on the ZetaContrast value. - /// - /// For [ZetaContrast.aa], it returns 80. - /// For [ZetaContrast.aaa], it returns 100. - int get selected { - switch (this) { - case ZetaContrast.aa: - return 80; - case ZetaContrast.aaa: - return 100; - } - } - - /// Returns the color index value for a focus state depending on the ZetaContrast value. - /// - /// For [ZetaContrast.aa], it returns 80. - /// For [ZetaContrast.aaa], it returns 100. - int get focus { - switch (this) { - case ZetaContrast.aa: - return 80; - case ZetaContrast.aaa: - return 100; - } - } - - /// Returns the color index value for a border depending on the ZetaContrast value. - /// - /// For [ZetaContrast.aa], it returns 60. - /// For [ZetaContrast.aaa], it returns 80. - int get border { - switch (this) { - case ZetaContrast.aa: - return 60; - case ZetaContrast.aaa: - return 80; - } - } - - /// Returns the color index value for a subtle visual element depending on the ZetaContrast value. - /// - /// For both [ZetaContrast.aa] and [ZetaContrast.aaa], it returns 40. - int get subtle { - switch (this) { - case ZetaContrast.aa: - return 40; - case ZetaContrast.aaa: - return 60; - } - } - - /// Returns the color index value for a surface depending on the ZetaContrast value. - /// - /// For both [ZetaContrast.aa] and [ZetaContrast.aaa], it returns 10. - int get surface { - switch (this) { - case ZetaContrast.aa: - return 10; - case ZetaContrast.aaa: - return 10; - } - } - /// Returns the target contrast value. /// /// The getter, `targetContrast`, returns a double value that represents the diff --git a/lib/src/theme/custom_theme.dart b/lib/src/theme/custom_theme.dart new file mode 100644 index 00000000..8edee88c --- /dev/null +++ b/lib/src/theme/custom_theme.dart @@ -0,0 +1,51 @@ +import 'package:flutter/material.dart'; + +import 'color_swatch.dart'; + +/// A custom theme that can be used to define custom colors for the app. +class ZetaCustomTheme { + /// Constructs a [ZetaCustomTheme]. + /// To define every shade of a color, provide a [ZetaColorSwatch] or a [MaterialColor]. + /// If only a [Color] is provided, a [ZetaColorSwatch] will be automatically generated. + ZetaCustomTheme({ + required this.id, + Color? primary, + Color? primaryDark, + Color? secondary, + Color? secondaryDark, + }) : assert( + !(primaryDark != null && primary == null), + 'Primary dark cannot be set without a primary color', + ), + assert( + !(secondaryDark != null && secondary == null), + 'Secondary dark cannot be set without a secondary color', + ), + primary = primary != null ? ZetaColorSwatch.fromColor(primary) : null, + primaryDark = primaryDark != null + ? ZetaColorSwatch.fromColor(primaryDark) + : primary != null + ? ZetaColorSwatch.inverse(ZetaColorSwatch.fromColor(primary)) + : null, + secondary = secondary != null ? ZetaColorSwatch.fromColor(secondary) : null, + secondaryDark = secondaryDark != null + ? ZetaColorSwatch.fromColor(secondaryDark) + : secondary != null + ? ZetaColorSwatch.inverse(ZetaColorSwatch.fromColor(secondary)) + : null; + + /// The ID of the custom theme. + final String id; + + /// The primary color of the custom theme. + final ZetaColorSwatch? primary; + + /// The dark primary color of the custom theme. + final ZetaColorSwatch? primaryDark; + + /// The secondary color of the custom theme. + final ZetaColorSwatch? secondary; + + /// The dark secondary color of the custom theme. + final ZetaColorSwatch? secondaryDark; +} diff --git a/lib/src/theme/theme.dart b/lib/src/theme/theme.dart index 61602f83..a9cabf84 100644 --- a/lib/src/theme/theme.dart +++ b/lib/src/theme/theme.dart @@ -1,9 +1,9 @@ +export 'breakpoints.dart'; export 'color_extensions.dart'; -export 'color_scheme.dart'; export 'color_swatch.dart'; export 'constants.dart'; export 'contrast.dart'; -export 'theme_data.dart'; +export 'custom_theme.dart'; export 'theme_service.dart'; export 'tokens.dart'; export 'typography.dart'; diff --git a/lib/src/theme/theme_data.dart b/lib/src/theme/theme_data.dart deleted file mode 100644 index 45e0fd83..00000000 --- a/lib/src/theme/theme_data.dart +++ /dev/null @@ -1,94 +0,0 @@ -import 'package:equatable/equatable.dart'; -import 'package:flutter/material.dart'; - -import 'color_extensions.dart'; -import 'colors.dart'; -import 'constants.dart'; -import 'contrast.dart'; - -export 'breakpoints.dart'; -export 'colors.dart'; -export 'colors_base.dart'; -export 'constants.dart'; - -/// A representation of the Zeta theme data. -/// -/// This class encapsulates the colors and fonts used for the Zeta theme in both light and dark modes. -/// {@category Theme} -@immutable -class ZetaThemeData extends Equatable { - /// Constructs a [ZetaThemeData]. - /// - /// If [primary] and/or [secondary] colors are provided, they will be used to create the light and dark Zeta color palettes. - ZetaThemeData({ - this.fontFamily = kZetaFontFamily, - this.identifier = 'default', - ZetaContrast contrast = ZetaContrast.aa, - ZetaColors? colorsLight, - ZetaColors? colorsDark, - Color? primary, - Color? secondary, - }) : _colorsDark = (primary != null - ? ZetaColors.dark( - contrast: contrast, - primary: primary.zetaColorSwatch, - secondary: secondary?.zetaColorSwatch, - ) - : (colorsDark ?? ZetaColors.dark())) - .apply(contrast: contrast), - _colorsLight = (primary != null - ? ZetaColors.light( - contrast: contrast, - primary: primary.zetaColorSwatch, - secondary: secondary?.zetaColorSwatch, - ) - : (colorsLight ?? ZetaColors.light())) - .apply(contrast: contrast); - - /// The font family used in the Zeta theme. - /// - /// Defaults to [kZetaFontFamily] if not provided. - final String fontFamily; - - /// An Identifier cab be assigned to identify the theme uniquely. - /// - /// It can be useful in case selected theme need to be displayed. - /// - /// Defaults to 'default'. - final String identifier; - - final ZetaColors _colorsLight; - - /// The colors used for the light mode of the Zeta theme. - /// - /// Defaults to a light mode color palette with default Zeta colors if not explicitly provided. - ZetaColors get colorsLight => _colorsLight; - - final ZetaColors _colorsDark; - - /// The colors used for the dark mode of the Zeta theme. - /// - /// Defaults to a dark mode color palette with default Zeta colors if not explicitly provided. - ZetaColors get colorsDark => _colorsDark; - - /// Applies the given [contrast] to the current [ZetaThemeData] and returns a new [ZetaThemeData] with the updated contrast. - ZetaThemeData apply({ - required ZetaContrast contrast, - }) { - return ZetaThemeData( - contrast: contrast, - identifier: identifier, - fontFamily: fontFamily, - colorsDark: colorsDark, - colorsLight: colorsLight, - ); - } - - @override - List get props => [ - fontFamily, - identifier, - _colorsLight, - _colorsDark, - ]; -} diff --git a/lib/src/theme/theme_service.dart b/lib/src/theme/theme_service.dart index fc2d7af0..b393a979 100644 --- a/lib/src/theme/theme_service.dart +++ b/lib/src/theme/theme_service.dart @@ -1,13 +1,47 @@ +import 'package:equatable/equatable.dart'; import 'package:flutter/material.dart'; +import 'package:shared_preferences/shared_preferences.dart'; import 'contrast.dart'; -import 'theme_data.dart'; +const String _kThemeMode = 'themeMode'; +const String _kContrast = 'contrast'; +const String _kThemeId = 'theme_id'; +const String _kFontFamily = 'fontFamily'; + +/// `ZetaThemeData` is a class that holds the theme data to be stored with the theme service. +class ZetaThemeServiceData extends Equatable { + /// Constructs a [ZetaThemeServiceData]. + /// + /// All fields are optional. If null, defaults will be used. + const ZetaThemeServiceData({this.themeId, this.themeMode, this.contrast, this.fontFamily}); + + /// The unique identifier for the custom theme data. + final String? themeId; + + /// The theme mode of the Zeta theme. + final ThemeMode? themeMode; + + /// The contrast of the Zeta theme. + final ZetaContrast? contrast; + + /// The font family of the Zeta theme. + final String? fontFamily; + + @override + List get props => [themeId, themeMode, contrast, fontFamily]; +} + +// TODO(colors): Re-add custom font somewhere (not here) +// TODO(colors): Add tests /// `ZetaThemeService` is an abstract class. /// It provides the structure for loading and saving themes in Zeta application. /// {@category Theme} abstract class ZetaThemeService { + /// Constructor for `ZetaThemeService`. + const ZetaThemeService(); + /// Asynchronously load the theme data. /// /// This method returns a `Future` that when complete will produce a @@ -19,8 +53,8 @@ abstract class ZetaThemeService { /// /// `ZetaContrast` defines different contrast styles to use across the application. /// - /// Returns a Future `(ZetaThemeData?, ThemeMode?, ZetaContrast?)`. - Future<(ZetaThemeData?, ThemeMode?, ZetaContrast?)> loadTheme(); + /// Returns a Future [ZetaThemeServiceData]. + Future loadTheme(); /// Saves the provided theme data as the application's theme. /// @@ -30,9 +64,57 @@ abstract class ZetaThemeService { /// /// Returns a `Future` that completes when the theme data has been successfully saved. - Future saveTheme({ - required ZetaThemeData themeData, - required ThemeMode themeMode, - required ZetaContrast contrast, - }); + Future saveTheme({required ZetaThemeServiceData themeData}); +} + +/// A default implementation of `ZetaThemeService` that uses `SharedPreferences` to store the theme data. +class ZetaDefaultThemeService extends ZetaThemeService { + /// Constructor for `ZetaDefaultThemeService`. + const ZetaDefaultThemeService(); + + @override + Future loadTheme() async { + final preferences = await SharedPreferences.getInstance(); + + final modeString = preferences.getString(_kThemeMode); + + final themeMode = modeString == ThemeMode.light.name + ? ThemeMode.light + : modeString == ThemeMode.dark.name + ? ThemeMode.dark + : ThemeMode.system; + + final contrastString = preferences.getString(_kContrast); + final contrast = contrastString == ZetaContrast.aaa.name ? ZetaContrast.aaa : ZetaContrast.aa; + + final themeId = preferences.getString(_kThemeId); + final fontFamily = preferences.getString(_kFontFamily); + + return ZetaThemeServiceData( + themeMode: themeMode, + contrast: contrast, + themeId: themeId, + fontFamily: fontFamily, + ); + } + + @override + Future saveTheme({required ZetaThemeServiceData themeData}) async { + final preferences = await SharedPreferences.getInstance(); + final List> futures = []; + + if (themeData.fontFamily != null) { + futures.add(preferences.setString(_kFontFamily, themeData.fontFamily!)); + } + if (themeData.themeMode != null) { + futures.add(preferences.setString(_kThemeMode, themeData.themeMode!.name)); + } + if (themeData.contrast != null) { + futures.add(preferences.setString(_kContrast, themeData.contrast!.name)); + } + if (themeData.themeId != null) { + futures.add(preferences.setString(_kThemeId, themeData.themeId!)); + } + await Future.wait(futures); + } } diff --git a/lib/src/theme/tokens.dart b/lib/src/theme/tokens.dart index 06b468a8..63dcd427 100644 --- a/lib/src/theme/tokens.dart +++ b/lib/src/theme/tokens.dart @@ -1,321 +1,3 @@ -import 'package:flutter/material.dart'; - -/// Tokens that are used for spacing. -/// -/// Values are doubles, and can be used for padding, margins and other spacings. -/// -/// Semantic zeta spacings. -/// {@category Theme} -@Deprecated('Use Zeta.of(context).spacing instead ' 'This has been deprecated as of 0.16.0') -class ZetaSpacing { - /// No spacing => 0px. - static const double none = ZetaSpacingBase.x0; - - /// Minimum spacing => 4px. - static const double minimum = ZetaSpacingBase.x1; - - /// Small spacing => 8px. - static const double small = ZetaSpacingBase.x2; - - /// Medium spacing => 12px. - static const double medium = ZetaSpacingBase.x3; - - /// Large spacing => 16px. - static const double large = ZetaSpacingBase.x4; - - /// 1xl spacing => 20px. - static const double xl_1 = ZetaSpacingBase.x5; - - /// 2xl spacing => 24px. - static const double xl_2 = ZetaSpacingBase.x6; - - /// 3xl spacing => 28px. - static const double xl_3 = ZetaSpacingBase.x7; - - /// 4xl spacing => 32px. - static const double xl_4 = ZetaSpacingBase.x8; - - /// 5xl spacing => 36px. - static const double xl_5 = ZetaSpacingBase.x9; - - /// 6xl spacing => 40px. - static const double xl_6 = ZetaSpacingBase.x10; - - /// 7xl spacing => 44px. - static const double xl_7 = ZetaSpacingBase.x11; - - /// 8xl spacing => 48px. - static const double xl_8 = ZetaSpacingBase.x12; - - /// 9xl spacing => 64px. - static const double xl_9 = ZetaSpacingBase.x13; - - /// 10xl spacing => 80px. - static const double xl_10 = ZetaSpacingBase.x14; - - /// 11xl spacing => 96px - static const double xl_11 = ZetaSpacingBase.x15; - - /// Base multiplier used to calculate spacing values. - @Deprecated('Use minimum instead ' 'This size has been deprecated as of 0.11.0') - static const double spacingBaseMultiplier = 4; - - /// 2dp space. - @Deprecated('Use ZetaSpacingBase.x0_5 instead ' 'This size has been deprecated as of 0.11.0') - static const double x0_5 = spacingBaseMultiplier * 0.5; - - /// 4dp space. - @Deprecated('Use minimum instead ' 'This size has been deprecated as of 0.11.0') - static const double x1 = spacingBaseMultiplier; - - /// 4dp space. - @Deprecated('Use minimum instead ' 'This size has been deprecated as of 0.11.0') - static const double xxs = spacingBaseMultiplier; - - /// 8dp space. - @Deprecated('Use small instead ' 'This size has been deprecated as of 0.11.0') - static const double x2 = spacingBaseMultiplier * 2; - - /// 8dp space. - @Deprecated('Use small instead ' 'This size has been deprecated as of 0.11.0') - static const double xs = spacingBaseMultiplier * 2; - - /// 10dp space. - @Deprecated('Use ZetaSpacingBase.x2_5 instead ' 'This size has been deprecated as of 0.11.0') - static const double x2_5 = spacingBaseMultiplier * 2.5; - - /// 12dp space. - @Deprecated('Use medium instead ' 'This size has been deprecated as of 0.11.0') - static const double x3 = spacingBaseMultiplier * 3; - - /// 12dp space. - @Deprecated('Use medium instead ' 'This size has been deprecated as of 0.11.0') - static const double s = spacingBaseMultiplier * 3; - - /// 14dp space. - @Deprecated('Use ZetaSpacingBase.x3_5 instead ' 'This size has been deprecated as of 0.11.0') - static const double x3_5 = spacingBaseMultiplier * 3.5; - - /// 16dp space. - @Deprecated('Use large instead ' 'This size has been deprecated as of 0.11.0') - static const double x4 = spacingBaseMultiplier * 4; - - /// 16dp space. - @Deprecated('Use large instead ' 'This size has been deprecated as of 0.11.0') - static const double b = spacingBaseMultiplier * 4; - - /// 20dp space. - @Deprecated('Use xl_1 instead ' 'This size has been deprecated as of 0.11.0') - static const double x5 = spacingBaseMultiplier * 5; - - /// 24dp space. - @Deprecated('Use xL2 instead ' 'This size has been deprecated as of 0.11.0') - static const double x6 = spacingBaseMultiplier * 6; - - /// 24dp space. - @Deprecated('Use xL2 instead ' 'This size has been deprecated as of 0.11.0') - static const double m = spacingBaseMultiplier * 6; - - /// 28dp space. - @Deprecated('Use xL3 instead ' 'This size has been deprecated as of 0.11.0') - static const double x7 = spacingBaseMultiplier * 7; - - /// 30dp space. - @Deprecated('Use ZetaSpacingBase.x7_5 instead ' 'This size has been deprecated as of 0.11.0') - static const double x7_5 = spacingBaseMultiplier * 7.5; - - /// 32dp space. - @Deprecated('Use xL4 instead ' 'This size has been deprecated as of 0.11.0') - static const double x8 = spacingBaseMultiplier * 8; - - /// 32dp space. - @Deprecated('Use xL4 instead ' 'This size has been deprecated as of 0.11.0') - static const double l = spacingBaseMultiplier * 8; - - /// 36dp space. - @Deprecated('Use xL5 instead ' 'This size has been deprecated as of 0.11.0') - static const double x9 = spacingBaseMultiplier * 9; - - /// 40dp space. - @Deprecated('Use xL6 instead ' 'This size has been deprecated as of 0.11.0') - static const double x10 = spacingBaseMultiplier * 10; - - /// 44dp space. - @Deprecated('Use xL7 instead ' 'This size has been deprecated as of 0.11.0') - static const double x11 = spacingBaseMultiplier * 11; - - /// 48dp space. - @Deprecated('Use xL8 instead ' 'This size has been deprecated as of 0.11.0') - static const double x12 = spacingBaseMultiplier * 12; - - /// 52dp Space. - @Deprecated('This size has been deprecated as of 0.11.0') - static const double x13 = spacingBaseMultiplier * 13; - - /// 56dp Space. - @Deprecated('Use ZetaSpacingBase.x12_5 instead ' 'This size has been deprecated as of 0.11.0') - static const double x14 = spacingBaseMultiplier * 14; - - /// 64dp space. - @Deprecated('Use xL9 instead ' 'This size has been deprecated as of 0.11.0') - static const double x16 = spacingBaseMultiplier * 16; - - /// 64dp space. - @Deprecated('Use xL9 instead ' 'This size has been deprecated as of 0.11.0') - static const double xl = spacingBaseMultiplier * 16; - - /// 80dp space. - @Deprecated('Use xL10 instead ' 'This size has been deprecated as of 0.11.0') - static const double x20 = spacingBaseMultiplier * 20; - - /// 80dp space. - @Deprecated('Use xL10 instead ' 'This size has been deprecated as of 0.11.0') - static const double xxl = spacingBaseMultiplier * 20; - - /// 96dp space. - @Deprecated('Use xL11 instead ' 'This size has been deprecated as of 0.11.0') - static const double x24 = spacingBaseMultiplier * 24; - - /// 96dp space. - @Deprecated('Use xL11 instead ' 'This size has been deprecated as of 0.11.0') - static const double xxxl = spacingBaseMultiplier * 24; - - /// 120dp space - @Deprecated('Use ZetaSpacingBase.x30 instead ' 'This size has been deprecated as of 0.11.0') - static const double x30 = spacingBaseMultiplier * 30; - - /// 200dp space - @Deprecated('Use ZetaSpacingBase.x50 instead ' 'This size has been deprecated as of 0.11.0') - static const double x50 = spacingBaseMultiplier * 50; -} - -/// Semantic zeta radii. -/// {@category Theme} -@Deprecated('Use Zeta.of(contest).radius instead ' 'This size has been deprecated as of 0.11.0') -class ZetaRadius { - /// No radius => 0px radius. - static const BorderRadius none = BorderRadius.zero; - - /// Minimal radius => 4px radius. - static const BorderRadius minimal = ZetaRadiusBase.s; - - /// Rounded radius => 8px radius. - static const BorderRadius rounded = ZetaRadiusBase.m; - - /// Large radius => 16px radius. - static const BorderRadius large = ZetaRadiusBase.l; - - /// xl radius => 24px radius. - static const BorderRadius xl = ZetaRadiusBase.xl; - - /// Full radius => 360px radius. - static const BorderRadius full = ZetaRadiusBase.x4; - - /// Wide border radius; 24px radius. - @Deprecated('Use xl instead ' 'This size has been deprecated as of 0.11.0') - static const BorderRadius wide = BorderRadius.all(Radius.circular(ZetaSpacing.m)); -} - -///Tokens that are used for Spacing -///{@category Theme} -@Deprecated('Use Zeta.of(context).spacing instead ' 'This has been deprecated as of 0.16.0') -class ZetaSpacingBase { - /// 0dp space - static const double x0 = 0; - - /// 2dp space - static const double x0_5 = 2; - - /// 4dp space - static const double x1 = 4; - - /// 8dp space - static const double x2 = 8; - - /// 10dp space - static const double x2_5 = 10; - - /// 12dp space - static const double x3 = 12; - - /// 14dp space. - static const double x3_5 = 14; - - /// 16dp space - static const double x4 = 16; - - /// 20dp space - static const double x5 = 20; - - /// 24dp space - static const double x6 = 24; - - /// 28dp space - static const double x7 = 28; - - /// 30dp space. - static const double x7_5 = 30; - - /// 32dp space - static const double x8 = 32; - - /// 36dp space - static const double x9 = 36; - - /// 40dp space - static const double x10 = 40; - - /// 44dp space - static const double x11 = 44; - - /// 48dp space - static const double x12 = 48; - - /// 56dp space - static const double x12_5 = 56; - - /// 64dp space - static const double x13 = 64; - - /// 80dp space - static const double x14 = 80; - - /// 96dp space - static const double x15 = 96; - - /// 120dp space - static const double x30 = 120; - - /// 200dp space - static const double x50 = 200; -} - -///Tokens that are used for Border Radius -///{@category Theme} -@Deprecated('Use Zeta.of(contest).radius instead ' 'This size has been deprecated as of 0.11.0') -class ZetaRadiusBase { - /// 4px radius - static const BorderRadius s = BorderRadius.all(Radius.circular(4)); - - /// 8px radius - static const BorderRadius m = BorderRadius.all(Radius.circular(8)); - - /// 16px radius - static const BorderRadius l = BorderRadius.all(Radius.circular(16)); - - /// 24px radius - static const BorderRadius xl = BorderRadius.all(Radius.circular(24)); - - /// 32px radius - static const BorderRadius x2 = BorderRadius.all(Radius.circular(32)); - - /// 128px radius - static const BorderRadius x3 = BorderRadius.all(Radius.circular(128)); - - /// 360px radius - static const BorderRadius x4 = BorderRadius.all(Radius.circular(360)); -} - /// Tokenised durations used for animations /// {@category Theme} class ZetaAnimationLength { diff --git a/lib/src/utils/extensions.dart b/lib/src/utils/extensions.dart index 942adbda..8ba366f5 100644 --- a/lib/src/utils/extensions.dart +++ b/lib/src/utils/extensions.dart @@ -1,7 +1,5 @@ import 'package:flutter/material.dart'; -import '../../zeta_flutter.dart'; - /// Extension to add dividers to any view that can take an iterable. /// /// Iterable can be converted to a list with [toList]. @@ -69,26 +67,6 @@ extension NumExtensions on num? { } } -/// Extensions on [ZetaWidgetStatus]. -extension ColorSwatches on ZetaWidgetStatus { - /// Gets color swatch from [ZetaWidgetStatus] - ZetaColorSwatch colorSwatch(BuildContext context) { - final colors = Zeta.of(context).colors; - switch (this) { - case ZetaWidgetStatus.info: - return colors.surfaceInfo; - case ZetaWidgetStatus.positive: - return colors.surfacePositive; - case ZetaWidgetStatus.warning: - return colors.surfaceWarning; - case ZetaWidgetStatus.negative: - return colors.surfaceNegative; - case ZetaWidgetStatus.neutral: - return colors.cool; - } - } -} - /// Extensions on [String]. extension StringExtensions on String? { /// Returns initials from a name. diff --git a/lib/src/utils/utils.dart b/lib/src/utils/utils.dart index 88621bd1..24e64784 100644 --- a/lib/src/utils/utils.dart +++ b/lib/src/utils/utils.dart @@ -5,4 +5,4 @@ export 'nothing.dart'; export 'platform/platform_is.dart' show PlatformIs; export 'rounded.dart'; export 'zeta.dart'; -export 'zeta_provider.dart'; +export 'zeta_provider.dart' hide InternalProvider, InternalProviderState, generateZetaTheme; diff --git a/lib/src/utils/zeta.dart b/lib/src/utils/zeta.dart index ad6b5be5..79138ef4 100644 --- a/lib/src/utils/zeta.dart +++ b/lib/src/utils/zeta.dart @@ -7,36 +7,37 @@ import '../../zeta_flutter.dart'; /// /// It holds information about the current contrast, theme mode, and theme data. /// The [colors] getter provides the correct color set based on the current theme mode. +/// /// {@category Utils} class Zeta extends InheritedWidget { /// Constructs a [Zeta] widget. - /// - /// The [contrast], [themeMode], [themeData], and [child] arguments are required. const Zeta({ super.key, - required Brightness mediaBrightness, - required this.contrast, - required this.themeMode, - required this.themeData, required super.child, this.rounded = true, - }) : _mediaBrightness = mediaBrightness; - - /// The current contrast setting for the app, which can be one of the predefined - /// values in [ZetaContrast]. - final ZetaContrast contrast; - - /// Specifies the theme mode for the app, which determines how the UI is rendered. - /// - /// It can be one of the values: [ThemeMode.system], [ThemeMode.light], or [ThemeMode.dark]. - final ThemeMode themeMode; - - /// Provides the theme data for the app, which contains all the theming information. - final ZetaThemeData themeData; - - /// Internal property to get the system brightness. - /// Used to determine the theme mode when it's set to [ThemeMode.system]. - final Brightness _mediaBrightness; + this.contrast = ZetaContrast.aa, + this.themeMode = ThemeMode.system, + this.customThemeId, + ZetaPrimitives? customPrimitives, + ZetaSemantics? customSemantics, + // String? fontFamily, + }) : _customPrimitives = customPrimitives, + _customSemantics = customSemantics; + + final ZetaPrimitives? _customPrimitives; + + final ZetaSemantics? _customSemantics; + + /// Primitives used for colors, spacing and radii in the Zeta theme. + ZetaPrimitives get primitives => + _customPrimitives ?? (brightness == Brightness.light ? const ZetaPrimitivesLight() : const ZetaPrimitivesDark()); + + /// Semantics used for colors, spacing and radii in the Zeta theme. + ZetaSemantics get semantics => + _customSemantics ?? + (contrast == ZetaContrast.aa + ? ZetaSemanticsAA(primitives: primitives) + : ZetaSemanticsAAA(primitives: primitives)); /// {@template zeta-component-rounded} /// Sets rounded or sharp border of the containing box and the icon style. @@ -45,61 +46,47 @@ class Zeta extends InheritedWidget { /// {@endtemplate} final bool rounded; + /// The contrast level of the Zeta theme. + /// + /// This will determine the color contrast level of the theme when using default semantics. + final ZetaContrast contrast; + + /// The theme mode of the Zeta theme. + /// It can be set to 'system', 'light', or 'dark'. + /// The default value is 'system'. + final ThemeMode themeMode; + + /// The ID of the current custom theme. + /// Set to null if no custom theme is being used. + final String? customThemeId; + /// Provides the color set based on the current theme mode. /// /// It determines the appropriate color set (light or dark) based on the theme mode /// and system brightness. - ZetaColors get colors { - if (themeMode == ThemeMode.system) { - return _mediaBrightness == Brightness.light ? themeData.colorsLight : themeData.colorsDark; - } else if (themeMode == ThemeMode.light) { - return themeData.colorsLight; - } else { - return themeData.colorsDark; - } - } + ZetaColors get colors => semantics.colors; /// Gets the brightness setting for the current theme. /// /// If the theme mode is set to 'system', it will return the brightness that ties with the device's system theme setting. /// If the theme mode is set to 'light', it always returns `Brightness.light`. /// If neither, it returns `Brightness.dark` by default (i.e., when the theme mode is 'dark'). - Brightness get brightness { - if (themeMode == ThemeMode.system) { - return _mediaBrightness; // Return the current system brightness setting - } else if (themeMode == ThemeMode.light) { - return Brightness.light; // Return the light mode brightness - } else { - return Brightness.dark; // Default: Return the dark mode brightness - } - } + Brightness get brightness => themeMode.brightness; /// Gets the radius values based on the tokens. - ZetaRadiiSemantics get radius => _semantics.radii; + ZetaRadius get radius => semantics.radius; /// Gets the spacing values based on the tokens. - ZetaSpacingSemantics get spacing => _semantics.size; - - /// Gets the [ZetaPrimitives] instance based on the current brightness setting. - /// - /// This is a temporary function used whilst the full implementation of tokens is taking place. - ZetaPrimitives get _primitives => - brightness == Brightness.light ? const ZetaPrimitivesLight() : const ZetaPrimitivesDark(); - - /// Gets the [ZetaSemantics] instance based on the current contrast setting. - /// - /// This is a temporary function used whilst the full implementation of tokens is taking place. - ZetaSemantics get _semantics => contrast == ZetaContrast.aa - ? ZetaSemanticsAA(primitives: _primitives) - : ZetaSemanticsAAA(primitives: _primitives); + ZetaSpacing get spacing => semantics.spacing; @override bool updateShouldNotify(covariant Zeta oldWidget) { return oldWidget.contrast != contrast || + oldWidget.rounded != rounded || oldWidget.themeMode != themeMode || - oldWidget.themeData != themeData || - oldWidget._mediaBrightness != _mediaBrightness || - oldWidget.rounded != rounded; + oldWidget._customPrimitives != _customPrimitives || + oldWidget._customSemantics != _customSemantics || + oldWidget.customThemeId != customThemeId; } /// Fetches the [Zeta] instance from the provided [context]. @@ -133,13 +120,15 @@ class Zeta extends InheritedWidget { void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties - ..add(EnumProperty('themeMode', themeMode)) - ..add(EnumProperty('contrast', contrast)) - ..add(DiagnosticsProperty('themeData', themeData)) ..add(DiagnosticsProperty('rounded', rounded)) ..add(DiagnosticsProperty('colors', colors)) ..add(EnumProperty('brightness', brightness)) - ..add(DiagnosticsProperty('radius', radius)) - ..add(DiagnosticsProperty('spacing', spacing)); + ..add(DiagnosticsProperty('radius', radius)) + ..add(DiagnosticsProperty('spacing', spacing)) + ..add(DiagnosticsProperty('primitives', primitives)) + ..add(DiagnosticsProperty('semantics', semantics)) + ..add(EnumProperty('contrast', contrast)) + ..add(EnumProperty('themeMode', themeMode)) + ..add(StringProperty('customThemeId', customThemeId)); } } diff --git a/lib/src/utils/zeta_provider.dart b/lib/src/utils/zeta_provider.dart index 62ff001f..b99564f3 100644 --- a/lib/src/utils/zeta_provider.dart +++ b/lib/src/utils/zeta_provider.dart @@ -1,5 +1,3 @@ -// ignore_for_file: prefer_function_declarations_over_variables - import 'dart:async'; import 'package:flutter/foundation.dart'; @@ -7,102 +5,64 @@ import 'package:flutter/material.dart'; import '../../zeta_flutter.dart'; -/// A typedef for the ZetaAppBuilder function which passes [BuildContext], [ZetaThemeData], -/// and [ThemeMode] and returns a [Widget]. -typedef ZetaAppBuilder = Widget Function(BuildContext context, ZetaThemeData themeData, ThemeMode themeMode); - /// A typedef for the ZetaAppBuilder function which passes [BuildContext], light [ThemeData], /// dark [ThemeData] and [ThemeMode] and returns a [Widget]. -typedef ZetaBaseAppBuilder = Widget Function( +typedef ZetaAppBuilder = Widget Function( BuildContext context, ThemeData light, ThemeData dark, ThemeMode themeMode, ); -final _emptyBuilder = (_, __, ___) => const Nothing(); -final _emptyBase = (_, __, ___, ____) => const Nothing(); - /// A widget that provides Zeta theming and contrast data down the widget tree. /// {@category Utils} class ZetaProvider extends StatefulWidget with Diagnosticable { /// Constructs a [ZetaProvider] widget. /// /// The [builder] argument is required. The [initialThemeMode], [initialContrast], - /// and [initialThemeData] arguments provide initial values. ZetaProvider({ super.key, required this.builder, - this.initialThemeMode = ThemeMode.system, - this.initialContrast = ZetaContrast.aa, - ZetaThemeData? initialThemeData, - this.themeService, + this.initialThemeMode, + this.initialContrast, + this.themeService = const ZetaDefaultThemeService(), this.initialRounded = true, - }) : initialZetaThemeData = initialThemeData ?? ZetaThemeData(), - baseBuilder = _emptyBase, - initialLightThemeData = null, - initialDarkThemeData = null; - - /// ZetaProvider constructor that returns light and dark [ThemeData]s ready to be consumed. - /// - /// The [builder] argument is required. The [initialThemeMode], [initialContrast], - /// and [initialLightThemeData] arguments provide initial values. - ZetaProvider.base({ - super.key, - required ZetaBaseAppBuilder builder, - this.initialThemeMode = ThemeMode.system, - this.initialContrast = ZetaContrast.aa, - ZetaThemeData? initialZetaThemeData, - this.initialLightThemeData, - this.initialDarkThemeData, - this.initialRounded = true, - }) : baseBuilder = builder, - initialZetaThemeData = initialZetaThemeData ?? ZetaThemeData(), - builder = _emptyBuilder, - themeService = null; + this.customThemes = const [], + this.initialTheme, + this.customLoadingWidget, + }); /// Specifies the initial theme mode for the app. /// /// It can be one of the values: [ThemeMode.system], [ThemeMode.light], or [ThemeMode.dark]. /// Defaults to [ThemeMode.system]. - final ThemeMode initialThemeMode; - - /// Provides the initial theme data for the app. - /// - /// This contains all the theming information. If not provided, - /// it defaults to a basic [ZetaThemeData] instance. - final ZetaThemeData initialZetaThemeData; + final ThemeMode? initialThemeMode; /// Specifies the initial contrast setting for the app. /// /// Defaults to [ZetaContrast.aa]. - final ZetaContrast initialContrast; + final ZetaContrast? initialContrast; /// A builder function to construct the widget tree using the provided theming information. - /// - /// It receives the [BuildContext], [ZetaThemeData], and [ThemeMode] as arguments - /// and is expected to return a [Widget]. final ZetaAppBuilder builder; - /// A builder function to construct the widget tree using the provided theming information. - /// - /// This builder returns light and dark [ThemeData]s ready to be consumed. - final ZetaBaseAppBuilder baseBuilder; - /// A `ZetaThemeService` /// /// It provides the structure for loading and saving themes in Zeta application. - final ZetaThemeService? themeService; - - /// Light [ThemeData] used in [ZetaProvider.base] constructor as the foundation for a custom theme. - final ThemeData? initialLightThemeData; - - /// Dark [ThemeData] used in [ZetaProvider.base] constructor as the foundation for a custom theme. - final ThemeData? initialDarkThemeData; + final ZetaThemeService themeService; /// Sets whether app should start with components in their rounded or sharp variants. final bool initialRounded; + /// A list of custom themes to be used in the app. + final List customThemes; + + /// Specifies the id of the initial custom theme to be used in the app. + final String? initialTheme; + + /// A custom loading widget to be displayed while the theme is being loaded. + final Widget? customLoadingWidget; + @override State createState() => ZetaProviderState(); @@ -110,15 +70,13 @@ class ZetaProvider extends StatefulWidget with Diagnosticable { void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties - ..add(DiagnosticsProperty('themeData', initialZetaThemeData)) ..add(ObjectFlagProperty.has('builder', builder)) ..add(EnumProperty('initialThemeMode', initialThemeMode)) ..add(EnumProperty('initialContrast', initialContrast)) ..add(DiagnosticsProperty('themeService', themeService)) - ..add(ObjectFlagProperty.has('customBuilder', baseBuilder)) - ..add(DiagnosticsProperty('initialThemeData', initialLightThemeData)) ..add(DiagnosticsProperty('initialRounded', initialRounded)) - ..add(DiagnosticsProperty('initialDarkThemeData', initialDarkThemeData)); + ..add(IterableProperty('customThemes', customThemes)) + ..add(StringProperty('initialTheme', initialTheme)); } /// Retrieves the [ZetaProviderState] from the provided context. @@ -149,7 +107,7 @@ class ZetaProvider extends StatefulWidget with Diagnosticable { /// The state associated with [ZetaProvider]. /// {@category Utils} class ZetaProviderState extends State with Diagnosticable, WidgetsBindingObserver { - // Fields for ZetaThemeManager. + bool _gotTheme = false; /// Represents the late initialization of the ZetaContrast value. late ZetaContrast _contrast; @@ -157,8 +115,12 @@ class ZetaProviderState extends State with Diagnosticable, Widgets /// Represents the late initialization of the ThemeMode value. late ThemeMode _themeMode; - /// Represents the late initialization of the ZetaThemeData object. - late ZetaThemeData _zetaThemeData; + Map _customThemes = {}; + + /// The list of custom themes in the app + List get customThemes => _customThemes.values.toList(); + + ZetaCustomTheme? _customTheme; /// Represents the late initialization of the system's current brightness (dark or light mode). late Brightness _platformBrightness; @@ -166,12 +128,6 @@ class ZetaProviderState extends State with Diagnosticable, Widgets /// {@macro zeta-component-rounded} late bool _rounded; - /// Represents the late initialization of the light [ThemeData] object. - late ThemeData? _lightThemeData; - - /// Represents the late initialization of the dark [ThemeData] object. - late ThemeData? _darkThemeData; - /// Represents a nullable brightness value to be used for brightness change debouncing. Brightness? _debounceBrightness; @@ -193,23 +149,46 @@ class ZetaProviderState extends State with Diagnosticable, Widgets // Set the initial brightness with the system's current brightness from the first view of the platform dispatcher. _platformBrightness = MediaQueryData.fromView(PlatformDispatcher.instance.views.first).platformBrightness; + // Sets the initial rounded. + _rounded = widget.initialRounded; + + setCustomThemes(widget.customThemes); + + _customTheme = _customThemes[widget.initialTheme]; + + if (widget.initialThemeMode != null) { + _themeMode = widget.initialThemeMode!; + } + if (widget.initialContrast != null) { + _contrast = widget.initialContrast!; + } + } + + /// Sets the custom themes in the app. + void setCustomThemes(List themes) { + setState(() { + _customThemes = Map.fromEntries(themes.map((theme) => MapEntry(theme.id, theme))); + }); + } + + /// Retrieves the theme values from the shared preferences. + Future getThemeValuesFromPreferences() async { + final ZetaThemeServiceData themeServiceData = await widget.themeService.loadTheme(); + // Set the initial theme mode. - _themeMode = widget.initialThemeMode; + _themeMode = themeServiceData.themeMode ?? widget.initialThemeMode ?? ThemeMode.system; // Set the initial contrast. - _contrast = widget.initialContrast; + _contrast = themeServiceData.contrast ?? widget.initialContrast ?? ZetaContrast.aa; - // Sets the initial rounded. - _rounded = widget.initialRounded; + final loadedTheme = _customThemes[themeServiceData.themeId ?? widget.initialTheme]; - // Apply the initial contrast to the theme data. - _zetaThemeData = widget.initialZetaThemeData.apply(contrast: _contrast); - - // Set the initial light [ThemeData]. - _lightThemeData = widget.initialLightThemeData; + if (loadedTheme != null) { + _customTheme = loadedTheme; + } - // Set the initial light [ThemeData]. - _darkThemeData = widget.initialDarkThemeData; + // Ensure this is only triggered once. + _gotTheme = true; } /// Clean up function to be called when this object is removed from the tree. @@ -259,37 +238,34 @@ class ZetaProviderState extends State with Diagnosticable, Widgets @override Widget build(BuildContext context) { - if (widget.baseBuilder != _emptyBase) { - return Zeta( - themeMode: _themeMode, - themeData: _zetaThemeData, - contrast: _contrast, - mediaBrightness: _platformBrightness, - rounded: _rounded, - child: widget.baseBuilder( - context, - generateZetaTheme( - brightness: Brightness.light, - existingTheme: _lightThemeData, - colorScheme: _lightThemeData?.colorScheme ?? _zetaThemeData.colorsLight.toScheme(), - ), - generateZetaTheme( - brightness: Brightness.dark, - existingTheme: _darkThemeData, - colorScheme: _darkThemeData?.colorScheme ?? _zetaThemeData.colorsDark.toScheme(), - ), - _themeMode, - ), - ); + if ((widget.initialContrast != null && + widget.initialThemeMode != null && + (widget.customThemes.isEmpty || _customThemes[widget.initialTheme] != null)) || + _gotTheme) { + return _getChild(); } - return Zeta( - themeMode: _themeMode, - themeData: _zetaThemeData, + return FutureBuilder( + // ignore: discarded_futures + future: getThemeValuesFromPreferences(), + builder: (BuildContext context, AsyncSnapshot snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return widget.customLoadingWidget ?? const Center(child: CircularProgressIndicator()); + } + + return _getChild(); + }, + ); + } + + Widget _getChild() { + return InternalProvider( contrast: _contrast, + themeMode: _themeMode, rounded: _rounded, - mediaBrightness: _platformBrightness, - child: widget.builder(context, _zetaThemeData, _themeMode), + widget: widget.builder, + customTheme: _customTheme, + customThemes: customThemes, ); } @@ -298,14 +274,10 @@ class ZetaProviderState extends State with Diagnosticable, Widgets super.didUpdateWidget(oldWidget); if (oldWidget.initialContrast != widget.initialContrast || oldWidget.initialThemeMode != widget.initialThemeMode || - oldWidget.initialLightThemeData != widget.initialLightThemeData || - oldWidget.initialZetaThemeData != widget.initialZetaThemeData || oldWidget.initialRounded != widget.initialRounded) { setState(() { - _themeMode = widget.initialThemeMode; - _contrast = widget.initialContrast; - _zetaThemeData = widget.initialZetaThemeData.apply(contrast: _contrast); - _lightThemeData = widget.initialLightThemeData; + _themeMode = widget.initialThemeMode ?? _themeMode; + _contrast = widget.initialContrast ?? _contrast; _rounded = widget.initialRounded; }); } @@ -319,10 +291,14 @@ class ZetaProviderState extends State with Diagnosticable, Widgets }); } - /// Updates the current theme data. - void updateThemeData(ZetaThemeData data) { + /// Updates the current custom theme. + /// The id of the theme must correspond to a [ZetaCustomTheme] object in the [customThemes] list. + /// If [themeId] is null or a corresponding theme cannot be found, the default theme is used. + void updateCustomTheme({ + required String? themeId, + }) { setState(() { - _zetaThemeData = data.apply(contrast: _contrast); + _customTheme = _customThemes[themeId]; _saveThemeChange(); }); } @@ -331,7 +307,6 @@ class ZetaProviderState extends State with Diagnosticable, Widgets void updateContrast(ZetaContrast contrast) { setState(() { _contrast = contrast; - _zetaThemeData = _zetaThemeData.apply(contrast: contrast); _saveThemeChange(); }); } @@ -347,10 +322,12 @@ class ZetaProviderState extends State with Diagnosticable, Widgets void _saveThemeChange() { unawaited( - widget.themeService?.saveTheme( - themeData: _zetaThemeData, - themeMode: _themeMode, - contrast: _contrast, + widget.themeService.saveTheme( + themeData: ZetaThemeServiceData( + themeMode: _themeMode, + contrast: _contrast, + themeId: _customTheme?.id, + ), ), ); } @@ -359,19 +336,109 @@ class ZetaProviderState extends State with Diagnosticable, Widgets void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); properties - ..add(DiagnosticsProperty('themeData', _zetaThemeData)) ..add(EnumProperty('contrast', _contrast)) - ..add(EnumProperty('themeMode', _themeMode)); + ..add(EnumProperty('themeMode', _themeMode)) + ..add(IterableProperty('customThemes', customThemes)) + ..add(DiagnosticsProperty('customTheme', _customTheme)); + } +} + +/// Provider used within ZetaProvider, placed within FutureBuilder to allow time for theme data to be pulled from async function +/// +/// For internal use only. +@visibleForTesting +class InternalProvider extends StatefulWidget { + /// Constructs an [InternalProvider]. + /// + /// For internal use only. + + @visibleForTesting + const InternalProvider({ + super.key, + required this.contrast, + required this.themeMode, + required this.rounded, + required this.widget, + required this.customTheme, + required this.customThemes, + }); + + /// Current custom theme. + final ZetaCustomTheme? customTheme; + + /// List of all custom themes. + final List customThemes; + + /// Represents the late initialization of the ZetaContrast value. + final ZetaContrast contrast; + + /// Current theme mode. + final ThemeMode themeMode; + + /// Current rounded value. + final bool rounded; + + /// Builder + final ZetaAppBuilder widget; + + @override + State createState() => InternalProviderState(); + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties + ..add(EnumProperty('themeMode', themeMode)) + ..add(EnumProperty('contrast', contrast)) + ..add(DiagnosticsProperty('rounded', rounded)) + ..add(ObjectFlagProperty.has('widget', widget)) + ..add(DiagnosticsProperty('customTheme', customTheme)) + ..add(IterableProperty('customThemes', customThemes)); + } +} + +/// State for [InternalProvider]. +/// +/// For internal use only. +@visibleForTesting +class InternalProviderState extends State { + @override + Widget build(BuildContext context) { + return Zeta( + themeMode: widget.themeMode, + contrast: widget.contrast, + customThemeId: widget.customTheme?.id, + rounded: widget.rounded, + customPrimitives: widget.themeMode.isDark + ? ZetaPrimitivesDark( + primary: widget.customTheme?.primaryDark, + secondary: widget.customTheme?.secondaryDark, + ) + : ZetaPrimitivesLight( + primary: widget.customTheme?.primary, + secondary: widget.customTheme?.secondary, + ), + child: Builder( + builder: (context) { + return widget.widget( + context, + generateZetaTheme(brightness: Brightness.light, colorScheme: Zeta.of(context).colors.toColorScheme), + generateZetaTheme(brightness: Brightness.dark, colorScheme: Zeta.of(context).colors.toColorScheme), + widget.themeMode, + ); + }, + ), + ); } } /// Creates a variant of [ThemeData] with added [Zeta] styles. +@visibleForTesting ThemeData generateZetaTheme({ required Brightness brightness, required ColorScheme colorScheme, ThemeData? existingTheme, String? fontFamily, - ZetaThemeData? zetaThemeData, }) { if (existingTheme != null) { final baseThemeData = ThemeData(); @@ -384,14 +451,7 @@ ThemeData generateZetaTheme({ (existingTheme.textTheme.bodyMedium?.fontFamily == baseThemeData.textTheme.bodyMedium?.fontFamily ? kZetaFontFamily : existingTheme.textTheme.bodyMedium?.fontFamily), - scaffoldBackgroundColor: [ - Colors.grey[850]!, - Colors.grey[50]!, - baseThemeData.scaffoldBackgroundColor, - baseThemeData.colorScheme.surface, - ].any((e) => e == existingTheme.scaffoldBackgroundColor) - ? colorScheme.surfaceTertiary - : existingTheme.scaffoldBackgroundColor, + scaffoldBackgroundColor: existingTheme.scaffoldBackgroundColor, colorScheme: ((existingTheme.colorScheme == baseThemeData.colorScheme ? null : existingTheme.colorScheme) ?? colorScheme) .copyWith(brightness: brightness), @@ -478,14 +538,8 @@ ThemeData generateZetaTheme({ useMaterial3: true, fontFamily: fontFamily ?? kZetaFontFamily, brightness: brightness, - scaffoldBackgroundColor: colorScheme.surfaceTertiary, colorScheme: colorScheme.copyWith(brightness: brightness), textTheme: zetaTextTheme, - iconTheme: IconThemeData( - size: kZetaIconSize, - color: (zetaThemeData != null - ? (brightness == Brightness.dark ? zetaThemeData.colorsDark : zetaThemeData.colorsLight).iconDefault - : colorScheme.onSurface), - ), + iconTheme: const IconThemeData(size: kZetaIconSize), ); } diff --git a/pubspec.yaml b/pubspec.yaml index dc28673a..93f4b34b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -28,6 +28,7 @@ dependencies: flutter_slidable: ^3.1.0 intl: ^0.19.0 mask_text_input_formatter: ^2.9.0 + shared_preferences: ^2.3.2 web: ^1.0.0 dev_dependencies: diff --git a/test/src/components/accordion/accordion_test.dart b/test/src/components/accordion/accordion_test.dart index 6ad08458..c170b53a 100644 --- a/test/src/components/accordion/accordion_test.dart +++ b/test/src/components/accordion/accordion_test.dart @@ -72,90 +72,90 @@ void main() { // Verify that the textButton color matches the hover color expect( textButton.style!.overlayColor?.resolve({WidgetState.hovered}), - ZetaColorBase.cool.shade20, + const ZetaPrimitivesLight().cool.shade20, ); expect( textButton.style!.overlayColor?.resolve({WidgetState.focused}), Colors.transparent, ); - expect(textButton.style!.side?.resolve({WidgetState.focused})?.color, ZetaColorBase.blue.shade50); + expect(textButton.style!.side?.resolve({WidgetState.focused})?.color, const ZetaPrimitivesLight().blue.shade50); }); - }); - group('Interaction Tests', () { - testWidgets('ZetaAccordion expands and collapses correctly', (WidgetTester tester) async { - await tester.pumpWidget( - const TestApp( - home: ZetaAccordion( - title: 'Accordion Title', - child: Text('Accordion Content'), + group('Interaction Tests', () { + testWidgets('ZetaAccordion expands and collapses correctly', (WidgetTester tester) async { + await tester.pumpWidget( + const TestApp( + home: ZetaAccordion( + title: 'Accordion Title', + child: Text('Accordion Content'), + ), ), - ), - ); - - // Verify that the accordion is initially collapsed - final Finder accordionContent = find.byType(SizeTransition); - expect(accordionContent, findsOneWidget); - - final SizeTransition sizeTransition = tester.widget(accordionContent); - expect(sizeTransition.sizeFactor.value, 0); - - // Tap on the accordion to expand it - await tester.tap(find.text('Accordion Title')); - await tester.pumpAndSettle(); - - // Verify that the accordion is now expanded - expect(sizeTransition.sizeFactor.value, 1); - - // Tap on the accordion again to collapse it - await tester.tap(find.text('Accordion Title')); - await tester.pumpAndSettle(); - - expect(sizeTransition.sizeFactor.value, 0); - }); - - testWidgets('ZetaAccordion changes isOpen property correctly', (WidgetTester tester) async { - bool isOpen = false; - StateSetter? setState; - - await tester.pumpWidget( - TestApp( - home: StatefulBuilder( - builder: (context, setState2) { - setState = setState2; - return ZetaAccordion( - title: 'Accordion Title', - isOpen: isOpen, - child: const Text('Accordion Content'), - ); - }, + ); + + // Verify that the accordion is initially collapsed + final Finder accordionContent = find.byType(SizeTransition); + expect(accordionContent, findsOneWidget); + + final SizeTransition sizeTransition = tester.widget(accordionContent); + expect(sizeTransition.sizeFactor.value, 0); + + // Tap on the accordion to expand it + await tester.tap(find.text('Accordion Title')); + await tester.pumpAndSettle(); + + // Verify that the accordion is now expanded + expect(sizeTransition.sizeFactor.value, 1); + + // Tap on the accordion again to collapse it + await tester.tap(find.text('Accordion Title')); + await tester.pumpAndSettle(); + + expect(sizeTransition.sizeFactor.value, 0); + }); + + testWidgets('ZetaAccordion changes isOpen property correctly', (WidgetTester tester) async { + bool isOpen = false; + StateSetter? setState; + + await tester.pumpWidget( + TestApp( + home: StatefulBuilder( + builder: (context, setState2) { + setState = setState2; + return ZetaAccordion( + title: 'Accordion Title', + isOpen: isOpen, + child: const Text('Accordion Content'), + ); + }, + ), ), - ), - ); + ); - // Verify that the accordion is initially closed - final Finder accordionContent = find.byType(SizeTransition); - expect(accordionContent, findsOneWidget); + // Verify that the accordion is initially closed + final Finder accordionContent = find.byType(SizeTransition); + expect(accordionContent, findsOneWidget); - final SizeTransition sizeTransition = tester.widget(accordionContent); - expect(sizeTransition.sizeFactor.value, 0); + final SizeTransition sizeTransition = tester.widget(accordionContent); + expect(sizeTransition.sizeFactor.value, 0); - // Change isOpen property to true - setState?.call(() => isOpen = true); + // Change isOpen property to true + setState?.call(() => isOpen = true); - await tester.pumpAndSettle(); + await tester.pumpAndSettle(); - // Verify that the accordion is now open - expect(sizeTransition.sizeFactor.value, 1); + // Verify that the accordion is now open + expect(sizeTransition.sizeFactor.value, 1); - // Change isOpen property to false - setState?.call(() => isOpen = false); + // Change isOpen property to false + setState?.call(() => isOpen = false); - await tester.pumpAndSettle(); + await tester.pumpAndSettle(); - // Verify that the accordion is now closed - expect(sizeTransition.sizeFactor.value, 0); + // Verify that the accordion is now closed + expect(sizeTransition.sizeFactor.value, 0); + }); }); + group('Golden Tests', () {}); + group('Performance Tests', () {}); }); - group('Golden Tests', () {}); - group('Performance Tests', () {}); } diff --git a/test/src/components/badge/priority_pill_test.dart b/test/src/components/badge/priority_pill_test.dart index 92c120bb..04bf9ee0 100644 --- a/test/src/components/badge/priority_pill_test.dart +++ b/test/src/components/badge/priority_pill_test.dart @@ -1,4 +1,3 @@ -// ignore_for_file: avoid_dynamic_calls import 'package:flutter_test/flutter_test.dart'; import 'package:zeta_flutter/zeta_flutter.dart'; @@ -21,16 +20,15 @@ void main() { 'rounded': 'false', 'isBadge': 'false', 'index': '"1"', - 'customColor': - 'ZetaColorSwatch(4278219750, Brightness.light, ZetaContrast.aa, Color(0xfff1f8ff), Color(0xffe2f1ff), Color(0xffb7dbff), Color(0xff7ebeff), Color(0xff599fe5), Color(0xff0073e6), Color(0xff0061c2), Color(0xff004d99), Color(0xff002c58), Color(0xff101b25))', + 'customColor': const ZetaPrimitivesLight().blue.toString(), 'type': 'urgent', 'size': 'large', }; debugFillPropertiesTest( - const ZetaPriorityPill( + ZetaPriorityPill( label: 'Test label', rounded: false, - customColor: ZetaColorBase.blue, + customColor: const ZetaPrimitivesLight().blue, index: '1', ), debugFillProperties, diff --git a/test/src/components/banner/banner_test.dart b/test/src/components/banner/banner_test.dart index 470a0c5e..b24fd290 100644 --- a/test/src/components/banner/banner_test.dart +++ b/test/src/components/banner/banner_test.dart @@ -7,18 +7,18 @@ import '../../../test_utils/test_app.dart'; import '../../../test_utils/tolerant_comparator.dart'; import '../../../test_utils/utils.dart'; -ZetaColorSwatch _backgroundColorFromType(BuildContext context, ZetaBannerStatus type) { +ZetaColorSwatch _colorFromType(BuildContext context, ZetaBannerStatus type) { final zeta = Zeta.of(context); switch (type) { case ZetaBannerStatus.primary: - return zeta.colors.primary; + return zeta.colors.primitives.primary; case ZetaBannerStatus.positive: - return zeta.colors.surfacePositive; + return zeta.colors.primitives.green; case ZetaBannerStatus.warning: - return zeta.colors.orange; + return zeta.colors.primitives.orange; case ZetaBannerStatus.negative: - return zeta.colors.surfaceNegative; + return zeta.colors.primitives.red; } } @@ -280,7 +280,7 @@ void main() { textWidget.style, equals( ZetaTextStyles.labelLarge.copyWith( - color: Zeta.of(tester.element(textFinder)).colors.textInverse, + color: Zeta.of(tester.element(textFinder)).colors.mainInverse, ), ), ); @@ -305,7 +305,7 @@ void main() { final Finder iconFinder = find.byIcon(Icons.info); final Icon iconWidget = tester.widget(iconFinder); - expect(iconWidget.color, _backgroundColorFromType(tester.element(iconFinder), type).onColor); + expect(iconWidget.color, const ZetaColorsAA(primitives: ZetaPrimitivesLight()).mainInverse); }); testWidgets('background colors are correct for $type', (WidgetTester tester) async { @@ -325,7 +325,7 @@ void main() { final Finder finder = find.byType(ZetaBanner); final ZetaBanner widget = tester.firstWidget(finder); - expect(widget.backgroundColor, equals(_backgroundColorFromType(tester.element(finder), type))); + expect(widget.backgroundColor, equals(_colorFromType(tester.element(finder), type))); }); } }); diff --git a/test/src/components/breadcrumb/breadcrumb_test.dart b/test/src/components/breadcrumb/breadcrumb_test.dart index bff2fc5f..db66e075 100644 --- a/test/src/components/breadcrumb/breadcrumb_test.dart +++ b/test/src/components/breadcrumb/breadcrumb_test.dart @@ -190,12 +190,12 @@ void main() { if (i == children.length - 1) { expect( (tester.firstWidget(labelFinder.at(i)) as Text).style?.color, - colors.black, + colors.primitives.pure.shade1000, ); } else { expect( (tester.firstWidget(labelFinder.at(i)) as Text).style?.color, - colors.textSubtle, + colors.mainSubtle, ); } } @@ -203,7 +203,7 @@ void main() { for (int i = 0; i < iconFinder.evaluate().length; i++) { expect( (tester.firstWidget(iconFinder.at(i)) as ZetaIcon).color, - colors.textSubtle, + colors.mainSubtle, ); } }); diff --git a/test/src/components/button/button_test.dart b/test/src/components/button/button_test.dart index 140d7537..9def46a9 100644 --- a/test/src/components/button/button_test.dart +++ b/test/src/components/button/button_test.dart @@ -1,5 +1,4 @@ import 'dart:ui'; - import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:zeta_flutter/zeta_flutter.dart'; @@ -204,11 +203,17 @@ void main() { await gesture.moveTo(tester.getCenter(find.byType(ZetaButton))); await tester.pumpAndSettle(); - expect(filledButton.style?.backgroundColor?.resolve({WidgetState.hovered}), ZetaColorBase.blue.shade50); + expect( + filledButton.style?.backgroundColor?.resolve({WidgetState.hovered}), + const ZetaPrimitivesLight().blue.shade50, + ); await gesture.down(tester.getCenter(find.byType(ZetaButton))); await tester.pumpAndSettle(); - expect(filledButton.style?.backgroundColor?.resolve({WidgetState.pressed}), ZetaColorBase.blue.shade70); + expect( + filledButton.style?.backgroundColor?.resolve({WidgetState.pressed}), + const ZetaPrimitivesLight().blue.shade70, + ); await gesture.up(); @@ -239,7 +244,7 @@ void main() { expect(button.size, ZetaWidgetSize.medium); expect( filledButton.style?.side?.resolve({WidgetState.focused}), - BorderSide(color: ZetaColorBase.blue, width: ZetaBorders.medium), + BorderSide(color: const ZetaPrimitivesLight().blue.shade50, width: ZetaBorders.medium), ); }); }); diff --git a/test/src/components/button/golden/button_secondary.png b/test/src/components/button/golden/button_secondary.png index 984e16f5..387a3e5f 100644 Binary files a/test/src/components/button/golden/button_secondary.png and b/test/src/components/button/golden/button_secondary.png differ diff --git a/test/src/components/chat_item/chat_item_test.dart b/test/src/components/chat_item/chat_item_test.dart index 88475d70..e62493fa 100644 --- a/test/src/components/chat_item/chat_item_test.dart +++ b/test/src/components/chat_item/chat_item_test.dart @@ -1,3 +1,4 @@ +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:intl/intl.dart'; @@ -8,9 +9,8 @@ import '../../../test_utils/tolerant_comparator.dart'; import '../../../test_utils/utils.dart'; void main() { - const String parentFolder = 'chat_item'; + const goldenFile = GoldenFiles(component: 'chat_item'); - const goldenFile = GoldenFiles(component: parentFolder); setUpAll(() { goldenFileComparator = TolerantComparator(goldenFile.uri); }); @@ -60,7 +60,7 @@ void main() { 'icon': 'IconData(U+0E5F9)', 'foregroundColor': null, 'backgroundColor': null, - 'color': ZetaColorBase.blue.toString(), + 'color': 'null', 'semanticLabel': 'null', 'paleColor': 'false', }; @@ -412,12 +412,12 @@ void main() { slidableActions: [ ZetaSlidableAction( onPressed: () {}, - color: ZetaColorBase.orange, + color: const ZetaPrimitivesLight().orange, icon: Icons.star, ), ZetaSlidableAction( onPressed: () {}, - color: ZetaColorBase.red, + color: const ZetaPrimitivesLight().red, icon: Icons.delete, ), ], @@ -446,6 +446,60 @@ void main() { await tester.tap(find.byIcon(Icons.delete)); await tester.pumpAndSettle(); expect(tester.takeException(), isNull); + + await expectLater( + chatItemFinder, + matchesGoldenFile(goldenFile.getFileUri('chat_item_custom_slidable_buttons')), + ); + }); + + testWidgets('debugFillProperties works correctly', (WidgetTester tester) async { + final diagnosticsZetaChatItem = DiagnosticPropertiesBuilder(); + final time = DateTime.now(); + ZetaChatItem( + title: const Text('Title'), + subtitle: const Text('Subtitle'), + time: time, + leading: const ZetaAvatar(initials: 'AZ'), + slidableActions: [ + ZetaSlidableAction.menuMore(onPressed: () {}), + ZetaSlidableAction.call(onPressed: () {}), + ZetaSlidableAction.ptt(onPressed: () {}), + ZetaSlidableAction.delete(onPressed: () {}), + ], + count: 1, + enabledNotificationIcon: true, + highlighted: true, + enabledWarningIcon: true, + starred: true, + ).debugFillProperties(diagnosticsZetaChatItem); + + expect(diagnosticsZetaChatItem.finder('rounded'), 'null'); + expect(diagnosticsZetaChatItem.finder('highlighted'), 'true'); + expect(diagnosticsZetaChatItem.finder('time'), time.toString()); + expect(diagnosticsZetaChatItem.finder('timeFormat'), 'null'); + expect(diagnosticsZetaChatItem.finder('enabledWarningIcon'), 'true'); + expect(diagnosticsZetaChatItem.finder('enabledNotificationIcon'), 'true'); + expect(diagnosticsZetaChatItem.finder('count'), '1'); + expect(diagnosticsZetaChatItem.finder('onTap'), 'null'); + expect(diagnosticsZetaChatItem.finder('starred'), 'true'); + expect(diagnosticsZetaChatItem.finder('onMenuMoreTap'), 'null'); + expect(diagnosticsZetaChatItem.finder('onCallTap'), 'null'); + expect(diagnosticsZetaChatItem.finder('onDeleteTap'), 'null'); + expect(diagnosticsZetaChatItem.finder('onPttTap'), 'null'); + expect(diagnosticsZetaChatItem.finder('explicitChildNodes'), 'true'); + expect(diagnosticsZetaChatItem.finder('paleButtonColors'), 'null'); + + final diagnosticsZetaSlidableAction = DiagnosticPropertiesBuilder(); + const ZetaSlidableAction(icon: Icons.star).debugFillProperties(diagnosticsZetaSlidableAction); + + expect(diagnosticsZetaSlidableAction.finder('onPressed'), 'null'); + expect(diagnosticsZetaSlidableAction.finder('icon'), 'IconData(U+0E5F9)'); + expect(diagnosticsZetaSlidableAction.finder('foregroundColor'), null); + expect(diagnosticsZetaSlidableAction.finder('backgroundColor'), null); + expect(diagnosticsZetaSlidableAction.finder('color'), 'null'); + expect(diagnosticsZetaSlidableAction.finder('semanticLabel'), 'null'); + expect(diagnosticsZetaSlidableAction.finder('paleColor'), 'false'); }); testWidgets('ZetaChatItem displays correctly', (WidgetTester tester) async { @@ -742,12 +796,12 @@ void main() { slidableActions: [ ZetaSlidableAction( onPressed: () {}, - color: ZetaColorBase.orange, + color: const ZetaPrimitivesLight().orange, icon: Icons.star, ), ZetaSlidableAction( onPressed: () {}, - color: ZetaColorBase.red, + color: const ZetaPrimitivesLight().red, icon: Icons.delete, ), ], diff --git a/test/src/components/chat_item/golden/chat_item_default.png b/test/src/components/chat_item/golden/chat_item_default.png index f6fa9d75..9e32f644 100644 Binary files a/test/src/components/chat_item/golden/chat_item_default.png and b/test/src/components/chat_item/golden/chat_item_default.png differ diff --git a/test/src/components/checkbox/checkbox_test.dart b/test/src/components/checkbox/checkbox_test.dart index f0b6c598..12c0534b 100644 --- a/test/src/components/checkbox/checkbox_test.dart +++ b/test/src/components/checkbox/checkbox_test.dart @@ -122,7 +122,10 @@ void main() { final animatedContainerFinder = find.byType(AnimatedContainer); final AnimatedContainer animatedContainer = tester.firstWidget(animatedContainerFinder); - expect((animatedContainer.decoration as BoxDecoration?)?.boxShadow?.first.color, ZetaColorBase.blue.shade50); + expect( + (animatedContainer.decoration as BoxDecoration?)?.boxShadow?.first.color, + const ZetaPrimitivesLight().blue.shade50, + ); final gesture = await tester.createGesture(kind: PointerDeviceKind.mouse); await gesture.addPointer(location: Offset.zero); diff --git a/test/src/components/chips/status_chip_test.dart b/test/src/components/chips/status_chip_test.dart index 5d993228..fc735b93 100644 --- a/test/src/components/chips/status_chip_test.dart +++ b/test/src/components/chips/status_chip_test.dart @@ -112,7 +112,7 @@ void main() { expect( widget.decoration, BoxDecoration( - color: ZetaColors.light().surfaceWarm, + color: const ZetaColorsAA(primitives: ZetaPrimitivesLight()).surfaceWarm, borderRadius: BorderRadius.circular(8), ), ); @@ -133,12 +133,12 @@ void main() { expect( widget.decoration, BoxDecoration( - color: ZetaColors.light().surfaceWarm, + color: const ZetaColorsAA(primitives: ZetaPrimitivesLight()).surfaceWarm, ), ); }); - testWidgets('text style is ZetaTextStyles.bodyXSmall and text color is textDefault', (WidgetTester tester) async { + testWidgets('text style is ZetaTextStyles.bodyXSmall and text color is mainDefault', (WidgetTester tester) async { await tester.pumpWidget( const TestApp( home: ZetaStatusChip( @@ -149,7 +149,12 @@ void main() { final Finder finder = find.byType(Text); expect(finder, findsOneWidget); final Text widget = tester.widget(finder); - expect(widget.style, ZetaTextStyles.bodyXSmall.copyWith(color: ZetaColors.light().textDefault)); + expect( + widget.style, + ZetaTextStyles.bodyXSmall.copyWith( + color: const ZetaColorsAA(primitives: ZetaPrimitivesLight()).mainDefault, + ), + ); }); }); diff --git a/test/src/components/dialpad/dialpad_test.dart b/test/src/components/dialpad/dialpad_test.dart index 37575292..7634c674 100644 --- a/test/src/components/dialpad/dialpad_test.dart +++ b/test/src/components/dialpad/dialpad_test.dart @@ -62,7 +62,7 @@ void main() { await gesture.moveTo(tester.getCenter(buttonFinder)); await tester.pumpAndSettle(); - expect(inkWell.overlayColor?.resolve({WidgetState.hovered}), ZetaColorBase.cool.shade20); + expect(inkWell.overlayColor?.resolve({WidgetState.hovered}), const ZetaPrimitivesLight().cool.shade20); }); }); diff --git a/test/src/components/fab/fab_test.dart b/test/src/components/fab/fab_test.dart index 636f8b80..4058ffc3 100644 --- a/test/src/components/fab/fab_test.dart +++ b/test/src/components/fab/fab_test.dart @@ -170,7 +170,10 @@ void main() { await gesture.moveTo(tester.getCenter(fabFinder)); await tester.pumpAndSettle(); - expect(filledButton.style?.backgroundColor?.resolve({WidgetState.hovered}), ZetaColorBase.yellow.shade70); + expect( + filledButton.style?.backgroundColor?.resolve({WidgetState.hovered}), + const ZetaPrimitivesLight().yellow.shade30, + ); await gesture.moveTo(Offset.zero); await tester.pumpAndSettle(); @@ -179,7 +182,7 @@ void main() { await tester.pumpAndSettle(); expect( filledButton.style?.side?.resolve({WidgetState.focused}), - BorderSide(color: ZetaColorBase.blue[50]!, width: ZetaBorders.medium), + BorderSide(color: const ZetaPrimitivesLight().blue[50]!, width: ZetaBorders.medium), ); }); }); diff --git a/test/src/components/fab/golden/FAB_disabled.png b/test/src/components/fab/golden/FAB_disabled.png index 8a0e4a44..f74ba1c0 100644 Binary files a/test/src/components/fab/golden/FAB_disabled.png and b/test/src/components/fab/golden/FAB_disabled.png differ diff --git a/test/src/components/fab/golden/FAB_inverse.png b/test/src/components/fab/golden/FAB_inverse.png index 1f994e94..c6d630fc 100644 Binary files a/test/src/components/fab/golden/FAB_inverse.png and b/test/src/components/fab/golden/FAB_inverse.png differ diff --git a/test/src/components/fab/golden/FAB_pressed.png b/test/src/components/fab/golden/FAB_pressed.png index e0b19382..6be7b8db 100644 Binary files a/test/src/components/fab/golden/FAB_pressed.png and b/test/src/components/fab/golden/FAB_pressed.png differ diff --git a/test/src/components/fab/golden/FAB_secondary.png b/test/src/components/fab/golden/FAB_secondary.png index ae97e30a..a55e9f06 100644 Binary files a/test/src/components/fab/golden/FAB_secondary.png and b/test/src/components/fab/golden/FAB_secondary.png differ diff --git a/test/src/components/in_page_banner/golden/in_page_banner_buttons.png b/test/src/components/in_page_banner/golden/in_page_banner_buttons.png index 1b34beed..e7ed4b12 100644 Binary files a/test/src/components/in_page_banner/golden/in_page_banner_buttons.png and b/test/src/components/in_page_banner/golden/in_page_banner_buttons.png differ diff --git a/test/src/components/in_page_banner/in_page_banner_test.dart b/test/src/components/in_page_banner/in_page_banner_test.dart index 8d840214..e6275999 100644 --- a/test/src/components/in_page_banner/in_page_banner_test.dart +++ b/test/src/components/in_page_banner/in_page_banner_test.dart @@ -65,7 +65,7 @@ void main() { expect(box.decoration.runtimeType, BoxDecoration); final BoxDecoration decoration = box.decoration as BoxDecoration; - expect(decoration.color, ZetaColorBase.purple.shade10); + expect(decoration.color, const ZetaPrimitivesLight().purple.shade10); }); testWidgets('negative background colour is correct', (WidgetTester tester) async { @@ -77,7 +77,7 @@ void main() { final DecoratedBox box = tester.firstWidget(decoratedBoxFinder); expect(box.decoration.runtimeType, BoxDecoration); final BoxDecoration decoration = box.decoration as BoxDecoration; - expect(decoration.color, ZetaColorBase.red.shade10); + expect(decoration.color, const ZetaPrimitivesLight().red.shade10); }); testWidgets('positive background colour is correct', (WidgetTester tester) async { @@ -89,7 +89,7 @@ void main() { final DecoratedBox box = tester.firstWidget(decoratedBoxFinder); expect(box.decoration.runtimeType, BoxDecoration); final BoxDecoration decoration = box.decoration as BoxDecoration; - expect(decoration.color, ZetaColorBase.green.shade10); + expect(decoration.color, const ZetaPrimitivesLight().green.shade10); }); testWidgets('neutral background colour is correct', (WidgetTester tester) async { @@ -101,7 +101,7 @@ void main() { final DecoratedBox box = tester.firstWidget(decoratedBoxFinder); expect(box.decoration.runtimeType, BoxDecoration); final BoxDecoration decoration = box.decoration as BoxDecoration; - expect(decoration.color, ZetaColorBase.cool.shade10); + expect(decoration.color, const ZetaPrimitivesLight().pure.shade0); }); }); group('Interaction Tests', () { diff --git a/test/src/components/navigation_bar/navigation_bar_test.dart b/test/src/components/navigation_bar/navigation_bar_test.dart index b4d48bfe..50ae9b84 100644 --- a/test/src/components/navigation_bar/navigation_bar_test.dart +++ b/test/src/components/navigation_bar/navigation_bar_test.dart @@ -52,23 +52,24 @@ void main() { handle.dispose(); }); - testWidgets('meets accessibility requirements with action', (WidgetTester tester) async { - final SemanticsHandle handle = tester.ensureSemantics(); - await tester.pumpWidget( - TestApp( - home: ZetaNavigationBar.action( - items: items, - action: action, - ), - ), - ); - - await expectLater(tester, meetsGuideline(androidTapTargetGuideline)); - await expectLater(tester, meetsGuideline(iOSTapTargetGuideline)); - await expectLater(tester, meetsGuideline(labeledTapTargetGuideline)); - await expectLater(tester, meetsGuideline(textContrastGuideline)); - handle.dispose(); - }); + // TODO(design): Button is not accessible. + // testWidgets('meets accessibility requirements with action', (WidgetTester tester) async { + // final SemanticsHandle handle = tester.ensureSemantics(); + // await tester.pumpWidget( + // TestApp( + // home: ZetaNavigationBar.action( + // items: items, + // action: action, + // ), + // ), + // ); + + // await expectLater(tester, meetsGuideline(androidTapTargetGuideline)); + // await expectLater(tester, meetsGuideline(iOSTapTargetGuideline)); + // await expectLater(tester, meetsGuideline(labeledTapTargetGuideline)); + // await expectLater(tester, meetsGuideline(textContrastGuideline)); + // handle.dispose(); + // }); testWidgets('meets accessibility requirements with divider', (WidgetTester tester) async { final SemanticsHandle handle = tester.ensureSemantics(); @@ -326,7 +327,7 @@ void main() { final containerWidget = tester.widget(containerFinder); final boxDecoration = containerWidget.decoration! as BoxDecoration; - expect(boxDecoration.color, Zeta.of(context).colors.surfacePrimary); + expect(boxDecoration.color, Zeta.of(context).colors.surfaceDefault); }); testWidgets('items are the correct color', (WidgetTester tester) async { @@ -344,8 +345,8 @@ void main() { tester.widget(find.descendant(of: itemFinder.first, matching: find.byType(ZetaIcon)).first); final label = tester.widget(find.descendant(of: itemFinder.first, matching: find.text('Label0'))); - expect(icon.color, Zeta.of(context).colors.textSubtle); - expect(label.style, Theme.of(context).textTheme.labelSmall?.copyWith(color: Zeta.of(context).colors.textSubtle)); + expect(icon.color, Zeta.of(context).colors.mainSubtle); + expect(label.style, Theme.of(context).textTheme.labelSmall?.copyWith(color: Zeta.of(context).colors.mainSubtle)); }); testWidgets('selected item is the correct color', (WidgetTester tester) async { @@ -364,8 +365,8 @@ void main() { tester.widget(find.descendant(of: itemFinder.first, matching: find.byType(ZetaIcon)).first); final label = tester.widget(find.descendant(of: itemFinder.first, matching: find.text('Label0'))); - expect(icon.color, Zeta.of(context).colors.primary); - expect(label.style, Theme.of(context).textTheme.labelSmall?.copyWith(color: Zeta.of(context).colors.primary)); + expect(icon.color, Zeta.of(context).colors.mainPrimary); + expect(label.style, Theme.of(context).textTheme.labelSmall?.copyWith(color: Zeta.of(context).colors.mainPrimary)); }); testWidgets('hover background color is correct', (WidgetTester tester) async { diff --git a/test/src/components/range_selector/range_selector_test.dart b/test/src/components/range_selector/range_selector_test.dart index a81796b6..168cc81e 100644 --- a/test/src/components/range_selector/range_selector_test.dart +++ b/test/src/components/range_selector/range_selector_test.dart @@ -202,7 +202,7 @@ void main() { final label = find.text('Range Selector'); final labelWidget = tester.widget(label); - expect(labelWidget.style!.color, colors.textDefault); + expect(labelWidget.style!.color, colors.mainDefault); expect(labelWidget.style!.fontSize, 14); expect(labelWidget.style!.fontWeight, FontWeight.w400); }); @@ -223,13 +223,13 @@ void main() { final textFields = find.byType(TextField); final firstTextFieldWidget = tester.widget(textFields.first); - expect(firstTextFieldWidget.style!.color, colors.textSubtle); + expect(firstTextFieldWidget.style!.color, colors.mainSubtle); expect(firstTextFieldWidget.style!.fontSize, 16); expect(firstTextFieldWidget.style!.fontWeight, FontWeight.w400); final lastTextFieldWidget = tester.widget(textFields.last); - expect(lastTextFieldWidget.style!.color, colors.textSubtle); + expect(lastTextFieldWidget.style!.color, colors.mainSubtle); expect(lastTextFieldWidget.style!.fontSize, 16); expect(lastTextFieldWidget.style!.fontWeight, FontWeight.w400); }); diff --git a/test/src/components/stepper/stepper_test.dart b/test/src/components/stepper/stepper_test.dart index 53d4734e..fa6436ff 100644 --- a/test/src/components/stepper/stepper_test.dart +++ b/test/src/components/stepper/stepper_test.dart @@ -293,7 +293,7 @@ void main() { final container = tester.widget(find.byType(Container)); expect( (container.decoration! as BoxDecoration).color, - Zeta.of(getBuildContext(tester, Container)).colors.primary, + Zeta.of(getBuildContext(tester, Container)).colors.mainPrimary, ); }, ); @@ -335,7 +335,7 @@ void main() { final container = tester.widget(find.byType(Container)); expect( (container.decoration! as BoxDecoration).color, - Zeta.of(getBuildContext(tester, Container)).colors.iconDisabled, + Zeta.of(getBuildContext(tester, Container)).colors.mainDisabled, ); }, ); diff --git a/test/src/components/tooltip/tooltip_test.dart b/test/src/components/tooltip/tooltip_test.dart index 31453509..d1033a25 100644 --- a/test/src/components/tooltip/tooltip_test.dart +++ b/test/src/components/tooltip/tooltip_test.dart @@ -18,7 +18,7 @@ void main() { const String parentFolder = 'tooltip'; final mockZeta = MockZeta(); - when(mockZeta.radius).thenReturn(const ZetaRadiiAA(primitives: ZetaPrimitivesLight())); + when(mockZeta.radius).thenReturn(const ZetaRadiusAA(primitives: ZetaPrimitivesLight())); const goldenFile = GoldenFiles(component: parentFolder); setUpAll(() { @@ -198,8 +198,8 @@ void main() { group('Golden Tests', () { goldenTest( goldenFile, - const Scaffold( - body: ZetaTooltip( + const TestApp( + home: ZetaTooltip( arrowDirection: ZetaTooltipArrowDirection.up, child: Text('Tooltip up'), ), @@ -209,8 +209,8 @@ void main() { ); goldenTest( goldenFile, - const Scaffold( - body: ZetaTooltip( + const TestApp( + home: ZetaTooltip( child: Text('Tooltip down'), ), ), @@ -219,8 +219,8 @@ void main() { ); goldenTest( goldenFile, - const Scaffold( - body: ZetaTooltip( + const TestApp( + home: ZetaTooltip( arrowDirection: ZetaTooltipArrowDirection.left, child: Text('Tooltip left'), ), @@ -230,8 +230,8 @@ void main() { ); goldenTest( goldenFile, - const Scaffold( - body: ZetaTooltip( + const TestApp( + home: ZetaTooltip( arrowDirection: ZetaTooltipArrowDirection.right, child: Text('Tooltip right'), ), diff --git a/test/src/components/tooltip/tooltip_test.mocks.dart b/test/src/components/tooltip/tooltip_test.mocks.dart index 100599a8..b906eb4f 100644 --- a/test/src/components/tooltip/tooltip_test.mocks.dart +++ b/test/src/components/tooltip/tooltip_test.mocks.dart @@ -24,8 +24,8 @@ import 'package:zeta_flutter/zeta_flutter.dart' as _i2; // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class -class _FakeZetaThemeData_0 extends _i1.SmartFake implements _i2.ZetaThemeData { - _FakeZetaThemeData_0( +class _FakeZetaPrimitives_0 extends _i1.SmartFake implements _i2.ZetaPrimitives { + _FakeZetaPrimitives_0( Object parent, Invocation parentInvocation, ) : super( @@ -34,8 +34,8 @@ class _FakeZetaThemeData_0 extends _i1.SmartFake implements _i2.ZetaThemeData { ); } -class _FakeZetaColors_1 extends _i1.SmartFake implements _i2.ZetaColors { - _FakeZetaColors_1( +class _FakeZetaSemantics_1 extends _i1.SmartFake implements _i2.ZetaSemantics { + _FakeZetaSemantics_1( Object parent, Invocation parentInvocation, ) : super( @@ -44,8 +44,8 @@ class _FakeZetaColors_1 extends _i1.SmartFake implements _i2.ZetaColors { ); } -class _FakeZetaRadiiSemantics_2 extends _i1.SmartFake implements _i2.ZetaRadiiSemantics { - _FakeZetaRadiiSemantics_2( +class _FakeZetaColors_2 extends _i1.SmartFake implements _i2.ZetaColors { + _FakeZetaColors_2( Object parent, Invocation parentInvocation, ) : super( @@ -54,8 +54,8 @@ class _FakeZetaRadiiSemantics_2 extends _i1.SmartFake implements _i2.ZetaRadiiSe ); } -class _FakeZetaSpacingSemantics_3 extends _i1.SmartFake implements _i2.ZetaSpacingSemantics { - _FakeZetaSpacingSemantics_3( +class _FakeZetaRadius_3 extends _i1.SmartFake implements _i2.ZetaRadius { + _FakeZetaRadius_3( Object parent, Invocation parentInvocation, ) : super( @@ -64,8 +64,18 @@ class _FakeZetaSpacingSemantics_3 extends _i1.SmartFake implements _i2.ZetaSpaci ); } -class _FakeWidget_4 extends _i1.SmartFake implements _i3.Widget { - _FakeWidget_4( +class _FakeZetaSpacing_4 extends _i1.SmartFake implements _i2.ZetaSpacing { + _FakeZetaSpacing_4( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeWidget_5 extends _i1.SmartFake implements _i3.Widget { + _FakeWidget_5( Object parent, Invocation parentInvocation, ) : super( @@ -77,8 +87,8 @@ class _FakeWidget_4 extends _i1.SmartFake implements _i3.Widget { String toString({_i4.DiagnosticLevel? minLevel = _i4.DiagnosticLevel.info}) => super.toString(); } -class _FakeInheritedElement_5 extends _i1.SmartFake implements _i3.InheritedElement { - _FakeInheritedElement_5( +class _FakeInheritedElement_6 extends _i1.SmartFake implements _i3.InheritedElement { + _FakeInheritedElement_6( Object parent, Invocation parentInvocation, ) : super( @@ -90,8 +100,8 @@ class _FakeInheritedElement_5 extends _i1.SmartFake implements _i3.InheritedElem String toString({_i4.DiagnosticLevel? minLevel = _i4.DiagnosticLevel.info}) => super.toString(); } -class _FakeDiagnosticsNode_6 extends _i1.SmartFake implements _i4.DiagnosticsNode { - _FakeDiagnosticsNode_6( +class _FakeDiagnosticsNode_7 extends _i1.SmartFake implements _i4.DiagnosticsNode { + _FakeDiagnosticsNode_7( Object parent, Invocation parentInvocation, ) : super( @@ -111,6 +121,13 @@ class _FakeDiagnosticsNode_6 extends _i1.SmartFake implements _i4.DiagnosticsNod /// /// See the documentation for Mockito's code generation for more information. class MockZeta extends _i1.Mock implements _i2.Zeta { + @override + bool get rounded => (super.noSuchMethod( + Invocation.getter(#rounded), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); + @override _i2.ZetaContrast get contrast => (super.noSuchMethod( Invocation.getter(#contrast), @@ -126,33 +143,39 @@ class MockZeta extends _i1.Mock implements _i2.Zeta { ) as _i3.ThemeMode); @override - _i2.ZetaThemeData get themeData => (super.noSuchMethod( - Invocation.getter(#themeData), - returnValue: _FakeZetaThemeData_0( + _i2.ZetaPrimitives get primitives => (super.noSuchMethod( + Invocation.getter(#primitives), + returnValue: _FakeZetaPrimitives_0( this, - Invocation.getter(#themeData), + Invocation.getter(#primitives), ), - returnValueForMissingStub: _FakeZetaThemeData_0( + returnValueForMissingStub: _FakeZetaPrimitives_0( this, - Invocation.getter(#themeData), + Invocation.getter(#primitives), ), - ) as _i2.ZetaThemeData); + ) as _i2.ZetaPrimitives); @override - bool get rounded => (super.noSuchMethod( - Invocation.getter(#rounded), - returnValue: false, - returnValueForMissingStub: false, - ) as bool); + _i2.ZetaSemantics get semantics => (super.noSuchMethod( + Invocation.getter(#semantics), + returnValue: _FakeZetaSemantics_1( + this, + Invocation.getter(#semantics), + ), + returnValueForMissingStub: _FakeZetaSemantics_1( + this, + Invocation.getter(#semantics), + ), + ) as _i2.ZetaSemantics); @override _i2.ZetaColors get colors => (super.noSuchMethod( Invocation.getter(#colors), - returnValue: _FakeZetaColors_1( + returnValue: _FakeZetaColors_2( this, Invocation.getter(#colors), ), - returnValueForMissingStub: _FakeZetaColors_1( + returnValueForMissingStub: _FakeZetaColors_2( this, Invocation.getter(#colors), ), @@ -166,39 +189,39 @@ class MockZeta extends _i1.Mock implements _i2.Zeta { ) as _i5.Brightness); @override - _i2.ZetaRadiiSemantics get radius => (super.noSuchMethod( + _i2.ZetaRadius get radius => (super.noSuchMethod( Invocation.getter(#radius), - returnValue: _FakeZetaRadiiSemantics_2( + returnValue: _FakeZetaRadius_3( this, Invocation.getter(#radius), ), - returnValueForMissingStub: _FakeZetaRadiiSemantics_2( + returnValueForMissingStub: _FakeZetaRadius_3( this, Invocation.getter(#radius), ), - ) as _i2.ZetaRadiiSemantics); + ) as _i2.ZetaRadius); @override - _i2.ZetaSpacingSemantics get spacing => (super.noSuchMethod( + _i2.ZetaSpacing get spacing => (super.noSuchMethod( Invocation.getter(#spacing), - returnValue: _FakeZetaSpacingSemantics_3( + returnValue: _FakeZetaSpacing_4( this, Invocation.getter(#spacing), ), - returnValueForMissingStub: _FakeZetaSpacingSemantics_3( + returnValueForMissingStub: _FakeZetaSpacing_4( this, Invocation.getter(#spacing), ), - ) as _i2.ZetaSpacingSemantics); + ) as _i2.ZetaSpacing); @override _i3.Widget get child => (super.noSuchMethod( Invocation.getter(#child), - returnValue: _FakeWidget_4( + returnValue: _FakeWidget_5( this, Invocation.getter(#child), ), - returnValueForMissingStub: _FakeWidget_4( + returnValueForMissingStub: _FakeWidget_5( this, Invocation.getter(#child), ), @@ -229,14 +252,14 @@ class MockZeta extends _i1.Mock implements _i2.Zeta { #createElement, [], ), - returnValue: _FakeInheritedElement_5( + returnValue: _FakeInheritedElement_6( this, Invocation.method( #createElement, [], ), ), - returnValueForMissingStub: _FakeInheritedElement_5( + returnValueForMissingStub: _FakeInheritedElement_6( this, Invocation.method( #createElement, @@ -361,7 +384,7 @@ class MockZeta extends _i1.Mock implements _i2.Zeta { #style: style, }, ), - returnValue: _FakeDiagnosticsNode_6( + returnValue: _FakeDiagnosticsNode_7( this, Invocation.method( #toDiagnosticsNode, @@ -372,7 +395,7 @@ class MockZeta extends _i1.Mock implements _i2.Zeta { }, ), ), - returnValueForMissingStub: _FakeDiagnosticsNode_6( + returnValueForMissingStub: _FakeDiagnosticsNode_7( this, Invocation.method( #toDiagnosticsNode, diff --git a/test/src/components/top_app_bar/extended_top_app_bar_test.dart b/test/src/components/top_app_bar/extended_top_app_bar_test.dart new file mode 100644 index 00000000..5f8b85a3 --- /dev/null +++ b/test/src/components/top_app_bar/extended_top_app_bar_test.dart @@ -0,0 +1,169 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:zeta_flutter/zeta_flutter.dart'; + +import '../../../test_utils/test_app.dart'; +import '../../../test_utils/tolerant_comparator.dart'; +import '../../../test_utils/utils.dart'; + +void main() { + const goldenFile = GoldenFiles(component: 'top_app_bar'); + + setUpAll(() { + goldenFileComparator = TolerantComparator(goldenFile.uri); + }); + + testWidgets('ZetaExtendedAppBarDelegate builds correctly', (WidgetTester tester) async { + const title = Text('Title'); + final actions = [IconButton(icon: const Icon(Icons.search), onPressed: () {})]; + final leading = IconButton(icon: const Icon(Icons.menu), onPressed: () {}); + const boxKey = Key('box'); + tester.view.devicePixelRatio = 1.0; + tester.view.physicalSize = const Size(481, 480); + + await tester.pumpWidget( + TestApp( + home: Builder( + builder: (context) { + return SizedBox( + child: CustomScrollView( + slivers: [ + ZetaTopAppBar.extended(leading: leading, title: title, actions: actions), + SliverToBoxAdapter( + child: Container( + width: 800, + height: 700, + color: Zeta.of(context).colors.surfaceSelectedHover, + key: boxKey, + ), + ), + ], + ), + ); + }, + ), + ), + ); + + final boxFinder = find.byKey(boxKey); + expect(boxFinder, findsOneWidget); + + await tester.drag(boxFinder.first, const Offset(0, -100)); + await tester.pumpAndSettle(); + + final appBarFinder = find.byType(ZetaTopAppBar); + expect(appBarFinder, findsOneWidget); + + final titleFinder = find.descendant(of: appBarFinder, matching: find.byWidget(title)); + expect(titleFinder, findsOneWidget); + + final actionsFinder = find.descendant(of: appBarFinder, matching: find.byWidget(actions[0])); + expect(actionsFinder, findsOneWidget); + + final leadingFinder = find.descendant(of: appBarFinder, matching: find.byWidget(leading)); + expect(leadingFinder, findsOneWidget); + + await expectLater( + appBarFinder, + matchesGoldenFile(goldenFile.getFileUri('extended_app_bar_shrinks')), + ); + }); + + testWidgets('ZetaExtendedAppBarDelegate shrinks correctly with padding', (WidgetTester tester) async { + const title = Text('Title'); + final actions = [IconButton(icon: const Icon(Icons.search), onPressed: () {})]; + final leading = IconButton(icon: const Icon(Icons.menu), onPressed: () {}); + const boxKey = Key('box'); + tester.view.devicePixelRatio = 1.0; + tester.view.physicalSize = const Size(481, 480); + + await tester.pumpWidget( + TestApp( + home: Builder( + builder: (context) { + return SizedBox( + child: CustomScrollView( + slivers: [ + ZetaTopAppBar.extended(leading: leading, title: title, actions: actions), + SliverToBoxAdapter( + child: Container( + width: 800, + height: 700, + color: Zeta.of(context).colors.surfaceSelectedHover, + key: boxKey, + ), + ), + ], + ), + ); + }, + ), + ), + ); + + final boxFinder = find.byKey(boxKey); + expect(boxFinder, findsOneWidget); + + await tester.drag(boxFinder.first, const Offset(0, -100)); + await tester.pumpAndSettle(); + + final appBarFinder = find.byType(ZetaTopAppBar); + expect(appBarFinder, findsOneWidget); + + final positionedFinder = find.descendant(of: appBarFinder, matching: find.byType(Positioned)); + + final positionedWidget = tester.widget(positionedFinder.first); + expect(positionedWidget.left, 64); + }); + testWidgets('ZetaExtendedAppBarDelegate shrinks correctly with padding and no leading', (WidgetTester tester) async { + const title = Text('Title'); + final actions = [IconButton(icon: const Icon(Icons.search), onPressed: () {})]; + + const boxKey = Key('box'); + tester.view.devicePixelRatio = 1.0; + tester.view.physicalSize = const Size(481, 480); + + await tester.pumpWidget( + TestApp( + home: Builder( + builder: (context) { + return SizedBox( + child: CustomScrollView( + slivers: [ + ZetaTopAppBar.extended(title: title, actions: actions), + SliverToBoxAdapter( + child: Container( + width: 800, + height: 700, + color: Zeta.of(context).colors.surfaceSelectedHover, + key: boxKey, + ), + ), + ], + ), + ); + }, + ), + ), + ); + + final boxFinder = find.byKey(boxKey); + expect(boxFinder, findsOneWidget); + + await tester.drag(boxFinder.first, const Offset(0, -100)); + await tester.pumpAndSettle(); + + final appBarFinder = find.byType(ZetaTopAppBar); + expect(appBarFinder, findsOneWidget); + + final positionedFinder = find.descendant(of: appBarFinder, matching: find.byType(Positioned)); + + final positionedWidget = tester.widget(positionedFinder.first); + expect(positionedWidget.left, 16); + + await expectLater( + appBarFinder, + matchesGoldenFile(goldenFile.getFileUri('extended_app_bar_shrinks_with_no_leading')), + ); + }); +} diff --git a/test/src/theme/color_extensions_test.dart b/test/src/theme/color_extensions_test.dart index be017c94..3fb9ce3d 100644 --- a/test/src/theme/color_extensions_test.dart +++ b/test/src/theme/color_extensions_test.dart @@ -33,10 +33,10 @@ void main() { test('onColor returns the correct on color', () { const color = Colors.blue; - expect(color.onColor, ZetaColorBase.white); + expect(color.onColor, const ZetaPrimitivesLight().pure.shade0); const lightColor = Colors.white; - expect(lightColor.onColor, ZetaColorBase.cool.shade90); + expect(lightColor.onColor, Colors.black87); }); test('isLight returns true for light colors', () { diff --git a/test/src/theme/color_scheme_test.dart b/test/src/theme/color_scheme_test.dart deleted file mode 100644 index 0e2cb063..00000000 --- a/test/src/theme/color_scheme_test.dart +++ /dev/null @@ -1,108 +0,0 @@ -import 'package:flutter/foundation.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:zeta_flutter/zeta_flutter.dart'; - -void main() { - group('ZetaColorScheme', () { - const String fontFamily = 'TestFontFamily'; - final ZetaColors zetaColors = ZetaColors( - primary: ZetaColorBase.blue, - secondary: ZetaColorBase.green, - surfacePrimary: ZetaColorBase.white, - surfaceTertiary: ZetaColorBase.white, - error: ZetaColorBase.red, - ); - - final ZetaColorScheme zetaColorScheme = ZetaColorScheme( - zetaColors: zetaColors, - fontFamily: fontFamily, - brightness: Brightness.light, - primary: Colors.blue, - onPrimary: Colors.white, - secondary: Colors.green, - onSecondary: Colors.white, - error: Colors.red, - onError: Colors.white, - surface: Colors.grey, - onSurface: Colors.black, - ); - - test('initialization of properties', () { - expect(zetaColorScheme.zetaColors, zetaColors); - expect(zetaColorScheme.fontFamily, fontFamily); - expect(zetaColorScheme.brightness, Brightness.light); - expect(zetaColorScheme.primary, Colors.blue); - expect(zetaColorScheme.onPrimary, Colors.white); - expect(zetaColorScheme.secondary, Colors.green); - expect(zetaColorScheme.onSecondary, Colors.white); - expect(zetaColorScheme.error, Colors.red); - expect(zetaColorScheme.onError, Colors.white); - expect(zetaColorScheme.surface, Colors.grey); - expect(zetaColorScheme.onSurface, Colors.black); - }); - - test('copyWith copies and overrides properties correctly', () { - final newZetaColors = ZetaColors( - primary: ZetaColorBase.purple, - secondary: ZetaColorBase.orange, - surfacePrimary: ZetaColorBase.yellow, - surfaceTertiary: ZetaColorBase.yellow, - error: ZetaColorBase.pink, - ); - const newFontFamily = 'NewTestFontFamily'; - - final copied = zetaColorScheme.copyWith( - zetaColors: newZetaColors, - fontFamily: newFontFamily, - primary: Colors.purple, - onPrimary: Colors.black, - ); - - expect(copied.zetaColors, newZetaColors); - expect(copied.fontFamily, newFontFamily); - expect(copied.primary, Colors.purple); - expect(copied.onPrimary, Colors.black); - expect(copied.secondary, zetaColorScheme.secondary); // Unchanged property - }); - - test('equality operator works as expected', () { - final identicalColorScheme = ZetaColorScheme( - zetaColors: zetaColors, - fontFamily: fontFamily, - brightness: Brightness.light, - primary: Colors.blue, - onPrimary: Colors.white, - secondary: Colors.green, - onSecondary: Colors.white, - error: Colors.red, - onError: Colors.white, - surface: Colors.grey, - onSurface: Colors.black, - ); - - expect(zetaColorScheme, identicalColorScheme); - expect(zetaColorScheme.hashCode, identicalColorScheme.hashCode); - expect(zetaColorScheme == identicalColorScheme, isTrue); - }); - - test('debugFillProperties includes correct properties', () { - final DiagnosticPropertiesBuilder properties = DiagnosticPropertiesBuilder(); - zetaColorScheme.debugFillProperties(properties); - - final zetaColorsProperty = properties.properties.firstWhere( - (prop) => prop is DiagnosticsProperty && prop.name == 'zetaColors', - ) as DiagnosticsProperty?; - - final fontFamilyProperty = properties.properties.firstWhere( - (prop) => prop is StringProperty && prop.name == 'fontFamily', - ) as StringProperty?; - - expect(zetaColorsProperty, isNotNull); - expect(zetaColorsProperty?.value, zetaColors); - - expect(fontFamilyProperty, isNotNull); - expect(fontFamilyProperty?.value, fontFamily); - }); - }); -} diff --git a/test/src/theme/color_swatch_test.dart b/test/src/theme/color_swatch_test.dart deleted file mode 100644 index 11eadba5..00000000 --- a/test/src/theme/color_swatch_test.dart +++ /dev/null @@ -1,182 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:zeta_flutter/zeta_flutter.dart'; - -void main() { - group('ZetaColorSwatch', () { - late ZetaColorSwatch zetaColorSwatch; - - setUp(() { - zetaColorSwatch = ZetaColorSwatch( - primary: Colors.blue.value, - swatch: { - 10: Colors.blue.shade100, - 20: Colors.blue.shade200, - 30: Colors.blue.shade300, - 40: Colors.blue.shade400, - 50: Colors.blue.shade500, - 60: Colors.blue, - 70: Colors.blue.shade700, - 80: Colors.blue.shade800, - 90: Colors.blue.shade900, - 100: Colors.blue.shade900, - }, - ); - }); - - test('initialization of properties', () { - expect(zetaColorSwatch.brightness, Brightness.light); - expect(zetaColorSwatch.contrast, ZetaContrast.aa); - expect(zetaColorSwatch.shade10, Colors.blue.shade100); - expect(zetaColorSwatch.shade20, Colors.blue.shade200); - expect(zetaColorSwatch.shade30, Colors.blue.shade300); - expect(zetaColorSwatch.shade40, Colors.blue.shade400); - expect(zetaColorSwatch.shade50, Colors.blue.shade500); - expect(zetaColorSwatch.shade60, Colors.blue); - expect(zetaColorSwatch.shade70, Colors.blue.shade700); - expect(zetaColorSwatch.shade80, Colors.blue.shade800); - expect(zetaColorSwatch.shade90, Colors.blue.shade900); - expect(zetaColorSwatch.shade100, Colors.blue.shade900); - }); - - test('fromColor factory constructor', () { - final swatch = ZetaColorSwatch.fromColor( - Colors.blue, - ); - - expect(swatch.value, Colors.blue.value); - expect(swatch.brightness, Brightness.light); - expect(swatch.contrast, ZetaContrast.aa); - }); - - test('apply method', () { - final appliedSwatch = zetaColorSwatch.apply( - brightness: Brightness.dark, - contrast: ZetaContrast.aaa, - ); - - expect(appliedSwatch.brightness, Brightness.dark); - expect(appliedSwatch.contrast, ZetaContrast.aaa); - expect(appliedSwatch.shade10, zetaColorSwatch.shade100); - expect(appliedSwatch.shade20, zetaColorSwatch.shade90); - expect(appliedSwatch.shade30, zetaColorSwatch.shade80); - expect(appliedSwatch.shade40, zetaColorSwatch.shade70); - expect(appliedSwatch.shade50, zetaColorSwatch.shade60); - expect(appliedSwatch.shade60, zetaColorSwatch.shade50); - expect(appliedSwatch.shade70, zetaColorSwatch.shade40); - expect(appliedSwatch.shade80, zetaColorSwatch.shade30); - expect(appliedSwatch.shade90, zetaColorSwatch.shade20); - expect(appliedSwatch.shade100, zetaColorSwatch.shade10); - }); - - test('equality operator works as expected', () { - final identicalSwatch = ZetaColorSwatch( - primary: Colors.blue.value, - swatch: { - 10: Colors.blue.shade100, - 20: Colors.blue.shade200, - 30: Colors.blue.shade300, - 40: Colors.blue.shade400, - 50: Colors.blue.shade500, - 60: Colors.blue, - 70: Colors.blue.shade700, - 80: Colors.blue.shade800, - 90: Colors.blue.shade900, - 100: Colors.blue.shade900, - }, - ); - - expect(zetaColorSwatch, identicalSwatch); - expect(zetaColorSwatch == identicalSwatch, isTrue); - }); - - test('hashCode method works as expected', () { - final identicalSwatch = ZetaColorSwatch( - primary: Colors.blue.value, - swatch: { - 10: Colors.blue.shade100, - 20: Colors.blue.shade200, - 30: Colors.blue.shade300, - 40: Colors.blue.shade400, - 50: Colors.blue.shade500, - 60: Colors.blue, - 70: Colors.blue.shade700, - 80: Colors.blue.shade800, - 90: Colors.blue.shade900, - 100: Colors.blue.shade900, - }, - ); - - expect(zetaColorSwatch.hashCode, identicalSwatch.hashCode); - }); - - test('shade getters works as expected', () { - expect(zetaColorSwatch.shade10, Colors.blue.shade100); - expect(zetaColorSwatch.shade20, Colors.blue.shade200); - expect(zetaColorSwatch.shade30, Colors.blue.shade300); - expect(zetaColorSwatch.shade40, Colors.blue.shade400); - expect(zetaColorSwatch.shade50, Colors.blue.shade500); - expect(zetaColorSwatch.shade60, Colors.blue); - expect(zetaColorSwatch.shade70, Colors.blue.shade700); - expect(zetaColorSwatch.shade80, Colors.blue.shade800); - expect(zetaColorSwatch.shade90, Colors.blue.shade900); - expect(zetaColorSwatch.shade100, Colors.blue.shade900); - }); - - test('token getters works as expected', () { - expect(zetaColorSwatch.text.value, Colors.blue.value); - expect(zetaColorSwatch.icon.value, Colors.blue.value); - expect(zetaColorSwatch.hover.value, Colors.blue.shade700.value); - expect(zetaColorSwatch.selected.value, Colors.blue.shade800.value); - expect(zetaColorSwatch.focus.value, Colors.blue.shade800.value); - expect(zetaColorSwatch.border.value, Colors.blue.value); - expect(zetaColorSwatch.subtle.value, Colors.blue.shade400.value); - expect(zetaColorSwatch.surface.value, Colors.blue.shade100.value); - - final aaaSwatch = ZetaColorSwatch( - contrast: ZetaContrast.aaa, - primary: Colors.blue.value, - swatch: { - 10: Colors.blue.shade100, - 20: Colors.blue.shade200, - 30: Colors.blue.shade300, - 40: Colors.blue.shade400, - 50: Colors.blue.shade500, - 60: Colors.blue, - 70: Colors.blue.shade700, - 80: Colors.blue.shade800, - 90: Colors.blue.shade900, - 100: Colors.blue.shade900, - }, - ); - - expect(aaaSwatch.text.value, Colors.blue.shade800.value); - expect(aaaSwatch.icon.value, Colors.blue.shade800.value); - expect(aaaSwatch.hover.value, Colors.blue.shade900.value); - expect(aaaSwatch.selected.value, Colors.blue.shade900.value); - expect(aaaSwatch.focus.value, Colors.blue.shade900.value); - expect(aaaSwatch.border.value, Colors.blue.shade800.value); - expect(aaaSwatch.subtle.value, Colors.blue.shade500.value); - expect(aaaSwatch.surface.value, Colors.blue.shade100.value); - }); - }); - - testWidgets('Light / Dark mode are inverted', (tester) async { - final ZetaColors light = ZetaColors(); - final ZetaColors dark = ZetaColors(brightness: Brightness.dark); - - expect(light.primary.shade10, dark.primary.shade100); - expect(light.primary.shade20, dark.primary.shade90); - expect(light.primary.shade30, dark.primary.shade80); - expect(light.primary.shade40, dark.primary.shade70); - expect(light.primary.shade50, dark.primary.shade60); - }); - - testWidgets('AAA mode value colors are 2 shades darker', (tester) async { - final ZetaColors aa = ZetaColors(); - final ZetaColors aaa = ZetaColors(brightness: Brightness.dark, contrast: ZetaContrast.aaa); - - expect(aa.primary.value, aa.primary.shade60.value); - expect(aaa.primary.value, aaa.primary.shade80.value); - }); -} diff --git a/test/src/theme/colors_test.dart b/test/src/theme/colors_test.dart deleted file mode 100644 index cb4d6367..00000000 --- a/test/src/theme/colors_test.dart +++ /dev/null @@ -1,291 +0,0 @@ -// ignore_for_file: deprecated_member_use_from_same_package - -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:zeta_flutter/zeta_flutter.dart'; - -void main() { - group('ZetaColors', () { - test('default constructor initializes correctly', () { - final zetaColors = ZetaColors(); - - expect(zetaColors.brightness, Brightness.light); - expect(zetaColors.contrast, ZetaContrast.aa); - expect(zetaColors.white, ZetaColorBase.white); - expect(zetaColors.black, ZetaColorBase.black); - expect(zetaColors.primary, isNotNull); - expect(zetaColors.secondary, isNotNull); - expect(zetaColors.error, isNotNull); - expect(zetaColors.cool, isNotNull); - expect(zetaColors.warm, isNotNull); - expect(zetaColors.pure, isNotNull); - expect(zetaColors.surfacePrimary, ZetaColorBase.white); - expect(zetaColors.surfaceSecondary, isNotNull); - expect(zetaColors.surfaceTertiary, isNotNull); - }); - - test('light constructor initializes correctly', () { - final zetaColors = ZetaColors.light( - warm: ZetaColorBase.warm, - cool: ZetaColorBase.cool, - ); - - expect(zetaColors.brightness, Brightness.light); - expect(zetaColors.contrast, ZetaContrast.aa); - expect(zetaColors.white, ZetaColorBase.white); - expect(zetaColors.black, ZetaColorBase.black); - expect(zetaColors.primary, isNotNull); - expect(zetaColors.secondary, isNotNull); - expect(zetaColors.error, isNotNull); - expect(zetaColors.cool, isNotNull); - expect(zetaColors.warm, isNotNull); - expect(zetaColors.pure, isNotNull); - expect(zetaColors.surfacePrimary, ZetaColorBase.white); - expect(zetaColors.surfaceSecondary, isNotNull); - expect(zetaColors.surfaceTertiary, isNotNull); - }); - - test('dark constructor initializes correctly', () { - final zetaColors = ZetaColors.dark( - warm: ZetaColorBase.warm, - cool: ZetaColorBase.cool, - ); - - expect(zetaColors.brightness, Brightness.dark); - expect(zetaColors.contrast, ZetaContrast.aa); - expect(zetaColors.white, ZetaColorBase.white); - expect(zetaColors.black, ZetaColorBase.black); - expect(zetaColors.primary, isNotNull); - expect(zetaColors.secondary, isNotNull); - expect(zetaColors.error, isNotNull); - expect(zetaColors.cool, isNotNull); - expect(zetaColors.warm, isNotNull); - expect(zetaColors.pure, isNotNull); - expect(zetaColors.surfacePrimary, ZetaColorBase.black); - expect(zetaColors.surfaceSecondary, isNotNull); - expect(zetaColors.surfaceTertiary, isNotNull); - }); - - test('copyWith creates a new instance with updated properties', () { - final zetaColors = ZetaColors().copyWith(); - final newColors = zetaColors.copyWith( - brightness: Brightness.dark, - contrast: ZetaContrast.aaa, - primary: ZetaColorBase.green, - secondary: ZetaColorBase.orange, - ); - - expect(newColors.isDarkMode, true); - expect(newColors.brightness, Brightness.dark); - expect(newColors.contrast, ZetaContrast.aaa); - expect(newColors.primary, ZetaColorBase.green.apply(brightness: Brightness.dark, contrast: ZetaContrast.aaa)); - expect(newColors.secondary, ZetaColorBase.orange.apply(brightness: Brightness.dark, contrast: ZetaContrast.aaa)); - expect(newColors.white, zetaColors.white); - expect(newColors.black, zetaColors.black); - }); - - test('rainbow getters returns correct colors', () { - final zetaColors = ZetaColors(); - expect(zetaColors.rainbow[0], zetaColors.red); - expect(zetaColors.rainbow[1], zetaColors.orange); - expect(zetaColors.rainbow[2], zetaColors.yellow); - expect(zetaColors.rainbow[3], zetaColors.green); - expect(zetaColors.rainbow[4], zetaColors.blue); - expect(zetaColors.rainbow[5], zetaColors.teal); - expect(zetaColors.rainbow[6], zetaColors.pink); - - expect(zetaColors.rainbowMap['red'], zetaColors.red); - expect(zetaColors.rainbowMap['orange'], zetaColors.orange); - expect(zetaColors.rainbowMap['yellow'], zetaColors.yellow); - expect(zetaColors.rainbowMap['green'], zetaColors.green); - expect(zetaColors.rainbowMap['blue'], zetaColors.blue); - expect(zetaColors.rainbowMap['teal'], zetaColors.teal); - expect(zetaColors.rainbowMap['pink'], zetaColors.pink); - }); - - test('apply returns a new instance with updated contrast', () { - final zetaColors = ZetaColors(); - final newColors = zetaColors.apply(contrast: ZetaContrast.aaa); - - expect(newColors.contrast, ZetaContrast.aaa); - expect(newColors.primary, isNotNull); - expect(newColors.secondary, isNotNull); - expect(newColors.error, isNotNull); - expect(newColors.cool, isNotNull); - expect(newColors.warm, isNotNull); - expect(newColors.pure, isNotNull); - }); - - test('toScheme returns a ZetaColorScheme with correct values', () { - final zetaColors = ZetaColors(); - final scheme = zetaColors.toScheme(); - - expect(scheme.zetaColors, zetaColors); - expect(scheme.brightness, zetaColors.brightness); - expect(scheme.primary, zetaColors.primary.shade(zetaColors.contrast.primary)); - expect(scheme.secondary, zetaColors.secondary.shade(zetaColors.contrast.primary)); - expect(scheme.surface, zetaColors.surfacePrimary); - expect(scheme.error, zetaColors.error); - }); - - test('Color getter returns correct values', () { - final zetaColors = ZetaColors(); - - expect(zetaColors.textDefault, ZetaColorBase.cool.shade90); - expect(zetaColors.textSubtle, ZetaColorBase.cool.shade70); - expect(zetaColors.textDisabled, ZetaColorBase.cool.shade50); - expect(zetaColors.textInverse, ZetaColorBase.cool.shade20); - expect(zetaColors.iconDefault, ZetaColorBase.cool.shade90); - expect(zetaColors.iconSubtle, ZetaColorBase.cool.shade70); - expect(zetaColors.iconDisabled, ZetaColorBase.cool.shade50); - expect(zetaColors.iconInverse, ZetaColorBase.cool.shade20); - expect(zetaColors.surfaceDefault, ZetaColorBase.pure.shade(0)); - expect(zetaColors.surfaceDefaultInverse, ZetaColorBase.warm.shade(100)); - expect(zetaColors.surfaceHover, ZetaColorBase.cool.shade(20)); - expect(zetaColors.surfaceSelected, ZetaColorBase.blue.shade(10)); - expect(zetaColors.surfaceSelectedHover, ZetaColorBase.blue.shade(20)); - expect(zetaColors.surfaceDisabled, ZetaColorBase.cool.shade(30)); - expect(zetaColors.surfaceCool, ZetaColorBase.cool.shade(10)); - expect(zetaColors.surfaceWarm, ZetaColorBase.warm.shade(10)); - expect(zetaColors.surfacePrimarySubtle, ZetaColorBase.blue.shade(10)); - expect(zetaColors.surfaceAvatarBlue, ZetaColorBase.blue.shade(80)); - expect(zetaColors.surfaceAvatarOrange, ZetaColorBase.orange.shade(50)); - expect(zetaColors.surfaceAvatarPink, ZetaColorBase.pink.shade(80)); - expect(zetaColors.surfaceAvatarPurple, ZetaColorBase.purple.shade(80)); - expect(zetaColors.surfaceAvatarTeal, ZetaColorBase.teal.shade(80)); - expect(zetaColors.surfaceAvatarYellow, ZetaColorBase.yellow.shade(50)); - expect(zetaColors.surfaceSecondarySubtle, ZetaColorBase.yellow.shade(10)); - expect(zetaColors.surfacePositiveSubtle, ZetaColorBase.green.shade(10)); - expect(zetaColors.surfaceWarningSubtle, ZetaColorBase.orange.shade(10)); - expect(zetaColors.surfaceNegativeSubtle, ZetaColorBase.red.shade(10)); - expect(zetaColors.surfaceInfoSubtle, ZetaColorBase.purple.shade(10)); - expect(zetaColors.borderDefault, ZetaColorBase.cool.shade(40)); - expect(zetaColors.borderSubtle, ZetaColorBase.cool.shade(30)); - expect(zetaColors.borderHover, ZetaColorBase.cool.shade(90)); - expect(zetaColors.borderSelected, ZetaColorBase.cool.shade(90)); - expect(zetaColors.borderDisabled, ZetaColorBase.cool.shade(20)); - expect(zetaColors.borderPure, ZetaColorBase.pure.shade(0)); - expect(zetaColors.borderPrimary, ZetaColorBase.blue.shade(50)); - expect(zetaColors.borderSecondary, ZetaColorBase.yellow.shade(50)); - expect(zetaColors.borderPositive, ZetaColorBase.green.shade(50)); - expect(zetaColors.borderWarning, ZetaColorBase.orange.shade(50)); - expect(zetaColors.borderNegative, ZetaColorBase.red.shade(50)); - expect(zetaColors.borderInfo, ZetaColorBase.purple.shade(50)); - expect(zetaColors.surfacePositive, ZetaColorBase.green); - expect(zetaColors.surfaceWarning, ZetaColorBase.orange); - expect(zetaColors.surfaceNegative, ZetaColorBase.red); - expect(zetaColors.surfaceAvatarGreen, ZetaColorBase.green); - expect(zetaColors.surfaceInfo, ZetaColorBase.purple); - expect(zetaColors.borderPrimaryMain, ZetaColorBase.blue); - }); - - test('deprecated properties return correct values', () { - final zetaColors = ZetaColors(); - - expect(zetaColors.surfaceHovered, zetaColors.surfaceHover); - expect(zetaColors.surfaceSelectedHovered, zetaColors.surfaceSelectedHover); - expect(zetaColors.positive, zetaColors.surfacePositive); - expect(zetaColors.negative, zetaColors.surfaceNegative); - expect(zetaColors.warning, zetaColors.surfaceWarning); - expect(zetaColors.info, zetaColors.surfaceInfo); - expect(zetaColors.shadow, const Color(0x1A49505E)); - expect(zetaColors.link, ZetaColorBase.linkLight); - expect(zetaColors.linkVisited, ZetaColorBase.linkVisitedLight); - }); - - test('props returns correct list of properties', () { - final zetaColors = ZetaColors(); - - expect( - zetaColors.props, - [ - zetaColors.brightness, - zetaColors.contrast, - zetaColors.primary, - zetaColors.secondary, - zetaColors.error, - zetaColors.cool, - zetaColors.warm, - zetaColors.white, - zetaColors.black, - zetaColors.surfacePrimary, - zetaColors.surfaceSecondary, - zetaColors.surfaceTertiary, - ], - ); - }); - }); - - group('ZetaColorGetters', () { - test('ColorScheme extension getters should return correct colors when scheme is ZetaColorScheme', () { - final zetaColors = ZetaColors(); - final themeData = ThemeData.light().copyWith(colorScheme: zetaColors.toScheme()); - expect(themeData.colorScheme.primarySwatch, zetaColors.primary); - expect(themeData.colorScheme.secondarySwatch, zetaColors.secondary); - expect(themeData.colorScheme.cool, zetaColors.cool); - expect(themeData.colorScheme.warm, zetaColors.warm); - expect(themeData.colorScheme.textDefault, zetaColors.textDefault); - expect(themeData.colorScheme.textSubtle, zetaColors.textSubtle); - expect(themeData.colorScheme.textDisabled, zetaColors.textDisabled); - expect(themeData.colorScheme.textInverse, zetaColors.textInverse); - expect(themeData.colorScheme.surfacePrimary, zetaColors.surfacePrimary); - expect(themeData.colorScheme.surfaceSecondary, zetaColors.surfaceSecondary); - expect(themeData.colorScheme.surfaceTertiary, zetaColors.surfaceTertiary); - expect(themeData.colorScheme.surfaceDisabled, zetaColors.surfaceDisabled); - expect(themeData.colorScheme.surfaceHover, zetaColors.surfaceHover); - expect(themeData.colorScheme.surfaceSelected, zetaColors.surfaceSelected); - expect(themeData.colorScheme.surfaceSelectedHover, zetaColors.surfaceSelectedHover); - expect(themeData.colorScheme.borderDefault, zetaColors.borderDefault); - expect(themeData.colorScheme.borderSubtle, zetaColors.borderSubtle); - expect(themeData.colorScheme.borderDisabled, zetaColors.borderDisabled); - expect(themeData.colorScheme.borderSelected, zetaColors.borderSelected); - expect(themeData.colorScheme.blue, zetaColors.blue); - expect(themeData.colorScheme.green, zetaColors.green); - expect(themeData.colorScheme.red, zetaColors.red); - expect(themeData.colorScheme.orange, zetaColors.orange); - expect(themeData.colorScheme.purple, zetaColors.purple); - expect(themeData.colorScheme.yellow, zetaColors.yellow); - expect(themeData.colorScheme.teal, zetaColors.teal); - expect(themeData.colorScheme.pink, zetaColors.pink); - expect(themeData.colorScheme.positive, zetaColors.green); - expect(themeData.colorScheme.negative, zetaColors.red); - expect(themeData.colorScheme.warning, zetaColors.orange); - expect(themeData.colorScheme.info, zetaColors.purple); - }); - - test('ColorScheme extension getters should return default colors when ZetaColorScheme scheme is not injected', () { - final themeData = ThemeData.light(); - expect(themeData.colorScheme.primarySwatch, ZetaColorBase.blue); - expect(themeData.colorScheme.secondarySwatch, ZetaColorBase.yellow); - expect(themeData.colorScheme.cool, ZetaColorBase.cool); - expect(themeData.colorScheme.warm, ZetaColorBase.warm); - expect(themeData.colorScheme.textDefault, ZetaColorBase.cool.shade90); - expect(themeData.colorScheme.textSubtle, ZetaColorBase.cool.shade70); - expect(themeData.colorScheme.textDisabled, ZetaColorBase.cool.shade50); - expect(themeData.colorScheme.textInverse, ZetaColorBase.cool.shade20); - expect(themeData.colorScheme.surfacePrimary, ZetaColorBase.white); - expect(themeData.colorScheme.surfaceSecondary, ZetaColorBase.cool.shade10); - expect(themeData.colorScheme.surfaceTertiary, ZetaColorBase.warm.shade10); - expect(themeData.colorScheme.surfaceDisabled, ZetaColorBase.cool.shade30); - expect(themeData.colorScheme.surfaceHover, ZetaColorBase.cool.shade20); - expect(themeData.colorScheme.surfaceSelected, ZetaColorBase.blue.shade10); - expect(themeData.colorScheme.surfaceSelectedHover, ZetaColorBase.blue.shade20); - expect(themeData.colorScheme.borderDefault, ZetaColorBase.cool.shade50); - expect(themeData.colorScheme.borderSubtle, ZetaColorBase.cool.shade40); - expect(themeData.colorScheme.borderDisabled, ZetaColorBase.cool.shade30); - expect(themeData.colorScheme.borderSelected, ZetaColorBase.cool.shade90); - expect(themeData.colorScheme.blue, ZetaColorBase.blue); - expect(themeData.colorScheme.green, ZetaColorBase.green); - expect(themeData.colorScheme.red, ZetaColorBase.red); - expect(themeData.colorScheme.orange, ZetaColorBase.orange); - expect(themeData.colorScheme.purple, ZetaColorBase.purple); - expect(themeData.colorScheme.yellow, ZetaColorBase.yellow); - expect(themeData.colorScheme.teal, ZetaColorBase.teal); - expect(themeData.colorScheme.pink, ZetaColorBase.pink); - expect(themeData.colorScheme.positive, ZetaColorBase.green); - expect(themeData.colorScheme.negative, ZetaColorBase.red); - expect(themeData.colorScheme.warning, ZetaColorBase.orange); - expect(themeData.colorScheme.info, ZetaColorBase.purple); - }); - }); -} diff --git a/test/src/theme/contrast_test.dart b/test/src/theme/contrast_test.dart deleted file mode 100644 index fbb0ddc1..00000000 --- a/test/src/theme/contrast_test.dart +++ /dev/null @@ -1,32 +0,0 @@ -import 'package:flutter_test/flutter_test.dart'; -import 'package:zeta_flutter/src/theme/contrast.dart'; - -void main() { - group('ZetaContrast Accessibility Indices', () { - test('AA contrast indices', () { - expect(ZetaContrast.aa.primary, 60); - expect(ZetaContrast.aa.text, 60); - expect(ZetaContrast.aa.icon, 60); - expect(ZetaContrast.aa.hover, 70); - expect(ZetaContrast.aa.selected, 80); - expect(ZetaContrast.aa.focus, 80); - expect(ZetaContrast.aa.border, 60); - expect(ZetaContrast.aa.subtle, 40); - expect(ZetaContrast.aa.surface, 10); - expect(ZetaContrast.aa.targetContrast, 4.53); - }); - - test('AAA contrast indices', () { - expect(ZetaContrast.aaa.primary, 80); - expect(ZetaContrast.aaa.text, 80); - expect(ZetaContrast.aaa.icon, 80); - expect(ZetaContrast.aaa.hover, 90); - expect(ZetaContrast.aaa.selected, 100); - expect(ZetaContrast.aaa.focus, 100); - expect(ZetaContrast.aaa.border, 80); - expect(ZetaContrast.aaa.subtle, 60); - expect(ZetaContrast.aaa.surface, 10); - expect(ZetaContrast.aaa.targetContrast, 8.33); - }); - }); -} diff --git a/test/src/theme/theme_data_test.dart b/test/src/theme/theme_data_test.dart deleted file mode 100644 index 4ddeb3cb..00000000 --- a/test/src/theme/theme_data_test.dart +++ /dev/null @@ -1,62 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:zeta_flutter/src/theme/color_extensions.dart'; -import 'package:zeta_flutter/src/theme/contrast.dart'; -import 'package:zeta_flutter/src/theme/theme_data.dart'; - -void main() { - group('ZetaThemeData', () { - test('Default constructor should initialize with correct defaults', () { - final themeData = ZetaThemeData(); - - expect(themeData.fontFamily, kZetaFontFamily); - expect(themeData.identifier, 'default'); - expect(themeData.colorsLight.brightness, Brightness.light); - expect(themeData.colorsDark.brightness, Brightness.dark); - }); - - test('Constructor should initialize with custom values', () { - const customFontFamily = 'CustomFont'; - const customIdentifier = 'custom_theme'; - const customPrimary = Colors.blue; - const customSecondary = Colors.green; - - final themeData = ZetaThemeData( - fontFamily: customFontFamily, - identifier: customIdentifier, - primary: customPrimary, - secondary: customSecondary, - ); - - expect(themeData.fontFamily, customFontFamily); - expect(themeData.identifier, customIdentifier); - expect(themeData.colorsLight.primary, customPrimary.zetaColorSwatch); - expect(themeData.colorsLight.secondary, customSecondary.zetaColorSwatch); - expect(themeData.colorsDark.primary, customPrimary.zetaColorSwatch.apply(brightness: Brightness.dark)); - expect(themeData.colorsDark.secondary, customSecondary.zetaColorSwatch.apply(brightness: Brightness.dark)); - }); - - test('Apply method should return a new instance with updated contrast', () { - final themeData = ZetaThemeData(); - const newContrast = ZetaContrast.aaa; - final newThemeData = themeData.apply(contrast: newContrast); - - expect(newThemeData.colorsLight.contrast, newContrast); - expect(newThemeData.colorsDark.contrast, newContrast); - expect(newThemeData.fontFamily, themeData.fontFamily); - expect(newThemeData.identifier, themeData.identifier); - }); - - test('Equality and hashCode should work correctly', () { - final themeData1 = ZetaThemeData(); - final themeData2 = ZetaThemeData(); - - expect(themeData1, themeData2); - expect(themeData1.hashCode, themeData2.hashCode); - - final themeData3 = ZetaThemeData(identifier: 'different'); - expect(themeData1, isNot(themeData3)); - expect(themeData1.hashCode, isNot(themeData3.hashCode)); - }); - }); -} diff --git a/test/src/utils/extensions_test.dart b/test/src/utils/extensions_test.dart index 2200f757..b8b9283e 100644 --- a/test/src/utils/extensions_test.dart +++ b/test/src/utils/extensions_test.dart @@ -1,11 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; -import 'package:mockito/mockito.dart'; import 'package:zeta_flutter/zeta_flutter.dart'; import '../../test_utils/test_app.dart'; -import 'extensions_test.mocks.dart'; @GenerateNiceMocks([ MockSpec(), @@ -195,33 +193,6 @@ void main() { }); }); - group('ColorSwatches extension', () { - late MockBuildContext mockContext; - late MockZetaColors mockZetaColors; - late MockZeta mockZeta; - - setUp(() { - mockZeta = MockZeta(); - mockContext = MockBuildContext(); - mockZetaColors = MockZetaColors(); - when(mockContext.dependOnInheritedWidgetOfExactType()).thenReturn(mockZeta as Zeta?); - when(mockZeta.colors).thenReturn(mockZetaColors); - when(mockZetaColors.surfaceInfo).thenReturn(ZetaColorBase.purple); - when(mockZetaColors.surfacePositive).thenReturn(ZetaColorBase.green); - when(mockZetaColors.surfaceWarning).thenReturn(ZetaColorBase.orange); - when(mockZetaColors.surfaceNegative).thenReturn(ZetaColorBase.red); - when(mockZetaColors.cool).thenReturn(ZetaColorBase.cool); - }); - - test('colorSwatch returns correct color swatch for status', () { - expect(ZetaWidgetStatus.info.colorSwatch(mockContext), ZetaColorBase.purple); - expect(ZetaWidgetStatus.positive.colorSwatch(mockContext), ZetaColorBase.green); - expect(ZetaWidgetStatus.warning.colorSwatch(mockContext), ZetaColorBase.orange); - expect(ZetaWidgetStatus.negative.colorSwatch(mockContext), ZetaColorBase.red); - expect(ZetaWidgetStatus.neutral.colorSwatch(mockContext), ZetaColorBase.cool); - }); - }); - group('StringExtensions extension', () { test('initials returns correct initials', () { expect('John Doe'.initials, 'JD'); diff --git a/test/src/utils/extensions_test.mocks.dart b/test/src/utils/extensions_test.mocks.dart index f4c8d9a7..3fa57e86 100644 --- a/test/src/utils/extensions_test.mocks.dart +++ b/test/src/utils/extensions_test.mocks.dart @@ -7,12 +7,10 @@ import 'dart:ui' as _i5; import 'package:flutter/foundation.dart' as _i3; import 'package:flutter/material.dart' as _i2; -import 'package:flutter/src/widgets/notification_listener.dart' as _i8; +import 'package:flutter/src/widgets/notification_listener.dart' as _i7; import 'package:mockito/mockito.dart' as _i1; -import 'package:mockito/src/dummies.dart' as _i10; -import 'package:zeta_flutter/src/theme/color_scheme.dart' as _i7; -import 'package:zeta_flutter/src/theme/color_swatch.dart' as _i4; -import 'package:zeta_flutter/src/theme/contrast.dart' as _i9; +import 'package:mockito/src/dummies.dart' as _i8; +import 'package:zeta_flutter/generated/tokens/primitives.g.dart' as _i4; import 'package:zeta_flutter/zeta_flutter.dart' as _i6; // ignore_for_file: type=lint @@ -71,8 +69,8 @@ class _FakeDiagnosticsNode_2 extends _i1.SmartFake implements _i3.DiagnosticsNod super.toString(); } -class _FakeZetaColorSwatch_3 extends _i1.SmartFake implements _i4.ZetaColorSwatch { - _FakeZetaColorSwatch_3( +class _FakeZetaPrimitives_3 extends _i1.SmartFake implements _i4.ZetaPrimitives { + _FakeZetaPrimitives_3( Object parent, Invocation parentInvocation, ) : super( @@ -91,8 +89,8 @@ class _FakeColor_4 extends _i1.SmartFake implements _i5.Color { ); } -class _FakeZetaColors_5 extends _i1.SmartFake implements _i6.ZetaColors { - _FakeZetaColors_5( +class _FakeZetaSemantics_5 extends _i1.SmartFake implements _i6.ZetaSemantics { + _FakeZetaSemantics_5( Object parent, Invocation parentInvocation, ) : super( @@ -101,21 +99,8 @@ class _FakeZetaColors_5 extends _i1.SmartFake implements _i6.ZetaColors { ); } -class _FakeZetaColorScheme_6 extends _i1.SmartFake implements _i7.ZetaColorScheme { - _FakeZetaColorScheme_6( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); - - @override - String toString({_i3.DiagnosticLevel? minLevel = _i3.DiagnosticLevel.info}) => super.toString(); -} - -class _FakeZetaThemeData_7 extends _i1.SmartFake implements _i6.ZetaThemeData { - _FakeZetaThemeData_7( +class _FakeZetaColors_6 extends _i1.SmartFake implements _i6.ZetaColors { + _FakeZetaColors_6( Object parent, Invocation parentInvocation, ) : super( @@ -124,8 +109,8 @@ class _FakeZetaThemeData_7 extends _i1.SmartFake implements _i6.ZetaThemeData { ); } -class _FakeZetaRadiiSemantics_8 extends _i1.SmartFake implements _i6.ZetaRadiiSemantics { - _FakeZetaRadiiSemantics_8( +class _FakeZetaRadius_7 extends _i1.SmartFake implements _i6.ZetaRadius { + _FakeZetaRadius_7( Object parent, Invocation parentInvocation, ) : super( @@ -134,8 +119,8 @@ class _FakeZetaRadiiSemantics_8 extends _i1.SmartFake implements _i6.ZetaRadiiSe ); } -class _FakeZetaSpacingSemantics_9 extends _i1.SmartFake implements _i6.ZetaSpacingSemantics { - _FakeZetaSpacingSemantics_9( +class _FakeZetaSpacing_8 extends _i1.SmartFake implements _i6.ZetaSpacing { + _FakeZetaSpacing_8( Object parent, Invocation parentInvocation, ) : super( @@ -144,8 +129,8 @@ class _FakeZetaSpacingSemantics_9 extends _i1.SmartFake implements _i6.ZetaSpaci ); } -class _FakeInheritedElement_10 extends _i1.SmartFake implements _i2.InheritedElement { - _FakeInheritedElement_10( +class _FakeInheritedElement_9 extends _i1.SmartFake implements _i2.InheritedElement { + _FakeInheritedElement_9( Object parent, Invocation parentInvocation, ) : super( @@ -236,7 +221,7 @@ class MockBuildContext extends _i1.Mock implements _i2.BuildContext { ); @override - void dispatchNotification(_i8.Notification? notification) => super.noSuchMethod( + void dispatchNotification(_i7.Notification? notification) => super.noSuchMethod( Invocation.method( #dispatchNotification, [notification], @@ -339,487 +324,446 @@ class MockBuildContext extends _i1.Mock implements _i2.BuildContext { /// A class which mocks [ZetaColors]. /// /// See the documentation for Mockito's code generation for more information. -// ignore: must_be_immutable class MockZetaColors extends _i1.Mock implements _i6.ZetaColors { @override - _i5.Brightness get brightness => (super.noSuchMethod( - Invocation.getter(#brightness), - returnValue: _i5.Brightness.dark, - returnValueForMissingStub: _i5.Brightness.dark, - ) as _i5.Brightness); - - @override - _i9.ZetaContrast get contrast => (super.noSuchMethod( - Invocation.getter(#contrast), - returnValue: _i9.ZetaContrast.aa, - returnValueForMissingStub: _i9.ZetaContrast.aa, - ) as _i9.ZetaContrast); - - @override - _i4.ZetaColorSwatch get primary => (super.noSuchMethod( - Invocation.getter(#primary), - returnValue: _FakeZetaColorSwatch_3( + _i4.ZetaPrimitives get primitives => (super.noSuchMethod( + Invocation.getter(#primitives), + returnValue: _FakeZetaPrimitives_3( this, - Invocation.getter(#primary), + Invocation.getter(#primitives), ), - returnValueForMissingStub: _FakeZetaColorSwatch_3( + returnValueForMissingStub: _FakeZetaPrimitives_3( this, - Invocation.getter(#primary), + Invocation.getter(#primitives), ), - ) as _i4.ZetaColorSwatch); + ) as _i4.ZetaPrimitives); @override - _i4.ZetaColorSwatch get secondary => (super.noSuchMethod( - Invocation.getter(#secondary), - returnValue: _FakeZetaColorSwatch_3( - this, - Invocation.getter(#secondary), - ), - returnValueForMissingStub: _FakeZetaColorSwatch_3( - this, - Invocation.getter(#secondary), - ), - ) as _i4.ZetaColorSwatch); - - @override - _i4.ZetaColorSwatch get error => (super.noSuchMethod( - Invocation.getter(#error), - returnValue: _FakeZetaColorSwatch_3( - this, - Invocation.getter(#error), - ), - returnValueForMissingStub: _FakeZetaColorSwatch_3( - this, - Invocation.getter(#error), - ), - ) as _i4.ZetaColorSwatch); - - @override - _i4.ZetaColorSwatch get cool => (super.noSuchMethod( - Invocation.getter(#cool), - returnValue: _FakeZetaColorSwatch_3( + _i5.Color get mainDefault => (super.noSuchMethod( + Invocation.getter(#mainDefault), + returnValue: _FakeColor_4( this, - Invocation.getter(#cool), + Invocation.getter(#mainDefault), ), - returnValueForMissingStub: _FakeZetaColorSwatch_3( + returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#cool), + Invocation.getter(#mainDefault), ), - ) as _i4.ZetaColorSwatch); + ) as _i5.Color); @override - _i4.ZetaColorSwatch get warm => (super.noSuchMethod( - Invocation.getter(#warm), - returnValue: _FakeZetaColorSwatch_3( + _i5.Color get mainSubtle => (super.noSuchMethod( + Invocation.getter(#mainSubtle), + returnValue: _FakeColor_4( this, - Invocation.getter(#warm), + Invocation.getter(#mainSubtle), ), - returnValueForMissingStub: _FakeZetaColorSwatch_3( + returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#warm), + Invocation.getter(#mainSubtle), ), - ) as _i4.ZetaColorSwatch); + ) as _i5.Color); @override - _i4.ZetaColorSwatch get pure => (super.noSuchMethod( - Invocation.getter(#pure), - returnValue: _FakeZetaColorSwatch_3( + _i5.Color get mainPrimary => (super.noSuchMethod( + Invocation.getter(#mainPrimary), + returnValue: _FakeColor_4( this, - Invocation.getter(#pure), + Invocation.getter(#mainPrimary), ), - returnValueForMissingStub: _FakeZetaColorSwatch_3( + returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#pure), + Invocation.getter(#mainPrimary), ), - ) as _i4.ZetaColorSwatch); + ) as _i5.Color); @override - _i5.Color get white => (super.noSuchMethod( - Invocation.getter(#white), + _i5.Color get mainSecondary => (super.noSuchMethod( + Invocation.getter(#mainSecondary), returnValue: _FakeColor_4( this, - Invocation.getter(#white), + Invocation.getter(#mainSecondary), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#white), + Invocation.getter(#mainSecondary), ), ) as _i5.Color); @override - _i5.Color get black => (super.noSuchMethod( - Invocation.getter(#black), + _i5.Color get mainPositive => (super.noSuchMethod( + Invocation.getter(#mainPositive), returnValue: _FakeColor_4( this, - Invocation.getter(#black), + Invocation.getter(#mainPositive), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#black), + Invocation.getter(#mainPositive), ), ) as _i5.Color); @override - _i5.Color get surfacePrimary => (super.noSuchMethod( - Invocation.getter(#surfacePrimary), + _i5.Color get mainWarning => (super.noSuchMethod( + Invocation.getter(#mainWarning), returnValue: _FakeColor_4( this, - Invocation.getter(#surfacePrimary), + Invocation.getter(#mainWarning), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#surfacePrimary), + Invocation.getter(#mainWarning), ), ) as _i5.Color); @override - _i5.Color get surfaceSecondary => (super.noSuchMethod( - Invocation.getter(#surfaceSecondary), + _i5.Color get mainNegative => (super.noSuchMethod( + Invocation.getter(#mainNegative), returnValue: _FakeColor_4( this, - Invocation.getter(#surfaceSecondary), + Invocation.getter(#mainNegative), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#surfaceSecondary), + Invocation.getter(#mainNegative), ), ) as _i5.Color); @override - _i5.Color get surfaceTertiary => (super.noSuchMethod( - Invocation.getter(#surfaceTertiary), + _i5.Color get mainInfo => (super.noSuchMethod( + Invocation.getter(#mainInfo), returnValue: _FakeColor_4( this, - Invocation.getter(#surfaceTertiary), + Invocation.getter(#mainInfo), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#surfaceTertiary), + Invocation.getter(#mainInfo), ), ) as _i5.Color); @override - _i4.ZetaColorSwatch get blue => (super.noSuchMethod( - Invocation.getter(#blue), - returnValue: _FakeZetaColorSwatch_3( + _i5.Color get mainDisabled => (super.noSuchMethod( + Invocation.getter(#mainDisabled), + returnValue: _FakeColor_4( this, - Invocation.getter(#blue), + Invocation.getter(#mainDisabled), ), - returnValueForMissingStub: _FakeZetaColorSwatch_3( + returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#blue), + Invocation.getter(#mainDisabled), ), - ) as _i4.ZetaColorSwatch); + ) as _i5.Color); @override - _i4.ZetaColorSwatch get green => (super.noSuchMethod( - Invocation.getter(#green), - returnValue: _FakeZetaColorSwatch_3( + _i5.Color get mainLight => (super.noSuchMethod( + Invocation.getter(#mainLight), + returnValue: _FakeColor_4( this, - Invocation.getter(#green), + Invocation.getter(#mainLight), ), - returnValueForMissingStub: _FakeZetaColorSwatch_3( + returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#green), + Invocation.getter(#mainLight), ), - ) as _i4.ZetaColorSwatch); + ) as _i5.Color); @override - _i4.ZetaColorSwatch get red => (super.noSuchMethod( - Invocation.getter(#red), - returnValue: _FakeZetaColorSwatch_3( + _i5.Color get mainInverse => (super.noSuchMethod( + Invocation.getter(#mainInverse), + returnValue: _FakeColor_4( this, - Invocation.getter(#red), + Invocation.getter(#mainInverse), ), - returnValueForMissingStub: _FakeZetaColorSwatch_3( + returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#red), + Invocation.getter(#mainInverse), ), - ) as _i4.ZetaColorSwatch); + ) as _i5.Color); @override - _i4.ZetaColorSwatch get orange => (super.noSuchMethod( - Invocation.getter(#orange), - returnValue: _FakeZetaColorSwatch_3( + _i5.Color get textDefault => (super.noSuchMethod( + Invocation.getter(#textDefault), + returnValue: _FakeColor_4( this, - Invocation.getter(#orange), + Invocation.getter(#textDefault), ), - returnValueForMissingStub: _FakeZetaColorSwatch_3( + returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#orange), + Invocation.getter(#textDefault), ), - ) as _i4.ZetaColorSwatch); + ) as _i5.Color); @override - _i4.ZetaColorSwatch get purple => (super.noSuchMethod( - Invocation.getter(#purple), - returnValue: _FakeZetaColorSwatch_3( + _i5.Color get iconSubtle => (super.noSuchMethod( + Invocation.getter(#iconSubtle), + returnValue: _FakeColor_4( this, - Invocation.getter(#purple), + Invocation.getter(#iconSubtle), ), - returnValueForMissingStub: _FakeZetaColorSwatch_3( + returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#purple), + Invocation.getter(#iconSubtle), ), - ) as _i4.ZetaColorSwatch); + ) as _i5.Color); @override - _i4.ZetaColorSwatch get yellow => (super.noSuchMethod( - Invocation.getter(#yellow), - returnValue: _FakeZetaColorSwatch_3( + _i5.Color get iconInverse => (super.noSuchMethod( + Invocation.getter(#iconInverse), + returnValue: _FakeColor_4( this, - Invocation.getter(#yellow), + Invocation.getter(#iconInverse), ), - returnValueForMissingStub: _FakeZetaColorSwatch_3( + returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#yellow), + Invocation.getter(#iconInverse), ), - ) as _i4.ZetaColorSwatch); + ) as _i5.Color); @override - _i4.ZetaColorSwatch get teal => (super.noSuchMethod( - Invocation.getter(#teal), - returnValue: _FakeZetaColorSwatch_3( + _i5.Color get iconDisabled => (super.noSuchMethod( + Invocation.getter(#iconDisabled), + returnValue: _FakeColor_4( this, - Invocation.getter(#teal), + Invocation.getter(#iconDisabled), ), - returnValueForMissingStub: _FakeZetaColorSwatch_3( + returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#teal), + Invocation.getter(#iconDisabled), ), - ) as _i4.ZetaColorSwatch); + ) as _i5.Color); @override - _i4.ZetaColorSwatch get pink => (super.noSuchMethod( - Invocation.getter(#pink), - returnValue: _FakeZetaColorSwatch_3( + _i5.Color get iconFlavorPrimary => (super.noSuchMethod( + Invocation.getter(#iconFlavorPrimary), + returnValue: _FakeColor_4( this, - Invocation.getter(#pink), + Invocation.getter(#iconFlavorPrimary), ), - returnValueForMissingStub: _FakeZetaColorSwatch_3( + returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#pink), + Invocation.getter(#iconFlavorPrimary), ), - ) as _i4.ZetaColorSwatch); + ) as _i5.Color); @override - _i5.Color get surfaceHovered => (super.noSuchMethod( - Invocation.getter(#surfaceHovered), + _i5.Color get iconFlavorPositive => (super.noSuchMethod( + Invocation.getter(#iconFlavorPositive), returnValue: _FakeColor_4( this, - Invocation.getter(#surfaceHovered), + Invocation.getter(#iconFlavorPositive), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#surfaceHovered), + Invocation.getter(#iconFlavorPositive), ), ) as _i5.Color); @override - _i5.Color get surfaceSelectedHovered => (super.noSuchMethod( - Invocation.getter(#surfaceSelectedHovered), + _i5.Color get iconFlavorWarning => (super.noSuchMethod( + Invocation.getter(#iconFlavorWarning), returnValue: _FakeColor_4( this, - Invocation.getter(#surfaceSelectedHovered), + Invocation.getter(#iconFlavorWarning), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#surfaceSelectedHovered), + Invocation.getter(#iconFlavorWarning), ), ) as _i5.Color); @override - _i4.ZetaColorSwatch get positive => (super.noSuchMethod( - Invocation.getter(#positive), - returnValue: _FakeZetaColorSwatch_3( + _i5.Color get iconFlavorNegative => (super.noSuchMethod( + Invocation.getter(#iconFlavorNegative), + returnValue: _FakeColor_4( this, - Invocation.getter(#positive), + Invocation.getter(#iconFlavorNegative), ), - returnValueForMissingStub: _FakeZetaColorSwatch_3( + returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#positive), + Invocation.getter(#iconFlavorNegative), ), - ) as _i4.ZetaColorSwatch); + ) as _i5.Color); @override - _i4.ZetaColorSwatch get negative => (super.noSuchMethod( - Invocation.getter(#negative), - returnValue: _FakeZetaColorSwatch_3( + _i5.Color get iconFlavorInfo => (super.noSuchMethod( + Invocation.getter(#iconFlavorInfo), + returnValue: _FakeColor_4( this, - Invocation.getter(#negative), + Invocation.getter(#iconFlavorInfo), ), - returnValueForMissingStub: _FakeZetaColorSwatch_3( + returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#negative), + Invocation.getter(#iconFlavorInfo), ), - ) as _i4.ZetaColorSwatch); + ) as _i5.Color); @override - _i4.ZetaColorSwatch get warning => (super.noSuchMethod( - Invocation.getter(#warning), - returnValue: _FakeZetaColorSwatch_3( + _i5.Color get borderDefault => (super.noSuchMethod( + Invocation.getter(#borderDefault), + returnValue: _FakeColor_4( this, - Invocation.getter(#warning), + Invocation.getter(#borderDefault), ), - returnValueForMissingStub: _FakeZetaColorSwatch_3( + returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#warning), + Invocation.getter(#borderDefault), ), - ) as _i4.ZetaColorSwatch); + ) as _i5.Color); @override - _i4.ZetaColorSwatch get info => (super.noSuchMethod( - Invocation.getter(#info), - returnValue: _FakeZetaColorSwatch_3( + _i5.Color get borderSelected => (super.noSuchMethod( + Invocation.getter(#borderSelected), + returnValue: _FakeColor_4( this, - Invocation.getter(#info), + Invocation.getter(#borderSelected), ), - returnValueForMissingStub: _FakeZetaColorSwatch_3( + returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#info), + Invocation.getter(#borderSelected), ), - ) as _i4.ZetaColorSwatch); + ) as _i5.Color); @override - _i5.Color get shadow => (super.noSuchMethod( - Invocation.getter(#shadow), + _i5.Color get borderHover => (super.noSuchMethod( + Invocation.getter(#borderHover), returnValue: _FakeColor_4( this, - Invocation.getter(#shadow), + Invocation.getter(#borderHover), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#shadow), + Invocation.getter(#borderHover), ), ) as _i5.Color); @override - _i5.Color get link => (super.noSuchMethod( - Invocation.getter(#link), + _i5.Color get borderSubtle => (super.noSuchMethod( + Invocation.getter(#borderSubtle), returnValue: _FakeColor_4( this, - Invocation.getter(#link), + Invocation.getter(#borderSubtle), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#link), + Invocation.getter(#borderSubtle), ), ) as _i5.Color); @override - _i5.Color get linkVisited => (super.noSuchMethod( - Invocation.getter(#linkVisited), + _i5.Color get borderDisabled => (super.noSuchMethod( + Invocation.getter(#borderDisabled), returnValue: _FakeColor_4( this, - Invocation.getter(#linkVisited), + Invocation.getter(#borderDisabled), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#linkVisited), + Invocation.getter(#borderDisabled), ), ) as _i5.Color); @override - _i5.Color get textDefault => (super.noSuchMethod( - Invocation.getter(#textDefault), + _i5.Color get borderPure => (super.noSuchMethod( + Invocation.getter(#borderPure), returnValue: _FakeColor_4( this, - Invocation.getter(#textDefault), + Invocation.getter(#borderPure), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#textDefault), + Invocation.getter(#borderPure), ), ) as _i5.Color); @override - _i5.Color get textSubtle => (super.noSuchMethod( - Invocation.getter(#textSubtle), + _i5.Color get borderPrimaryMain => (super.noSuchMethod( + Invocation.getter(#borderPrimaryMain), returnValue: _FakeColor_4( this, - Invocation.getter(#textSubtle), + Invocation.getter(#borderPrimaryMain), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#textSubtle), + Invocation.getter(#borderPrimaryMain), ), ) as _i5.Color); @override - _i5.Color get textDisabled => (super.noSuchMethod( - Invocation.getter(#textDisabled), + _i5.Color get borderPrimary => (super.noSuchMethod( + Invocation.getter(#borderPrimary), returnValue: _FakeColor_4( this, - Invocation.getter(#textDisabled), + Invocation.getter(#borderPrimary), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#textDisabled), + Invocation.getter(#borderPrimary), ), ) as _i5.Color); @override - _i5.Color get textInverse => (super.noSuchMethod( - Invocation.getter(#textInverse), + _i5.Color get borderSecondary => (super.noSuchMethod( + Invocation.getter(#borderSecondary), returnValue: _FakeColor_4( this, - Invocation.getter(#textInverse), + Invocation.getter(#borderSecondary), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#textInverse), + Invocation.getter(#borderSecondary), ), ) as _i5.Color); @override - _i5.Color get iconDefault => (super.noSuchMethod( - Invocation.getter(#iconDefault), + _i5.Color get borderPositive => (super.noSuchMethod( + Invocation.getter(#borderPositive), returnValue: _FakeColor_4( this, - Invocation.getter(#iconDefault), + Invocation.getter(#borderPositive), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#iconDefault), + Invocation.getter(#borderPositive), ), ) as _i5.Color); @override - _i5.Color get iconSubtle => (super.noSuchMethod( - Invocation.getter(#iconSubtle), + _i5.Color get borderWarning => (super.noSuchMethod( + Invocation.getter(#borderWarning), returnValue: _FakeColor_4( this, - Invocation.getter(#iconSubtle), + Invocation.getter(#borderWarning), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#iconSubtle), + Invocation.getter(#borderWarning), ), ) as _i5.Color); @override - _i5.Color get iconDisabled => (super.noSuchMethod( - Invocation.getter(#iconDisabled), + _i5.Color get borderNegative => (super.noSuchMethod( + Invocation.getter(#borderNegative), returnValue: _FakeColor_4( this, - Invocation.getter(#iconDisabled), + Invocation.getter(#borderNegative), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#iconDisabled), + Invocation.getter(#borderNegative), ), ) as _i5.Color); @override - _i5.Color get iconInverse => (super.noSuchMethod( - Invocation.getter(#iconInverse), + _i5.Color get borderInfo => (super.noSuchMethod( + Invocation.getter(#borderInfo), returnValue: _FakeColor_4( this, - Invocation.getter(#iconInverse), + Invocation.getter(#borderInfo), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#iconInverse), + Invocation.getter(#borderInfo), ), ) as _i5.Color); @@ -927,6 +871,19 @@ class MockZetaColors extends _i1.Mock implements _i6.ZetaColors { ), ) as _i5.Color); + @override + _i5.Color get surfacePrimary => (super.noSuchMethod( + Invocation.getter(#surfacePrimary), + returnValue: _FakeColor_4( + this, + Invocation.getter(#surfacePrimary), + ), + returnValueForMissingStub: _FakeColor_4( + this, + Invocation.getter(#surfacePrimary), + ), + ) as _i5.Color); + @override _i5.Color get surfacePrimarySubtle => (super.noSuchMethod( Invocation.getter(#surfacePrimarySubtle), @@ -940,6 +897,19 @@ class MockZetaColors extends _i1.Mock implements _i6.ZetaColors { ), ) as _i5.Color); + @override + _i5.Color get surfaceSecondary => (super.noSuchMethod( + Invocation.getter(#surfaceSecondary), + returnValue: _FakeColor_4( + this, + Invocation.getter(#surfaceSecondary), + ), + returnValueForMissingStub: _FakeColor_4( + this, + Invocation.getter(#surfaceSecondary), + ), + ) as _i5.Color); + @override _i5.Color get surfaceAvatarBlue => (super.noSuchMethod( Invocation.getter(#surfaceAvatarBlue), @@ -954,17 +924,17 @@ class MockZetaColors extends _i1.Mock implements _i6.ZetaColors { ) as _i5.Color); @override - _i4.ZetaColorSwatch get surfaceAvatarGreen => (super.noSuchMethod( + _i5.Color get surfaceAvatarGreen => (super.noSuchMethod( Invocation.getter(#surfaceAvatarGreen), - returnValue: _FakeZetaColorSwatch_3( + returnValue: _FakeColor_4( this, Invocation.getter(#surfaceAvatarGreen), ), - returnValueForMissingStub: _FakeZetaColorSwatch_3( + returnValueForMissingStub: _FakeColor_4( this, Invocation.getter(#surfaceAvatarGreen), ), - ) as _i4.ZetaColorSwatch); + ) as _i5.Color); @override _i5.Color get surfaceAvatarOrange => (super.noSuchMethod( @@ -1045,17 +1015,17 @@ class MockZetaColors extends _i1.Mock implements _i6.ZetaColors { ) as _i5.Color); @override - _i4.ZetaColorSwatch get surfacePositive => (super.noSuchMethod( + _i5.Color get surfacePositive => (super.noSuchMethod( Invocation.getter(#surfacePositive), - returnValue: _FakeZetaColorSwatch_3( + returnValue: _FakeColor_4( this, Invocation.getter(#surfacePositive), ), - returnValueForMissingStub: _FakeZetaColorSwatch_3( + returnValueForMissingStub: _FakeColor_4( this, Invocation.getter(#surfacePositive), ), - ) as _i4.ZetaColorSwatch); + ) as _i5.Color); @override _i5.Color get surfacePositiveSubtle => (super.noSuchMethod( @@ -1071,17 +1041,17 @@ class MockZetaColors extends _i1.Mock implements _i6.ZetaColors { ) as _i5.Color); @override - _i4.ZetaColorSwatch get surfaceWarning => (super.noSuchMethod( + _i5.Color get surfaceWarning => (super.noSuchMethod( Invocation.getter(#surfaceWarning), - returnValue: _FakeZetaColorSwatch_3( + returnValue: _FakeColor_4( this, Invocation.getter(#surfaceWarning), ), - returnValueForMissingStub: _FakeZetaColorSwatch_3( + returnValueForMissingStub: _FakeColor_4( this, Invocation.getter(#surfaceWarning), ), - ) as _i4.ZetaColorSwatch); + ) as _i5.Color); @override _i5.Color get surfaceWarningSubtle => (super.noSuchMethod( @@ -1097,17 +1067,17 @@ class MockZetaColors extends _i1.Mock implements _i6.ZetaColors { ) as _i5.Color); @override - _i4.ZetaColorSwatch get surfaceNegative => (super.noSuchMethod( + _i5.Color get surfaceNegative => (super.noSuchMethod( Invocation.getter(#surfaceNegative), - returnValue: _FakeZetaColorSwatch_3( + returnValue: _FakeColor_4( this, Invocation.getter(#surfaceNegative), ), - returnValueForMissingStub: _FakeZetaColorSwatch_3( + returnValueForMissingStub: _FakeColor_4( this, Invocation.getter(#surfaceNegative), ), - ) as _i4.ZetaColorSwatch); + ) as _i5.Color); @override _i5.Color get surfaceNegativeSubtle => (super.noSuchMethod( @@ -1123,17 +1093,17 @@ class MockZetaColors extends _i1.Mock implements _i6.ZetaColors { ) as _i5.Color); @override - _i4.ZetaColorSwatch get surfaceInfo => (super.noSuchMethod( + _i5.Color get surfaceInfo => (super.noSuchMethod( Invocation.getter(#surfaceInfo), - returnValue: _FakeZetaColorSwatch_3( + returnValue: _FakeColor_4( this, Invocation.getter(#surfaceInfo), ), - returnValueForMissingStub: _FakeZetaColorSwatch_3( + returnValueForMissingStub: _FakeColor_4( this, Invocation.getter(#surfaceInfo), ), - ) as _i4.ZetaColorSwatch); + ) as _i5.Color); @override _i5.Color get surfaceInfoSubtle => (super.noSuchMethod( @@ -1149,338 +1119,381 @@ class MockZetaColors extends _i1.Mock implements _i6.ZetaColors { ) as _i5.Color); @override - _i5.Color get borderDefault => (super.noSuchMethod( - Invocation.getter(#borderDefault), + _i5.Color get stateDisabledDisabled => (super.noSuchMethod( + Invocation.getter(#stateDisabledDisabled), returnValue: _FakeColor_4( this, - Invocation.getter(#borderDefault), + Invocation.getter(#stateDisabledDisabled), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#borderDefault), + Invocation.getter(#stateDisabledDisabled), ), ) as _i5.Color); @override - _i5.Color get borderSubtle => (super.noSuchMethod( - Invocation.getter(#borderSubtle), + _i5.Color get stateDefaultEnabled => (super.noSuchMethod( + Invocation.getter(#stateDefaultEnabled), returnValue: _FakeColor_4( this, - Invocation.getter(#borderSubtle), + Invocation.getter(#stateDefaultEnabled), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#borderSubtle), + Invocation.getter(#stateDefaultEnabled), ), ) as _i5.Color); @override - _i5.Color get borderHover => (super.noSuchMethod( - Invocation.getter(#borderHover), + _i5.Color get stateDefaultHover => (super.noSuchMethod( + Invocation.getter(#stateDefaultHover), returnValue: _FakeColor_4( this, - Invocation.getter(#borderHover), + Invocation.getter(#stateDefaultHover), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#borderHover), + Invocation.getter(#stateDefaultHover), ), ) as _i5.Color); @override - _i5.Color get borderSelected => (super.noSuchMethod( - Invocation.getter(#borderSelected), + _i5.Color get stateDefaultSelected => (super.noSuchMethod( + Invocation.getter(#stateDefaultSelected), returnValue: _FakeColor_4( this, - Invocation.getter(#borderSelected), + Invocation.getter(#stateDefaultSelected), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#borderSelected), + Invocation.getter(#stateDefaultSelected), ), ) as _i5.Color); @override - _i5.Color get borderDisabled => (super.noSuchMethod( - Invocation.getter(#borderDisabled), + _i5.Color get stateDefaultFocus => (super.noSuchMethod( + Invocation.getter(#stateDefaultFocus), returnValue: _FakeColor_4( this, - Invocation.getter(#borderDisabled), + Invocation.getter(#stateDefaultFocus), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#borderDisabled), + Invocation.getter(#stateDefaultFocus), ), ) as _i5.Color); @override - _i5.Color get borderPure => (super.noSuchMethod( - Invocation.getter(#borderPure), + _i5.Color get statePrimaryEnabled => (super.noSuchMethod( + Invocation.getter(#statePrimaryEnabled), returnValue: _FakeColor_4( this, - Invocation.getter(#borderPure), + Invocation.getter(#statePrimaryEnabled), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#borderPure), + Invocation.getter(#statePrimaryEnabled), ), ) as _i5.Color); @override - _i4.ZetaColorSwatch get borderPrimaryMain => (super.noSuchMethod( - Invocation.getter(#borderPrimaryMain), - returnValue: _FakeZetaColorSwatch_3( + _i5.Color get statePrimaryHover => (super.noSuchMethod( + Invocation.getter(#statePrimaryHover), + returnValue: _FakeColor_4( this, - Invocation.getter(#borderPrimaryMain), + Invocation.getter(#statePrimaryHover), ), - returnValueForMissingStub: _FakeZetaColorSwatch_3( + returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#borderPrimaryMain), + Invocation.getter(#statePrimaryHover), ), - ) as _i4.ZetaColorSwatch); + ) as _i5.Color); @override - _i5.Color get borderPrimary => (super.noSuchMethod( - Invocation.getter(#borderPrimary), + _i5.Color get statePrimarySelected => (super.noSuchMethod( + Invocation.getter(#statePrimarySelected), returnValue: _FakeColor_4( this, - Invocation.getter(#borderPrimary), + Invocation.getter(#statePrimarySelected), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#borderPrimary), + Invocation.getter(#statePrimarySelected), ), ) as _i5.Color); @override - _i5.Color get borderSecondary => (super.noSuchMethod( - Invocation.getter(#borderSecondary), + _i5.Color get statePrimaryFocus => (super.noSuchMethod( + Invocation.getter(#statePrimaryFocus), returnValue: _FakeColor_4( this, - Invocation.getter(#borderSecondary), + Invocation.getter(#statePrimaryFocus), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#borderSecondary), + Invocation.getter(#statePrimaryFocus), ), ) as _i5.Color); @override - _i5.Color get borderPositive => (super.noSuchMethod( - Invocation.getter(#borderPositive), + _i5.Color get stateSecondaryEnabled => (super.noSuchMethod( + Invocation.getter(#stateSecondaryEnabled), returnValue: _FakeColor_4( this, - Invocation.getter(#borderPositive), + Invocation.getter(#stateSecondaryEnabled), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#borderPositive), + Invocation.getter(#stateSecondaryEnabled), ), ) as _i5.Color); @override - _i5.Color get borderWarning => (super.noSuchMethod( - Invocation.getter(#borderWarning), + _i5.Color get stateSecondaryHover => (super.noSuchMethod( + Invocation.getter(#stateSecondaryHover), returnValue: _FakeColor_4( this, - Invocation.getter(#borderWarning), + Invocation.getter(#stateSecondaryHover), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#borderWarning), + Invocation.getter(#stateSecondaryHover), ), ) as _i5.Color); @override - _i5.Color get borderNegative => (super.noSuchMethod( - Invocation.getter(#borderNegative), + _i5.Color get stateSecondarySelected => (super.noSuchMethod( + Invocation.getter(#stateSecondarySelected), returnValue: _FakeColor_4( this, - Invocation.getter(#borderNegative), + Invocation.getter(#stateSecondarySelected), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#borderNegative), + Invocation.getter(#stateSecondarySelected), ), ) as _i5.Color); @override - _i5.Color get borderInfo => (super.noSuchMethod( - Invocation.getter(#borderInfo), + _i5.Color get stateSecondaryFocus => (super.noSuchMethod( + Invocation.getter(#stateSecondaryFocus), returnValue: _FakeColor_4( this, - Invocation.getter(#borderInfo), + Invocation.getter(#stateSecondaryFocus), ), returnValueForMissingStub: _FakeColor_4( this, - Invocation.getter(#borderInfo), + Invocation.getter(#stateSecondaryFocus), ), ) as _i5.Color); @override - bool get isDarkMode => (super.noSuchMethod( - Invocation.getter(#isDarkMode), - returnValue: false, - returnValueForMissingStub: false, - ) as bool); + _i5.Color get stateNegativeEnabled => (super.noSuchMethod( + Invocation.getter(#stateNegativeEnabled), + returnValue: _FakeColor_4( + this, + Invocation.getter(#stateNegativeEnabled), + ), + returnValueForMissingStub: _FakeColor_4( + this, + Invocation.getter(#stateNegativeEnabled), + ), + ) as _i5.Color); @override - List<_i4.ZetaColorSwatch> get rainbow => (super.noSuchMethod( - Invocation.getter(#rainbow), - returnValue: <_i4.ZetaColorSwatch>[], - returnValueForMissingStub: <_i4.ZetaColorSwatch>[], - ) as List<_i4.ZetaColorSwatch>); - - @override - Map get rainbowMap => (super.noSuchMethod( - Invocation.getter(#rainbowMap), - returnValue: {}, - returnValueForMissingStub: {}, - ) as Map); - - @override - List get props => (super.noSuchMethod( - Invocation.getter(#props), - returnValue: [], - returnValueForMissingStub: [], - ) as List); - - @override - _i6.ZetaColors copyWith({ - _i5.Brightness? brightness, - _i9.ZetaContrast? contrast, - _i4.ZetaColorSwatch? primary, - _i4.ZetaColorSwatch? secondary, - _i4.ZetaColorSwatch? error, - _i4.ZetaColorSwatch? cool, - _i4.ZetaColorSwatch? warm, - _i5.Color? white, - _i5.Color? black, - _i5.Color? surfacePrimary, - _i5.Color? surfaceSecondary, - _i5.Color? surfaceTertiary, - _i5.Color? link, - _i5.Color? linkVisited, - _i5.Color? shadow, - }) => - (super.noSuchMethod( - Invocation.method( - #copyWith, - [], - { - #brightness: brightness, - #contrast: contrast, - #primary: primary, - #secondary: secondary, - #error: error, - #cool: cool, - #warm: warm, - #white: white, - #black: black, - #surfacePrimary: surfacePrimary, - #surfaceSecondary: surfaceSecondary, - #surfaceTertiary: surfaceTertiary, - #link: link, - #linkVisited: linkVisited, - #shadow: shadow, - }, + _i5.Color get stateNegativeHover => (super.noSuchMethod( + Invocation.getter(#stateNegativeHover), + returnValue: _FakeColor_4( + this, + Invocation.getter(#stateNegativeHover), ), - returnValue: _FakeZetaColors_5( + returnValueForMissingStub: _FakeColor_4( this, - Invocation.method( - #copyWith, - [], - { - #brightness: brightness, - #contrast: contrast, - #primary: primary, - #secondary: secondary, - #error: error, - #cool: cool, - #warm: warm, - #white: white, - #black: black, - #surfacePrimary: surfacePrimary, - #surfaceSecondary: surfaceSecondary, - #surfaceTertiary: surfaceTertiary, - #link: link, - #linkVisited: linkVisited, - #shadow: shadow, - }, - ), + Invocation.getter(#stateNegativeHover), ), - returnValueForMissingStub: _FakeZetaColors_5( + ) as _i5.Color); + + @override + _i5.Color get stateNegativeSelected => (super.noSuchMethod( + Invocation.getter(#stateNegativeSelected), + returnValue: _FakeColor_4( this, - Invocation.method( - #copyWith, - [], - { - #brightness: brightness, - #contrast: contrast, - #primary: primary, - #secondary: secondary, - #error: error, - #cool: cool, - #warm: warm, - #white: white, - #black: black, - #surfacePrimary: surfacePrimary, - #surfaceSecondary: surfaceSecondary, - #surfaceTertiary: surfaceTertiary, - #link: link, - #linkVisited: linkVisited, - #shadow: shadow, - }, - ), + Invocation.getter(#stateNegativeSelected), ), - ) as _i6.ZetaColors); + returnValueForMissingStub: _FakeColor_4( + this, + Invocation.getter(#stateNegativeSelected), + ), + ) as _i5.Color); @override - _i6.ZetaColors apply({required _i9.ZetaContrast? contrast}) => (super.noSuchMethod( - Invocation.method( - #apply, - [], - {#contrast: contrast}, + _i5.Color get stateNegativeFocus => (super.noSuchMethod( + Invocation.getter(#stateNegativeFocus), + returnValue: _FakeColor_4( + this, + Invocation.getter(#stateNegativeFocus), ), - returnValue: _FakeZetaColors_5( + returnValueForMissingStub: _FakeColor_4( this, - Invocation.method( - #apply, - [], - {#contrast: contrast}, - ), + Invocation.getter(#stateNegativeFocus), ), - returnValueForMissingStub: _FakeZetaColors_5( + ) as _i5.Color); + + @override + _i5.Color get stateInfoEnabled => (super.noSuchMethod( + Invocation.getter(#stateInfoEnabled), + returnValue: _FakeColor_4( this, - Invocation.method( - #apply, - [], - {#contrast: contrast}, - ), + Invocation.getter(#stateInfoEnabled), ), - ) as _i6.ZetaColors); + returnValueForMissingStub: _FakeColor_4( + this, + Invocation.getter(#stateInfoEnabled), + ), + ) as _i5.Color); @override - _i7.ZetaColorScheme toScheme() => (super.noSuchMethod( - Invocation.method( - #toScheme, - [], + _i5.Color get stateInfoHover => (super.noSuchMethod( + Invocation.getter(#stateInfoHover), + returnValue: _FakeColor_4( + this, + Invocation.getter(#stateInfoHover), ), - returnValue: _FakeZetaColorScheme_6( + returnValueForMissingStub: _FakeColor_4( this, - Invocation.method( - #toScheme, - [], - ), + Invocation.getter(#stateInfoHover), ), - returnValueForMissingStub: _FakeZetaColorScheme_6( + ) as _i5.Color); + + @override + _i5.Color get stateInfoSelected => (super.noSuchMethod( + Invocation.getter(#stateInfoSelected), + returnValue: _FakeColor_4( this, - Invocation.method( - #toScheme, - [], - ), + Invocation.getter(#stateInfoSelected), + ), + returnValueForMissingStub: _FakeColor_4( + this, + Invocation.getter(#stateInfoSelected), + ), + ) as _i5.Color); + + @override + _i5.Color get stateInfoFocus => (super.noSuchMethod( + Invocation.getter(#stateInfoFocus), + returnValue: _FakeColor_4( + this, + Invocation.getter(#stateInfoFocus), + ), + returnValueForMissingStub: _FakeColor_4( + this, + Invocation.getter(#stateInfoFocus), + ), + ) as _i5.Color); + + @override + _i5.Color get stateInverseEnabled => (super.noSuchMethod( + Invocation.getter(#stateInverseEnabled), + returnValue: _FakeColor_4( + this, + Invocation.getter(#stateInverseEnabled), ), - ) as _i7.ZetaColorScheme); + returnValueForMissingStub: _FakeColor_4( + this, + Invocation.getter(#stateInverseEnabled), + ), + ) as _i5.Color); + + @override + _i5.Color get stateInverseHover => (super.noSuchMethod( + Invocation.getter(#stateInverseHover), + returnValue: _FakeColor_4( + this, + Invocation.getter(#stateInverseHover), + ), + returnValueForMissingStub: _FakeColor_4( + this, + Invocation.getter(#stateInverseHover), + ), + ) as _i5.Color); + + @override + _i5.Color get stateInverseSelected => (super.noSuchMethod( + Invocation.getter(#stateInverseSelected), + returnValue: _FakeColor_4( + this, + Invocation.getter(#stateInverseSelected), + ), + returnValueForMissingStub: _FakeColor_4( + this, + Invocation.getter(#stateInverseSelected), + ), + ) as _i5.Color); + + @override + _i5.Color get stateInverseFocus => (super.noSuchMethod( + Invocation.getter(#stateInverseFocus), + returnValue: _FakeColor_4( + this, + Invocation.getter(#stateInverseFocus), + ), + returnValueForMissingStub: _FakeColor_4( + this, + Invocation.getter(#stateInverseFocus), + ), + ) as _i5.Color); + + @override + _i5.Color get statePositiveEnabled => (super.noSuchMethod( + Invocation.getter(#statePositiveEnabled), + returnValue: _FakeColor_4( + this, + Invocation.getter(#statePositiveEnabled), + ), + returnValueForMissingStub: _FakeColor_4( + this, + Invocation.getter(#statePositiveEnabled), + ), + ) as _i5.Color); + + @override + _i5.Color get statePositiveHover => (super.noSuchMethod( + Invocation.getter(#statePositiveHover), + returnValue: _FakeColor_4( + this, + Invocation.getter(#statePositiveHover), + ), + returnValueForMissingStub: _FakeColor_4( + this, + Invocation.getter(#statePositiveHover), + ), + ) as _i5.Color); + + @override + _i5.Color get statePositiveSelected => (super.noSuchMethod( + Invocation.getter(#statePositiveSelected), + returnValue: _FakeColor_4( + this, + Invocation.getter(#statePositiveSelected), + ), + returnValueForMissingStub: _FakeColor_4( + this, + Invocation.getter(#statePositiveSelected), + ), + ) as _i5.Color); + + @override + _i5.Color get statePositiveFocus => (super.noSuchMethod( + Invocation.getter(#statePositiveFocus), + returnValue: _FakeColor_4( + this, + Invocation.getter(#statePositiveFocus), + ), + returnValueForMissingStub: _FakeColor_4( + this, + Invocation.getter(#statePositiveFocus), + ), + ) as _i5.Color); } /// A class which mocks [Zeta]. @@ -1488,11 +1501,18 @@ class MockZetaColors extends _i1.Mock implements _i6.ZetaColors { /// See the documentation for Mockito's code generation for more information. class MockZeta extends _i1.Mock implements _i6.Zeta { @override - _i9.ZetaContrast get contrast => (super.noSuchMethod( + bool get rounded => (super.noSuchMethod( + Invocation.getter(#rounded), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); + + @override + _i6.ZetaContrast get contrast => (super.noSuchMethod( Invocation.getter(#contrast), - returnValue: _i9.ZetaContrast.aa, - returnValueForMissingStub: _i9.ZetaContrast.aa, - ) as _i9.ZetaContrast); + returnValue: _i6.ZetaContrast.aa, + returnValueForMissingStub: _i6.ZetaContrast.aa, + ) as _i6.ZetaContrast); @override _i2.ThemeMode get themeMode => (super.noSuchMethod( @@ -1502,33 +1522,39 @@ class MockZeta extends _i1.Mock implements _i6.Zeta { ) as _i2.ThemeMode); @override - _i6.ZetaThemeData get themeData => (super.noSuchMethod( - Invocation.getter(#themeData), - returnValue: _FakeZetaThemeData_7( + _i4.ZetaPrimitives get primitives => (super.noSuchMethod( + Invocation.getter(#primitives), + returnValue: _FakeZetaPrimitives_3( this, - Invocation.getter(#themeData), + Invocation.getter(#primitives), ), - returnValueForMissingStub: _FakeZetaThemeData_7( + returnValueForMissingStub: _FakeZetaPrimitives_3( this, - Invocation.getter(#themeData), + Invocation.getter(#primitives), ), - ) as _i6.ZetaThemeData); + ) as _i4.ZetaPrimitives); @override - bool get rounded => (super.noSuchMethod( - Invocation.getter(#rounded), - returnValue: false, - returnValueForMissingStub: false, - ) as bool); + _i6.ZetaSemantics get semantics => (super.noSuchMethod( + Invocation.getter(#semantics), + returnValue: _FakeZetaSemantics_5( + this, + Invocation.getter(#semantics), + ), + returnValueForMissingStub: _FakeZetaSemantics_5( + this, + Invocation.getter(#semantics), + ), + ) as _i6.ZetaSemantics); @override _i6.ZetaColors get colors => (super.noSuchMethod( Invocation.getter(#colors), - returnValue: _FakeZetaColors_5( + returnValue: _FakeZetaColors_6( this, Invocation.getter(#colors), ), - returnValueForMissingStub: _FakeZetaColors_5( + returnValueForMissingStub: _FakeZetaColors_6( this, Invocation.getter(#colors), ), @@ -1542,30 +1568,30 @@ class MockZeta extends _i1.Mock implements _i6.Zeta { ) as _i5.Brightness); @override - _i6.ZetaRadiiSemantics get radius => (super.noSuchMethod( + _i6.ZetaRadius get radius => (super.noSuchMethod( Invocation.getter(#radius), - returnValue: _FakeZetaRadiiSemantics_8( + returnValue: _FakeZetaRadius_7( this, Invocation.getter(#radius), ), - returnValueForMissingStub: _FakeZetaRadiiSemantics_8( + returnValueForMissingStub: _FakeZetaRadius_7( this, Invocation.getter(#radius), ), - ) as _i6.ZetaRadiiSemantics); + ) as _i6.ZetaRadius); @override - _i6.ZetaSpacingSemantics get spacing => (super.noSuchMethod( + _i6.ZetaSpacing get spacing => (super.noSuchMethod( Invocation.getter(#spacing), - returnValue: _FakeZetaSpacingSemantics_9( + returnValue: _FakeZetaSpacing_8( this, Invocation.getter(#spacing), ), - returnValueForMissingStub: _FakeZetaSpacingSemantics_9( + returnValueForMissingStub: _FakeZetaSpacing_8( this, Invocation.getter(#spacing), ), - ) as _i6.ZetaSpacingSemantics); + ) as _i6.ZetaSpacing); @override _i2.Widget get child => (super.noSuchMethod( @@ -1605,14 +1631,14 @@ class MockZeta extends _i1.Mock implements _i6.Zeta { #createElement, [], ), - returnValue: _FakeInheritedElement_10( + returnValue: _FakeInheritedElement_9( this, Invocation.method( #createElement, [], ), ), - returnValueForMissingStub: _FakeInheritedElement_10( + returnValueForMissingStub: _FakeInheritedElement_9( this, Invocation.method( #createElement, @@ -1627,14 +1653,14 @@ class MockZeta extends _i1.Mock implements _i6.Zeta { #toStringShort, [], ), - returnValue: _i10.dummyValue( + returnValue: _i8.dummyValue( this, Invocation.method( #toStringShort, [], ), ), - returnValueForMissingStub: _i10.dummyValue( + returnValueForMissingStub: _i8.dummyValue( this, Invocation.method( #toStringShort, @@ -1657,7 +1683,7 @@ class MockZeta extends _i1.Mock implements _i6.Zeta { #minLevel: minLevel, }, ), - returnValue: _i10.dummyValue( + returnValue: _i8.dummyValue( this, Invocation.method( #toStringShallow, @@ -1668,7 +1694,7 @@ class MockZeta extends _i1.Mock implements _i6.Zeta { }, ), ), - returnValueForMissingStub: _i10.dummyValue( + returnValueForMissingStub: _i8.dummyValue( this, Invocation.method( #toStringShallow, @@ -1697,7 +1723,7 @@ class MockZeta extends _i1.Mock implements _i6.Zeta { #minLevel: minLevel, }, ), - returnValue: _i10.dummyValue( + returnValue: _i8.dummyValue( this, Invocation.method( #toStringDeep, @@ -1709,7 +1735,7 @@ class MockZeta extends _i1.Mock implements _i6.Zeta { }, ), ), - returnValueForMissingStub: _i10.dummyValue( + returnValueForMissingStub: _i8.dummyValue( this, Invocation.method( #toStringDeep, diff --git a/test/src/utils/rounded_test.dart b/test/src/utils/rounded_test.dart index ebfae397..bb3f68bc 100644 --- a/test/src/utils/rounded_test.dart +++ b/test/src/utils/rounded_test.dart @@ -16,7 +16,7 @@ void main() { testWidgets('Global round inherited', (WidgetTester tester) async { final GlobalKey key = GlobalKey(); - when(mockZeta.radius).thenReturn(const ZetaRadiiAA(primitives: ZetaPrimitivesLight())); + when(mockZeta.radius).thenReturn(const ZetaRadiusAA(primitives: ZetaPrimitivesLight())); await tester.pumpWidget( TestApp( rounded: true, diff --git a/test/src/utils/rounded_test.mocks.dart b/test/src/utils/rounded_test.mocks.dart index 1ea97859..170b9921 100644 --- a/test/src/utils/rounded_test.mocks.dart +++ b/test/src/utils/rounded_test.mocks.dart @@ -24,8 +24,8 @@ import 'package:zeta_flutter/zeta_flutter.dart' as _i2; // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class -class _FakeZetaThemeData_0 extends _i1.SmartFake implements _i2.ZetaThemeData { - _FakeZetaThemeData_0( +class _FakeZetaPrimitives_0 extends _i1.SmartFake implements _i2.ZetaPrimitives { + _FakeZetaPrimitives_0( Object parent, Invocation parentInvocation, ) : super( @@ -34,8 +34,8 @@ class _FakeZetaThemeData_0 extends _i1.SmartFake implements _i2.ZetaThemeData { ); } -class _FakeZetaColors_1 extends _i1.SmartFake implements _i2.ZetaColors { - _FakeZetaColors_1( +class _FakeZetaSemantics_1 extends _i1.SmartFake implements _i2.ZetaSemantics { + _FakeZetaSemantics_1( Object parent, Invocation parentInvocation, ) : super( @@ -44,8 +44,8 @@ class _FakeZetaColors_1 extends _i1.SmartFake implements _i2.ZetaColors { ); } -class _FakeZetaRadiiSemantics_2 extends _i1.SmartFake implements _i2.ZetaRadiiSemantics { - _FakeZetaRadiiSemantics_2( +class _FakeZetaColors_2 extends _i1.SmartFake implements _i2.ZetaColors { + _FakeZetaColors_2( Object parent, Invocation parentInvocation, ) : super( @@ -54,8 +54,8 @@ class _FakeZetaRadiiSemantics_2 extends _i1.SmartFake implements _i2.ZetaRadiiSe ); } -class _FakeZetaSpacingSemantics_3 extends _i1.SmartFake implements _i2.ZetaSpacingSemantics { - _FakeZetaSpacingSemantics_3( +class _FakeZetaRadius_3 extends _i1.SmartFake implements _i2.ZetaRadius { + _FakeZetaRadius_3( Object parent, Invocation parentInvocation, ) : super( @@ -64,8 +64,18 @@ class _FakeZetaSpacingSemantics_3 extends _i1.SmartFake implements _i2.ZetaSpaci ); } -class _FakeWidget_4 extends _i1.SmartFake implements _i3.Widget { - _FakeWidget_4( +class _FakeZetaSpacing_4 extends _i1.SmartFake implements _i2.ZetaSpacing { + _FakeZetaSpacing_4( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeWidget_5 extends _i1.SmartFake implements _i3.Widget { + _FakeWidget_5( Object parent, Invocation parentInvocation, ) : super( @@ -77,8 +87,8 @@ class _FakeWidget_4 extends _i1.SmartFake implements _i3.Widget { String toString({_i4.DiagnosticLevel? minLevel = _i4.DiagnosticLevel.info}) => super.toString(); } -class _FakeInheritedElement_5 extends _i1.SmartFake implements _i3.InheritedElement { - _FakeInheritedElement_5( +class _FakeInheritedElement_6 extends _i1.SmartFake implements _i3.InheritedElement { + _FakeInheritedElement_6( Object parent, Invocation parentInvocation, ) : super( @@ -90,8 +100,8 @@ class _FakeInheritedElement_5 extends _i1.SmartFake implements _i3.InheritedElem String toString({_i4.DiagnosticLevel? minLevel = _i4.DiagnosticLevel.info}) => super.toString(); } -class _FakeDiagnosticsNode_6 extends _i1.SmartFake implements _i4.DiagnosticsNode { - _FakeDiagnosticsNode_6( +class _FakeDiagnosticsNode_7 extends _i1.SmartFake implements _i4.DiagnosticsNode { + _FakeDiagnosticsNode_7( Object parent, Invocation parentInvocation, ) : super( @@ -111,6 +121,13 @@ class _FakeDiagnosticsNode_6 extends _i1.SmartFake implements _i4.DiagnosticsNod /// /// See the documentation for Mockito's code generation for more information. class MockZeta extends _i1.Mock implements _i2.Zeta { + @override + bool get rounded => (super.noSuchMethod( + Invocation.getter(#rounded), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); + @override _i2.ZetaContrast get contrast => (super.noSuchMethod( Invocation.getter(#contrast), @@ -126,33 +143,39 @@ class MockZeta extends _i1.Mock implements _i2.Zeta { ) as _i3.ThemeMode); @override - _i2.ZetaThemeData get themeData => (super.noSuchMethod( - Invocation.getter(#themeData), - returnValue: _FakeZetaThemeData_0( + _i2.ZetaPrimitives get primitives => (super.noSuchMethod( + Invocation.getter(#primitives), + returnValue: _FakeZetaPrimitives_0( this, - Invocation.getter(#themeData), + Invocation.getter(#primitives), ), - returnValueForMissingStub: _FakeZetaThemeData_0( + returnValueForMissingStub: _FakeZetaPrimitives_0( this, - Invocation.getter(#themeData), + Invocation.getter(#primitives), ), - ) as _i2.ZetaThemeData); + ) as _i2.ZetaPrimitives); @override - bool get rounded => (super.noSuchMethod( - Invocation.getter(#rounded), - returnValue: false, - returnValueForMissingStub: false, - ) as bool); + _i2.ZetaSemantics get semantics => (super.noSuchMethod( + Invocation.getter(#semantics), + returnValue: _FakeZetaSemantics_1( + this, + Invocation.getter(#semantics), + ), + returnValueForMissingStub: _FakeZetaSemantics_1( + this, + Invocation.getter(#semantics), + ), + ) as _i2.ZetaSemantics); @override _i2.ZetaColors get colors => (super.noSuchMethod( Invocation.getter(#colors), - returnValue: _FakeZetaColors_1( + returnValue: _FakeZetaColors_2( this, Invocation.getter(#colors), ), - returnValueForMissingStub: _FakeZetaColors_1( + returnValueForMissingStub: _FakeZetaColors_2( this, Invocation.getter(#colors), ), @@ -166,39 +189,39 @@ class MockZeta extends _i1.Mock implements _i2.Zeta { ) as _i5.Brightness); @override - _i2.ZetaRadiiSemantics get radius => (super.noSuchMethod( + _i2.ZetaRadius get radius => (super.noSuchMethod( Invocation.getter(#radius), - returnValue: _FakeZetaRadiiSemantics_2( + returnValue: _FakeZetaRadius_3( this, Invocation.getter(#radius), ), - returnValueForMissingStub: _FakeZetaRadiiSemantics_2( + returnValueForMissingStub: _FakeZetaRadius_3( this, Invocation.getter(#radius), ), - ) as _i2.ZetaRadiiSemantics); + ) as _i2.ZetaRadius); @override - _i2.ZetaSpacingSemantics get spacing => (super.noSuchMethod( + _i2.ZetaSpacing get spacing => (super.noSuchMethod( Invocation.getter(#spacing), - returnValue: _FakeZetaSpacingSemantics_3( + returnValue: _FakeZetaSpacing_4( this, Invocation.getter(#spacing), ), - returnValueForMissingStub: _FakeZetaSpacingSemantics_3( + returnValueForMissingStub: _FakeZetaSpacing_4( this, Invocation.getter(#spacing), ), - ) as _i2.ZetaSpacingSemantics); + ) as _i2.ZetaSpacing); @override _i3.Widget get child => (super.noSuchMethod( Invocation.getter(#child), - returnValue: _FakeWidget_4( + returnValue: _FakeWidget_5( this, Invocation.getter(#child), ), - returnValueForMissingStub: _FakeWidget_4( + returnValueForMissingStub: _FakeWidget_5( this, Invocation.getter(#child), ), @@ -229,14 +252,14 @@ class MockZeta extends _i1.Mock implements _i2.Zeta { #createElement, [], ), - returnValue: _FakeInheritedElement_5( + returnValue: _FakeInheritedElement_6( this, Invocation.method( #createElement, [], ), ), - returnValueForMissingStub: _FakeInheritedElement_5( + returnValueForMissingStub: _FakeInheritedElement_6( this, Invocation.method( #createElement, @@ -361,7 +384,7 @@ class MockZeta extends _i1.Mock implements _i2.Zeta { #style: style, }, ), - returnValue: _FakeDiagnosticsNode_6( + returnValue: _FakeDiagnosticsNode_7( this, Invocation.method( #toDiagnosticsNode, @@ -372,7 +395,7 @@ class MockZeta extends _i1.Mock implements _i2.Zeta { }, ), ), - returnValueForMissingStub: _FakeDiagnosticsNode_6( + returnValueForMissingStub: _FakeDiagnosticsNode_7( this, Invocation.method( #toDiagnosticsNode, diff --git a/test/src/utils/zeta_provider_test.dart b/test/src/utils/zeta_provider_test.dart new file mode 100644 index 00000000..a08910b8 --- /dev/null +++ b/test/src/utils/zeta_provider_test.dart @@ -0,0 +1,658 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/annotations.dart'; +import 'package:mockito/mockito.dart'; +import 'package:zeta_flutter/src/utils/zeta_provider.dart'; +import 'package:zeta_flutter/zeta_flutter.dart'; + +import '../../test_utils/utils.dart'; +import './zeta_provider_test.mocks.dart'; + +@GenerateNiceMocks([MockSpec()]) +void main() { + group('ZetaProvider', () { + late MockZetaThemeService mockThemeService; + + setUp(() async { + mockThemeService = MockZetaThemeService(); + + when(mockThemeService.loadTheme()).thenAnswer( + (_) async => const ZetaThemeServiceData(), + ); + when(mockThemeService.saveTheme(themeData: anyNamed('themeData'))).thenAnswer( + (_) async => {}, + ); + }); + + group('initializers', () { + testWidgets('initializes with correct default values', (WidgetTester tester) async { + await tester.pumpWidget( + ZetaProvider(builder: (context, light, dark, themeMode) => Container()), + ); + + final providerState = tester.state(find.byType(ZetaProvider)); + expect(providerState.widget.initialThemeMode, null); + expect(providerState.widget.initialContrast, null); + expect(providerState.widget.customThemes, []); + expect(providerState.widget.initialRounded, true); + expect(providerState.widget.initialTheme, null); + + expect(providerState.widget.themeService.runtimeType, ZetaDefaultThemeService); + }); + + testWidgets('initializes with provided values', (WidgetTester tester) async { + final themes = [ZetaCustomTheme(id: '1')]; + await tester.pumpWidget( + ZetaProvider( + builder: (context, light, dark, themeMode) => Container(), + initialThemeMode: ThemeMode.light, + initialContrast: ZetaContrast.aaa, + themeService: mockThemeService, + initialRounded: false, + initialTheme: '1', + customThemes: themes, + ), + ); + + final providerState = tester.state(find.byType(ZetaProvider)); + expect(providerState.widget.initialThemeMode, ThemeMode.light); + expect(providerState.widget.initialContrast, ZetaContrast.aaa); + expect(providerState.widget.themeService, mockThemeService); + expect(providerState.widget.initialTheme, '1'); + expect(providerState.widget.customThemes, themes); + expect(providerState.widget.initialRounded, false); + }); + + testWidgets('initializes values in Zeta', (WidgetTester tester) async { + await tester.pumpWidget( + ZetaProvider( + builder: (context, light, dark, themeMode) => Container(), + themeService: mockThemeService, + initialThemeMode: ThemeMode.dark, + initialContrast: ZetaContrast.aaa, + customLoadingWidget: const SizedBox(), + ), + ); + await tester.pumpAndSettle(); + + final zeta = tester.widget(find.byType(Zeta)); + + expect(zeta.themeMode, ThemeMode.dark); + expect(zeta.contrast, ZetaContrast.aaa); + }); + }); + + group('updates state', () { + late ZetaProvider subject; + + setUp(() { + subject = ZetaProvider( + builder: (context, light, dark, themeMode) => Container(), + initialThemeMode: ThemeMode.light, + themeService: mockThemeService, + ); + }); + + testWidgets('updateThemeMode updates the state correctly', (WidgetTester tester) async { + await tester.pumpWidget(subject); + + tester.state(find.byType(ZetaProvider)).updateThemeMode(ThemeMode.dark); + await tester.pump(); + + final zeta = tester.widget(find.byType(Zeta)); + + // Verifying through the public interface of Zeta widget + expect(zeta.themeMode, ThemeMode.dark); + }); + + testWidgets('updateContrast updates the state correctly', (WidgetTester tester) async { + await tester.pumpWidget(subject); + + tester.state(find.byType(ZetaProvider)).updateContrast(ZetaContrast.aaa); + await tester.pump(); + + // Verifying through the public interface of Zeta widget + final zeta = tester.widget(find.byType(Zeta)); + + expect(zeta.contrast, ZetaContrast.aaa); + }); + + testWidgets('updateRounded updates the state correctly', (WidgetTester tester) async { + await tester.pumpWidget(subject); + + tester.state(find.byType(ZetaProvider)).updateRounded(false); + await tester.pump(); + + // Verifying through the public interface of Zeta widget + final zeta = tester.widget(find.byType(Zeta)); + + expect(zeta.rounded, false); + }); + }); + + group('didUpdateWidget', () { + late ZetaProvider subject; + + setUp(() { + subject = ZetaProvider( + builder: (context, light, dark, themeMode) => Container(), + initialThemeMode: ThemeMode.light, + themeService: mockThemeService, + ); + }); + + testWidgets('didUpdateWidget in ZetaProviderState works correctly with change in ThemeMode', + (WidgetTester tester) async { + await tester.pumpWidget(subject); + + await tester.pump(); + // Verifying through the public interface of Zeta widget + expect(tester.widget(find.byType(Zeta)).themeMode, ThemeMode.light); + + await tester.pumpWidget( + ZetaProvider( + initialThemeMode: ThemeMode.dark, + customLoadingWidget: const SizedBox(), + builder: (context, light, dark, themeMode) => Builder( + builder: (context) { + return Container(); + }, + ), + ), + ); + + await tester.pumpAndSettle(const Duration(milliseconds: 250)); + + // Verifying through the public interface of Zeta widget + expect(tester.widget(find.byType(Zeta)).themeMode, ThemeMode.dark); + }); + + testWidgets('didUpdateWidget in ZetaProviderState works correctly with change in contrast', + (WidgetTester tester) async { + await tester.pumpWidget(subject); + + await tester.pumpAndSettle(); + + // Verifying through the public interface of Zeta widget + expect(tester.widget(find.byType(Zeta)).contrast, ZetaContrast.aa); + + await tester.pumpWidget( + ZetaProvider( + initialContrast: ZetaContrast.aaa, + builder: (context, light, dark, themeMode) => Builder( + builder: (context) { + return Container(); + }, + ), + ), + ); + + await tester.pumpAndSettle(const Duration(milliseconds: 250)); + + // Verifying through the public interface of Zeta widget + expect(tester.widget(find.byType(Zeta)).contrast, ZetaContrast.aaa); + }); + + testWidgets('didUpdateWidget in ZetaProviderState works correctly with change rounded', + (WidgetTester tester) async { + await tester.pumpWidget(subject); + + await tester.pumpAndSettle(); + + // Verifying through the public interface of Zeta widget + expect(tester.widget(find.byType(Zeta)).rounded, true); + + await tester.pumpWidget( + ZetaProvider( + initialRounded: false, + themeService: mockThemeService, + customLoadingWidget: const SizedBox(), + builder: (context, light, dark, themeMode) => Builder( + builder: (context) { + return Container(); + }, + ), + ), + ); + + await tester.pumpAndSettle(); + + // Verifying through the public interface of Zeta widget + expect(tester.widget(find.byType(Zeta)).rounded, false); + }); + }); + + testWidgets('retrieves ZetaProviderState from context', (WidgetTester tester) async { + await tester.pumpWidget( + ZetaProvider( + themeService: mockThemeService, + builder: (context, light, dark, themeMode) => Builder( + builder: (context) { + final providerState = ZetaProvider.of(context); + expect(providerState, isNotNull); + return Container(); + }, + ), + ), + ); + }); + + testWidgets('throws error if ZetaProvider is not found in widget tree', (WidgetTester tester) async { + await tester.pumpWidget( + Builder( + builder: (context) { + expect(() => ZetaProvider.of(context), throwsA(isA())); + return Container(); + }, + ), + ); + }); + + testWidgets('handles platform brightness changes', (WidgetTester tester) async { + const Key k = Key('1'); + await tester.pumpWidget( + ZetaProvider( + initialThemeMode: ThemeMode.system, + themeService: mockThemeService, + builder: (context, light, dark, themeMode) => Container(key: k), + ), + ); + + // Rebuild the widget tree + await tester.pump(Durations.extralong4); + + // Get test binding + final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized(); + + // Simulate platform brightness change to dark + binding.platformDispatcher.platformBrightnessTestValue = Brightness.dark; + + await tester.pump(Durations.extralong4); + final zeta = Zeta.of(tester.element(find.byKey(k))); + + // Verifying through the public interface of Zeta widget + // It is important to check here that zeta.brightness is changed to dark, + // as this shows if themeMode.system actually works. + expect(zeta.brightness, Brightness.dark); + }); + + testWidgets('generateZetaTheme applies zeta values to existing theme', (WidgetTester tester) async { + final ColorScheme colors = ColorScheme.fromSeed(seedColor: Colors.red); + final theme = generateZetaTheme( + brightness: Brightness.light, + colorScheme: const ZetaColorsAA(primitives: ZetaPrimitivesLight()).toColorScheme, + existingTheme: ThemeData( + fontFamily: 'Comic Sans', + primaryColor: Colors.red, + useMaterial3: false, + scaffoldBackgroundColor: Colors.blue, + colorScheme: colors, + ), + ); + expect(theme.useMaterial3, false); + expect(theme.brightness, Brightness.light); + expect(theme.primaryColor, Colors.red); + expect(theme.scaffoldBackgroundColor, Colors.blue); + + final theme2 = generateZetaTheme( + brightness: Brightness.light, + colorScheme: colors, + existingTheme: ThemeData( + fontFamily: 'Comic Sans', + primaryColor: Colors.red, + useMaterial3: false, + colorScheme: colors, + scaffoldBackgroundColor: Colors.orange, + ), + ); + expect(theme2.useMaterial3, false); + expect(theme2.brightness, Brightness.light); + expect(theme2.primaryColor, Colors.red); + + expect(theme2.scaffoldBackgroundColor, Colors.orange); + }); + + testWidgets('generateZetaTheme generates a new theme', (WidgetTester tester) async { + final colorScheme = const ZetaColorsAA(primitives: ZetaPrimitivesLight()).toColorScheme; + + final theme = generateZetaTheme( + brightness: Brightness.light, + colorScheme: colorScheme, + ); + + expect(theme.useMaterial3, true); + expect(theme.brightness, Brightness.light); + expect(colorScheme, theme.colorScheme); + }); + + group('custom theme', () { + late ZetaProvider subject; + + final customPrimary = ZetaColorSwatch.fromColor(Colors.red); + + final customThemes = [ + ZetaCustomTheme(id: '1', primary: customPrimary), + ZetaCustomTheme(id: '2', primary: Colors.orange), + ]; + + setUp(() { + subject = ZetaProvider( + themeService: mockThemeService, + customThemes: customThemes, + initialThemeMode: ThemeMode.light, + initialTheme: '1', + builder: (_, __, ___, ____) => const SizedBox(), + ); + }); + + testWidgets('initial theme gets set correctly', (tester) async { + await tester.pumpWidget(subject); + + await tester.pump(); + + final zeta = tester.widget(find.byType(Zeta)); + + expect(zeta.primitives.primary, customPrimary); + }); + + testWidgets('customThemeId getter works as expected', (tester) async { + await tester.pumpWidget(subject); + + await tester.pump(); + + final providerState = tester.widget(find.byType(Zeta)); + + expect(providerState.customThemeId, '1'); + }); + + testWidgets('custom themes can be changed', (tester) async { + await tester.pumpWidget(subject); + await tester.pump(); + + final newThemes = [ + ZetaCustomTheme(id: '3', primary: Colors.blue), + ZetaCustomTheme(id: '4', primary: Colors.green), + ]; + ZetaProviderState providerState = tester.state(find.byType(ZetaProvider)) + ..setCustomThemes(newThemes); + + await tester.pump(); + + providerState = tester.state(find.byType(ZetaProvider)); + + expect(providerState.customThemes, newThemes); + }); + + testWidgets('updateCustomTheme works as expected', (tester) async { + await tester.pumpWidget(subject); + await tester.pump(); + + tester + .state( + find.byType(ZetaProvider), + ) + .updateCustomTheme(themeId: '2'); + await tester.pump(); + + final zeta = tester.widget(find.byType(Zeta)); + + expect(zeta.customThemeId, '2'); + }); + }); + + group('theme service', () { + group('load theme', () { + setUp(() async { + when(mockThemeService.loadTheme()).thenAnswer( + (_) async => const ZetaThemeServiceData( + contrast: ZetaContrast.aaa, + themeMode: ThemeMode.dark, + themeId: '1', + ), + ); + }); + + testWidgets('loads a custom theme correctly', (tester) async { + final customThemes = [ + ZetaCustomTheme(id: '1', primary: Colors.red), + ]; + + await tester.pumpWidget( + ZetaProvider( + themeService: mockThemeService, + customThemes: customThemes, + builder: (_, __, ___, ____) { + return const SizedBox(); + }, + ), + ); + await tester.pump(); + + final zeta = tester.widget(find.byType(Zeta)); + + verify(mockThemeService.loadTheme()).called(1); + expect(zeta.customThemeId, '1'); + expect(zeta.themeMode, ThemeMode.dark); + expect(zeta.contrast, ZetaContrast.aaa); + }); + + testWidgets('theme is not loaded if all defaults are given to provider and no custom themes are provided', + (tester) async { + await tester.pumpWidget( + ZetaProvider( + themeService: mockThemeService, + initialThemeMode: ThemeMode.light, + initialContrast: ZetaContrast.aa, + builder: (_, __, ___, ____) { + return const SizedBox(); + }, + ), + ); + await tester.pump(); + + verifyNever(mockThemeService.loadTheme()); + }); + + testWidgets('theme is not loaded if all defaults are given to provider and custom themes contains initialTheme', + (tester) async { + final customThemes = [ + ZetaCustomTheme(id: '1', primary: Colors.red), + ]; + + await tester.pumpWidget( + ZetaProvider( + themeService: mockThemeService, + customThemes: customThemes, + initialThemeMode: ThemeMode.light, + initialContrast: ZetaContrast.aa, + initialTheme: '1', + builder: (_, __, ___, ____) { + return const SizedBox(); + }, + ), + ); + await tester.pump(); + + verifyNever(mockThemeService.loadTheme()); + }); + + testWidgets('theme is loaded if some defaults are given to provider', (tester) async { + final customThemes = [ + ZetaCustomTheme(id: '1', primary: Colors.red), + ]; + + await tester.pumpWidget( + ZetaProvider( + themeService: mockThemeService, + customThemes: customThemes, + initialThemeMode: ThemeMode.light, + builder: (_, __, ___, ____) { + return const SizedBox(); + }, + ), + ); + await tester.pump(); + + verify(mockThemeService.loadTheme()).called(1); + }); + + testWidgets( + 'theme is loaded if all other defaults are specified but custom themes does not contain initialTheme', + (tester) async { + await tester.pumpWidget( + ZetaProvider( + themeService: mockThemeService, + initialContrast: ZetaContrast.aa, + customThemes: [ + ZetaCustomTheme(id: '1', primary: Colors.red), + ], + initialTheme: 'not found', + initialThemeMode: ThemeMode.light, + builder: (_, __, ___, ____) { + return const SizedBox(); + }, + ), + ); + await tester.pump(); + + verify(mockThemeService.loadTheme()).called(1); + }); + + testWidgets('use default theme if saved custom theme is not found by theme service', (tester) async { + when(mockThemeService.loadTheme()).thenAnswer( + (_) async => const ZetaThemeServiceData(themeId: 'this theme does not exist'), + ); + + await tester.pumpWidget( + ZetaProvider( + themeService: mockThemeService, + initialThemeMode: ThemeMode.light, + initialContrast: ZetaContrast.aa, + builder: (_, __, ___, ____) { + return const SizedBox(); + }, + ), + ); + await tester.pump(); + + final zeta = tester.widget(find.byType(Zeta)); + + expect(zeta.customThemeId, null); + expect( + zeta.colors.primitives.primary, + const ZetaPrimitivesLight().primary, + ); + }); + }); + + group('save theme', () { + late ZetaProvider subject; + + setUp(() { + subject = ZetaProvider( + themeService: mockThemeService, + builder: (context, light, dark, themeMode) => Container(), + ); + }); + + testWidgets('saveTheme is called when theme mode is updated', (tester) async { + await tester.pumpWidget(subject); + await tester.pumpAndSettle(); + + tester.state(find.byType(ZetaProvider)).updateThemeMode(ThemeMode.dark); + + await tester.pumpAndSettle(); + + verify(mockThemeService.saveTheme(themeData: anyNamed('themeData'))).called(1); + }); + + testWidgets('saveTheme is called when contrast is updated', (tester) async { + await tester.pumpWidget(subject); + await tester.pumpAndSettle(); + + tester.state(find.byType(ZetaProvider)).updateContrast(ZetaContrast.aaa); + + await tester.pumpAndSettle(); + + verify(mockThemeService.saveTheme(themeData: anyNamed('themeData'))).called(1); + }); + + testWidgets('saveTheme is called when theme id is updated', (tester) async { + await tester.pumpWidget(subject); + await tester.pumpAndSettle(); + + tester.state(find.byType(ZetaProvider)).updateCustomTheme(themeId: '2'); + + await tester.pumpAndSettle(); + + verify(mockThemeService.saveTheme(themeData: anyNamed('themeData'))).called(1); + }); + }); + }); + + group('debugFillProperties', () { + testWidgets('ZetaProvider debugFillProperties works correctly', (WidgetTester tester) async { + final diagnostics = DiagnosticPropertiesBuilder(); + + ZetaProvider( + builder: (context, light, dark, themeMode) => Container(), + themeService: mockThemeService, + initialContrast: ZetaContrast.aa, + initialRounded: false, + initialThemeMode: ThemeMode.system, + ).debugFillProperties(diagnostics); + + expect(diagnostics.finder('builder'), 'has builder'); + expect(diagnostics.finder('initialThemeMode'), ThemeMode.system.name); + expect(diagnostics.finder('initialContrast'), ZetaContrast.aa.name); + expect(diagnostics.finder('themeService'), 'MockZetaThemeService'); + expect(diagnostics.finder('initialRounded'), 'false'); + expect(diagnostics.finder('customThemes'), '[]'); + expect(diagnostics.finder('initialTheme'), 'null'); + }); + + testWidgets('ZetaProviderState debugFillProperties works correctly', (WidgetTester tester) async { + final diagnostics = DiagnosticPropertiesBuilder(); + + await tester.pumpWidget( + ZetaProvider( + builder: (context, light, dark, themeMode) => Container(), + themeService: mockThemeService, + initialContrast: ZetaContrast.aa, + initialRounded: false, + initialThemeMode: ThemeMode.system, + ), + ); + + await tester.pump(); + tester.state(find.byType(ZetaProvider)).debugFillProperties(diagnostics); + + expect(diagnostics.finder('themeMode'), ThemeMode.system.name); + expect(diagnostics.finder('contrast'), ZetaContrast.aa.name); + expect(diagnostics.finder('customThemes'), '[]'); + expect(diagnostics.finder('customTheme'), 'null'); + }); + + testWidgets('InternalProvider debugFillProperties works correctly', (WidgetTester tester) async { + final diagnostics = DiagnosticPropertiesBuilder(); + + InternalProvider( + contrast: ZetaContrast.aa, + themeMode: ThemeMode.dark, + rounded: false, + customTheme: null, + customThemes: const [], + widget: (context, light, dark, themeMode) => Container(), + ).debugFillProperties(diagnostics); + + expect(diagnostics.finder('widget'), 'has widget'); + expect(diagnostics.finder('themeMode'), ThemeMode.dark.name); + expect(diagnostics.finder('contrast'), ZetaContrast.aa.name); + expect(diagnostics.finder('rounded'), 'false'); + expect(diagnostics.finder('customThemes'), '[]'); + expect(diagnostics.finder('customTheme'), 'null'); + }); + }); + }); +} diff --git a/test/src/zeta_provider_test.mocks.dart b/test/src/utils/zeta_provider_test.mocks.dart similarity index 57% rename from test/src/zeta_provider_test.mocks.dart rename to test/src/utils/zeta_provider_test.mocks.dart index 04681f4b..a46853a6 100644 --- a/test/src/zeta_provider_test.mocks.dart +++ b/test/src/utils/zeta_provider_test.mocks.dart @@ -1,14 +1,11 @@ // Mocks generated by Mockito 5.4.4 from annotations -// in zeta_flutter/test/src/zeta_provider_test.dart. +// in zeta_flutter/test/src/utils/zeta_provider_test.dart. // Do not manually edit this file. // ignore_for_file: no_leading_underscores_for_library_prefixes import 'dart:async' as _i3; -import 'package:flutter/material.dart' as _i5; import 'package:mockito/mockito.dart' as _i1; -import 'package:zeta_flutter/src/theme/contrast.dart' as _i6; -import 'package:zeta_flutter/src/theme/theme_data.dart' as _i4; import 'package:zeta_flutter/src/theme/theme_service.dart' as _i2; // ignore_for_file: type=lint @@ -24,36 +21,48 @@ import 'package:zeta_flutter/src/theme/theme_service.dart' as _i2; // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +class _FakeZetaThemeServiceData_0 extends _i1.SmartFake implements _i2.ZetaThemeServiceData { + _FakeZetaThemeServiceData_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + /// A class which mocks [ZetaThemeService]. /// /// See the documentation for Mockito's code generation for more information. class MockZetaThemeService extends _i1.Mock implements _i2.ZetaThemeService { @override - _i3.Future<(_i4.ZetaThemeData?, _i5.ThemeMode?, _i6.ZetaContrast?)> loadTheme() => (super.noSuchMethod( + _i3.Future<_i2.ZetaThemeServiceData> loadTheme() => (super.noSuchMethod( Invocation.method( #loadTheme, [], ), - returnValue: _i3.Future<(_i4.ZetaThemeData?, _i5.ThemeMode?, _i6.ZetaContrast?)>.value((null, null, null)), - returnValueForMissingStub: - _i3.Future<(_i4.ZetaThemeData?, _i5.ThemeMode?, _i6.ZetaContrast?)>.value((null, null, null)), - ) as _i3.Future<(_i4.ZetaThemeData?, _i5.ThemeMode?, _i6.ZetaContrast?)>); + returnValue: _i3.Future<_i2.ZetaThemeServiceData>.value(_FakeZetaThemeServiceData_0( + this, + Invocation.method( + #loadTheme, + [], + ), + )), + returnValueForMissingStub: _i3.Future<_i2.ZetaThemeServiceData>.value(_FakeZetaThemeServiceData_0( + this, + Invocation.method( + #loadTheme, + [], + ), + )), + ) as _i3.Future<_i2.ZetaThemeServiceData>); @override - _i3.Future saveTheme({ - required _i4.ZetaThemeData? themeData, - required _i5.ThemeMode? themeMode, - required _i6.ZetaContrast? contrast, - }) => - (super.noSuchMethod( + _i3.Future saveTheme({required _i2.ZetaThemeServiceData? themeData}) => (super.noSuchMethod( Invocation.method( #saveTheme, [], - { - #themeData: themeData, - #themeMode: themeMode, - #contrast: contrast, - }, + {#themeData: themeData}, ), returnValue: _i3.Future.value(), returnValueForMissingStub: _i3.Future.value(), diff --git a/test/src/utils/zeta_test.dart b/test/src/utils/zeta_test.dart new file mode 100644 index 00000000..4ea52d56 --- /dev/null +++ b/test/src/utils/zeta_test.dart @@ -0,0 +1,342 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:zeta_flutter/zeta_flutter.dart'; + +import '../../test_utils/utils.dart'; + +void main() { + group('Zeta InheritedWidget', () { + testWidgets('provides correct default colors in light mode', (WidgetTester tester) async { + await tester.pumpWidget( + Zeta( + themeMode: ThemeMode.light, + child: Container(), + ), + ); + + await tester.pumpAndSettle(); + + final zeta = Zeta.of(tester.element(find.byType(Container))).colors; + + expect(zeta, const ZetaColorsAA(primitives: ZetaPrimitivesLight())); + }); + + testWidgets('provides correct default colors in dark mode', (WidgetTester tester) async { + await tester.pumpWidget( + Zeta( + themeMode: ThemeMode.dark, + child: Container(), + ), + ); + + await tester.pumpAndSettle(); + + final zeta = Zeta.of(tester.element(find.byType(Container))); + expect(zeta.colors, const ZetaColorsAA(primitives: ZetaPrimitivesDark())); + }); + + testWidgets('provides AAA colors in light mode', (WidgetTester tester) async { + await tester.pumpWidget( + Zeta( + themeMode: ThemeMode.light, + contrast: ZetaContrast.aaa, + child: Container(), + ), + ); + + await tester.pumpAndSettle(); + + final zeta = Zeta.of(tester.element(find.byType(Container))); + + expect(zeta.colors, const ZetaColorsAAA(primitives: ZetaPrimitivesLight())); + }); + + testWidgets('provides AAA colors in dark mode', (WidgetTester tester) async { + await tester.pumpWidget( + Zeta( + themeMode: ThemeMode.dark, + contrast: ZetaContrast.aaa, + child: Container(), + ), + ); + + await tester.pumpAndSettle(); + + final zeta = Zeta.of(tester.element(find.byType(Container))); + + expect(zeta.colors, const ZetaColorsAAA(primitives: ZetaPrimitivesDark())); + }); + + testWidgets('provides custom primitives in light mode', (WidgetTester tester) async { + await tester.pumpWidget( + Zeta( + themeMode: ThemeMode.light, + customPrimitives: const ZetaPrimitivesDark(), + child: Container(), + ), + ); + + await tester.pumpAndSettle(); + + final zeta = Zeta.of(tester.element(find.byType(Container))); + + /// We set custom primitives to be dark, even though the theme mode is light. + expect(zeta.colors, const ZetaColorsAA(primitives: ZetaPrimitivesDark())); + }); + + testWidgets('provides custom primitives in dark mode', (WidgetTester tester) async { + await tester.pumpWidget( + Zeta( + themeMode: ThemeMode.dark, + customPrimitives: const ZetaPrimitivesLight(), + child: Container(), + ), + ); + + await tester.pumpAndSettle(); + + final zeta = Zeta.of(tester.element(find.byType(Container))); + + /// We set custom primitives to be light, even though the theme mode is dark. + expect(zeta.colors, const ZetaColorsAA(primitives: ZetaPrimitivesLight())); + }); + + testWidgets('provides custom semantics in AA mode', (WidgetTester tester) async { + await tester.pumpWidget( + Zeta( + // ignore: avoid_redundant_argument_values + contrast: ZetaContrast.aa, + customSemantics: ZetaSemanticsAAA(primitives: const ZetaPrimitivesLight()), + child: Container(), + ), + ); + + await tester.pumpAndSettle(); + + final zeta = Zeta.of(tester.element(find.byType(Container))); + + /// We set custom primitives to be AAA, even though the contrast is AA. + expect(zeta.colors, const ZetaColorsAAA(primitives: ZetaPrimitivesLight())); + }); + + testWidgets('provides custom semantics in AAA mode', (WidgetTester tester) async { + await tester.pumpWidget( + Zeta( + contrast: ZetaContrast.aaa, + customSemantics: ZetaSemanticsAA(primitives: const ZetaPrimitivesLight()), + child: Container(), + ), + ); + + await tester.pumpAndSettle(); + + final zeta = Zeta.of(tester.element(find.byType(Container))); + + /// We set custom primitives to be AA, even though the contrast is AAA. + expect(zeta.colors, const ZetaColorsAA(primitives: ZetaPrimitivesLight())); + }); + + testWidgets('provides size tokens', (WidgetTester tester) async { + await tester.pumpWidget( + Zeta( + themeMode: ThemeMode.light, + child: Container(), + ), + ); + + await tester.pumpAndSettle(); + final zeta = Zeta.of(tester.element(find.byType(Container))); + + expect(zeta.spacing, const ZetaSpacingAA(primitives: ZetaPrimitivesLight())); + }); + + testWidgets('provides radius tokens', (WidgetTester tester) async { + await tester.pumpWidget( + Zeta( + themeMode: ThemeMode.light, + child: Container(), + ), + ); + + await tester.pumpAndSettle(); + final zeta = Zeta.of(tester.element(find.byType(Container))); + + expect(zeta.radius, const ZetaRadiusAA(primitives: ZetaPrimitivesLight())); + }); + + testWidgets('throws FlutterError if Zeta is not found in widget tree', (WidgetTester tester) async { + await tester.pumpWidget(Container()); + await tester.pumpAndSettle(); + expect(() => Zeta.of(tester.element(find.byType(Container))), throwsA(isA())); + }); + }); + + group('Zeta properties', () { + group('updates state', () { + late Zeta subject; + const Key subjectKey = Key('subject'); + + setUp(() { + subject = Zeta( + key: subjectKey, + themeMode: ThemeMode.light, + child: Container(), + ); + }); + + testWidgets('changing contrast updates state correctly', (WidgetTester tester) async { + await tester.pumpWidget(subject); + await tester.pumpAndSettle(); + + await tester.pumpWidget( + Zeta( + key: subjectKey, + themeMode: ThemeMode.light, + contrast: ZetaContrast.aaa, + child: Container(), + ), + ); + + await tester.pumpAndSettle(); + + final zeta = Zeta.of(tester.element(find.byType(Container))); + expect(zeta.contrast, ZetaContrast.aaa); + }); + + testWidgets('changing rounded updates state correctly', (WidgetTester tester) async { + await tester.pumpWidget(subject); + await tester.pumpAndSettle(); + + await tester.pumpWidget( + Zeta( + key: subjectKey, + themeMode: ThemeMode.light, + rounded: false, + child: Container(), + ), + ); + + await tester.pumpAndSettle(); + + final zeta = Zeta.of(tester.element(find.byType(Container))); + expect(zeta.rounded, false); + }); + + testWidgets('changing theme mode updates state correctly', (WidgetTester tester) async { + await tester.pumpWidget(subject); + await tester.pumpAndSettle(); + + await tester.pumpWidget( + Zeta( + key: subjectKey, + themeMode: ThemeMode.dark, + child: Container(), + ), + ); + + await tester.pumpAndSettle(); + + final zeta = Zeta.of(tester.element(find.byType(Container))); + expect(zeta.themeMode, ThemeMode.dark); + }); + + testWidgets('changing custom primitives updates state correctly', (WidgetTester tester) async { + await tester.pumpWidget(subject); + await tester.pumpAndSettle(); + + await tester.pumpWidget( + Zeta( + key: subjectKey, + themeMode: ThemeMode.light, + customPrimitives: const ZetaPrimitivesDark(), + child: Container(), + ), + ); + + await tester.pumpAndSettle(); + + final zeta = Zeta.of(tester.element(find.byType(Container))); + expect(zeta.primitives, const ZetaPrimitivesDark()); + }); + + testWidgets('changing custom semantics updates state correctly', (WidgetTester tester) async { + await tester.pumpWidget(subject); + await tester.pumpAndSettle(); + + final newSemantics = ZetaSemanticsAAA(primitives: const ZetaPrimitivesLight()); + + await tester.pumpWidget( + Zeta( + key: subjectKey, + themeMode: ThemeMode.light, + customSemantics: newSemantics, + child: Container(), + ), + ); + + await tester.pumpAndSettle(); + + final zeta = Zeta.of(tester.element(find.byType(Container))); + expect(zeta.semantics, newSemantics); + }); + + testWidgets('changing customThemeId updates state correctly', (WidgetTester tester) async { + await tester.pumpWidget(subject); + await tester.pumpAndSettle(); + + await tester.pumpWidget( + Zeta( + key: subjectKey, + themeMode: ThemeMode.light, + customThemeId: 'custom', + child: Container(), + ), + ); + + await tester.pumpAndSettle(); + + final zeta = Zeta.of(tester.element(find.byType(Container))); + expect(zeta.customThemeId, 'custom'); + }); + }); + + testWidgets('brightness getter works correctly', (WidgetTester tester) async { + const Key test1 = Key('1'); + const Key test2 = Key('2'); + await tester.pumpWidget( + Zeta( + themeMode: ThemeMode.light, + child: Container(key: test1), + ), + ); + + final zeta = Zeta.of(tester.element(find.byKey(test1))); + expect(zeta.brightness, Brightness.light); + + await tester.pumpWidget( + Zeta( + themeMode: ThemeMode.dark, + child: Container(key: test2), + ), + ); + + final zetaDark = Zeta.of(tester.element(find.byKey(test2))); + expect(zetaDark.brightness, Brightness.dark); + }); + + testWidgets('debugFillProperties works correctly', (WidgetTester tester) async { + final diagnostics = DiagnosticPropertiesBuilder(); + Zeta(child: Container()).debugFillProperties(diagnostics); + expect(diagnostics.finder('rounded'), 'true'); + expect(diagnostics.finder('colors'), const ZetaColorsAA(primitives: ZetaPrimitivesLight()).toString()); + expect(diagnostics.finder('brightness'), Brightness.light.name); + expect(diagnostics.finder('radius'), const ZetaRadiusAA(primitives: ZetaPrimitivesLight()).toString()); + expect(diagnostics.finder('spacing'), const ZetaSpacingAA(primitives: ZetaPrimitivesLight()).toString()); + expect(diagnostics.finder('primitives'), const ZetaPrimitivesLight().toString()); + expect(diagnostics.finder('semantics'), ZetaSemanticsAA(primitives: const ZetaPrimitivesLight()).toString()); + expect(diagnostics.finder('contrast'), ZetaContrast.aa.name); + expect(diagnostics.finder('themeMode'), ThemeMode.system.name); + }); + }); +} diff --git a/test/src/zeta_provider_test.dart b/test/src/zeta_provider_test.dart deleted file mode 100644 index ecf19b76..00000000 --- a/test/src/zeta_provider_test.dart +++ /dev/null @@ -1,429 +0,0 @@ -import 'package:flutter/foundation.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:mockito/annotations.dart'; -import 'package:mockito/mockito.dart'; -import 'package:zeta_flutter/zeta_flutter.dart'; - -import 'zeta_provider_test.mocks.dart'; - -@GenerateNiceMocks([ - MockSpec(), -]) -void main() { - final mockThemeService = MockZetaThemeService(); - final initialThemeData = ZetaThemeData(); - - group('ZetaProvider', () { - testWidgets('initializes with correct default values', (WidgetTester tester) async { - await tester.pumpWidget( - ZetaProvider( - builder: (context, themeData, themeMode) => Container(), - ), - ); - - final providerState = tester.state(find.byType(ZetaProvider)); - expect(providerState.widget.initialThemeMode, ThemeMode.system); - expect(providerState.widget.initialContrast, ZetaContrast.aa); - expect(providerState.widget.initialZetaThemeData, isNotNull); - }); - - testWidgets('initializes with provided values', (WidgetTester tester) async { - await tester.pumpWidget( - ZetaProvider( - builder: (context, themeData, themeMode) => Container(), - initialThemeMode: ThemeMode.light, - initialContrast: ZetaContrast.aaa, - initialThemeData: initialThemeData, - themeService: mockThemeService, - ), - ); - - final providerState = tester.state(find.byType(ZetaProvider)); - expect(providerState.widget.initialThemeMode, ThemeMode.light); - expect(providerState.widget.initialContrast, ZetaContrast.aaa); - expect(providerState.widget.initialZetaThemeData, initialThemeData); - expect(providerState.widget.themeService, mockThemeService); - }); - - testWidgets('updateThemeMode updates the state correctly', (WidgetTester tester) async { - await tester.pumpWidget( - ZetaProvider( - builder: (context, themeData, themeMode) => Container(), - initialThemeData: initialThemeData, - themeService: mockThemeService, - ), - ); - - tester.state(find.byType(ZetaProvider)).updateThemeMode(ThemeMode.dark); - await tester.pump(); - - // Verifying through the public interface of Zeta widget - final zeta = tester.widget(find.byType(Zeta)); - expect(zeta.themeMode, ThemeMode.dark); - verify( - mockThemeService.saveTheme( - themeData: initialThemeData, - themeMode: ThemeMode.dark, - contrast: ZetaContrast.aa, - ), - ).called(1); - }); - - testWidgets('updateThemeData updates the state correctly', (WidgetTester tester) async { - final newThemeData = ZetaThemeData(); - - await tester.pumpWidget( - ZetaProvider( - builder: (context, themeData, themeMode) => Container(), - initialThemeData: initialThemeData, - themeService: mockThemeService, - ), - ); - - tester.state(find.byType(ZetaProvider)).updateThemeData(newThemeData); - await tester.pump(); - - // Verifying through the public interface of Zeta widget - final zeta = tester.widget(find.byType(Zeta)); - expect(zeta.themeData, newThemeData); - verify( - mockThemeService.saveTheme( - themeData: newThemeData, - themeMode: ThemeMode.system, - contrast: ZetaContrast.aa, - ), - ).called(1); - }); - - testWidgets('updateContrast updates the state correctly', (WidgetTester tester) async { - await tester.pumpWidget( - ZetaProvider( - builder: (context, themeData, themeMode) => Container(), - initialThemeData: initialThemeData, - themeService: mockThemeService, - ), - ); - - tester.state(find.byType(ZetaProvider)).updateContrast(ZetaContrast.aaa); - await tester.pump(); - - // Verifying through the public interface of Zeta widget - final zeta = tester.widget(find.byType(Zeta)); - expect(zeta.contrast, ZetaContrast.aaa); - verify( - mockThemeService.saveTheme( - themeData: initialThemeData.apply(contrast: ZetaContrast.aaa), - themeMode: ThemeMode.system, - contrast: ZetaContrast.aaa, - ), - ).called(1); - }); - - testWidgets('updateRounded updates the state correctly', (WidgetTester tester) async { - await tester.pumpWidget( - ZetaProvider( - builder: (context, themeData, themeMode) => Container(), - initialThemeData: initialThemeData, - themeService: mockThemeService, - ), - ); - - tester.state(find.byType(ZetaProvider)).updateRounded(false); - await tester.pump(); - - // Verifying through the public interface of Zeta widget - final zeta = tester.widget(find.byType(Zeta)); - expect(zeta.rounded, false); - }); - - testWidgets('didUpdateWidget in ZetaProviderState works correctly with change in ThemeMode', - (WidgetTester tester) async { - await tester.pumpWidget( - ZetaProvider( - initialThemeMode: ThemeMode.light, - builder: (context, themeData, themeMode) => Builder( - builder: (context) { - return Container(); - }, - ), - ), - ); - - await tester.pumpAndSettle(); - // Verifying through the public interface of Zeta widget - expect(tester.widget(find.byType(Zeta)).themeMode, ThemeMode.light); - - await tester.pumpWidget( - ZetaProvider( - initialThemeMode: ThemeMode.dark, - builder: (context, themeData, themeMode) => Builder( - builder: (context) { - return Container(); - }, - ), - ), - ); - - await tester.pumpAndSettle(const Duration(milliseconds: 250)); - - // Verifying through the public interface of Zeta widget - expect(tester.widget(find.byType(Zeta)).themeMode, ThemeMode.dark); - }); - - testWidgets('didUpdateWidget in ZetaProviderState works correctly with change in contrast', - (WidgetTester tester) async { - await tester.pumpWidget( - ZetaProvider( - builder: (context, themeData, themeMode) => Builder( - builder: (context) { - return Container(); - }, - ), - ), - ); - - await tester.pumpAndSettle(); - - // Verifying through the public interface of Zeta widget - expect(tester.widget(find.byType(Zeta)).contrast, ZetaContrast.aa); - - await tester.pumpWidget( - ZetaProvider( - initialContrast: ZetaContrast.aaa, - builder: (context, themeData, themeMode) => Builder( - builder: (context) { - return Container(); - }, - ), - ), - ); - - await tester.pumpAndSettle(const Duration(milliseconds: 250)); - - // Verifying through the public interface of Zeta widget - expect(tester.widget(find.byType(Zeta)).contrast, ZetaContrast.aaa); - }); - - testWidgets('didUpdateWidget in ZetaProviderState works correctly with change in theme data', - (WidgetTester tester) async { - await tester.pumpWidget( - ZetaProvider( - initialThemeData: initialThemeData, - builder: (context, themeData, themeMode) => Builder( - builder: (context) { - return Container(); - }, - ), - ), - ); - - await tester.pumpAndSettle(); - - // Verifying through the public interface of Zeta widget - expect(tester.widget(find.byType(Zeta)).themeData.identifier, 'default'); - - await tester.pumpWidget( - ZetaProvider( - initialThemeData: ZetaThemeData(identifier: 'different'), - builder: (context, themeData, themeMode) => Builder( - builder: (context) { - return Container(); - }, - ), - ), - ); - - await tester.pumpAndSettle(const Duration(milliseconds: 250)); - - // Verifying through the public interface of Zeta widget - expect(tester.widget(find.byType(Zeta)).themeData.identifier, 'different'); - }); - testWidgets('didUpdateWidget in ZetaProviderState works correctly with change rounded', - (WidgetTester tester) async { - await tester.pumpWidget( - ZetaProvider( - initialThemeData: initialThemeData, - builder: (context, themeData, themeMode) => Builder( - builder: (context) { - return Container(); - }, - ), - ), - ); - - await tester.pumpAndSettle(); - - // Verifying through the public interface of Zeta widget - expect(tester.widget(find.byType(Zeta)).rounded, true); - - await tester.pumpWidget( - ZetaProvider( - initialThemeData: initialThemeData, - initialRounded: false, - builder: (context, themeData, themeMode) => Builder( - builder: (context) { - return Container(); - }, - ), - ), - ); - - await tester.pumpAndSettle(const Duration(milliseconds: 250)); - - // Verifying through the public interface of Zeta widget - expect(tester.widget(find.byType(Zeta)).rounded, false); - }); - - testWidgets('retrieves ZetaProviderState from context', (WidgetTester tester) async { - await tester.pumpWidget( - ZetaProvider( - builder: (context, themeData, themeMode) => Builder( - builder: (context) { - final providerState = ZetaProvider.of(context); - expect(providerState, isNotNull); - return Container(); - }, - ), - ), - ); - }); - - testWidgets('throws error if ZetaProvider is not found in widget tree', (WidgetTester tester) async { - await tester.pumpWidget( - Builder( - builder: (context) { - expect(() => ZetaProvider.of(context), throwsA(isA())); - return Container(); - }, - ), - ); - }); - - testWidgets('handles platform brightness changes', (WidgetTester tester) async { - await tester.pumpWidget( - ZetaProvider( - builder: (context, themeData, themeMode) => Container(), - initialThemeData: initialThemeData, - ), - ); - - // Rebuild the widget tree - await tester.pumpAndSettle(); - - // Get test binding - final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized(); - - // Simulate platform brightness change to dark - binding.platformDispatcher.platformBrightnessTestValue = Brightness.dark; - - await tester.pumpAndSettle(const Duration(milliseconds: 550)); - - // Verifying through the public interface of Zeta widget - final zeta = tester.widget(find.byType(Zeta)); - expect(zeta.brightness, Brightness.dark); - }); - - testWidgets('generateZetaTheme applies zeta values to existing theme', (WidgetTester tester) async { - final ColorScheme colors = ColorScheme.fromSeed(seedColor: Colors.red); - - final theme = generateZetaTheme( - brightness: Brightness.light, - colorScheme: ZetaColors.light().toScheme(), - existingTheme: ThemeData( - fontFamily: 'Comic Sans', - primaryColor: Colors.red, - useMaterial3: false, - scaffoldBackgroundColor: Colors.blue, - colorScheme: colors, - ), - ); - expect(theme.useMaterial3, false); - expect(theme.brightness, Brightness.light); - expect(theme.primaryColor, Colors.red); - expect(theme.scaffoldBackgroundColor, Colors.blue); - - final theme2 = generateZetaTheme( - brightness: Brightness.light, - colorScheme: colors, - existingTheme: ThemeData( - fontFamily: 'Comic Sans', - primaryColor: Colors.red, - useMaterial3: false, - colorScheme: colors, - ), - ); - expect(theme2.useMaterial3, false); - expect(theme2.brightness, Brightness.light); - expect(theme2.primaryColor, Colors.red); - - expect(theme2.scaffoldBackgroundColor, ZetaColors.light().toScheme().surfaceTertiary); - }); - testWidgets('generateZetaTheme generates a new theme', (WidgetTester tester) async { - final theme = generateZetaTheme(brightness: Brightness.light, colorScheme: ZetaColors.light().toScheme()); - expect(theme.useMaterial3, true); - expect(theme.brightness, Brightness.light); - expect(theme.colorScheme, ZetaColors.light().toScheme()); - - final theme2 = generateZetaTheme( - brightness: Brightness.light, - colorScheme: ZetaColors.light().toScheme(), - zetaThemeData: initialThemeData, - ); - - expect(theme2.iconTheme.color, initialThemeData.colorsLight.iconDefault); - }); - - testWidgets('debugFillProperties works correctly', (WidgetTester tester) async { - final diagnostics = DiagnosticPropertiesBuilder(); - - ZetaProvider( - builder: (context, themeData, themeMode) => Container(), - initialThemeData: initialThemeData, - themeService: mockThemeService, - ).debugFillProperties(diagnostics); - - final description = - diagnostics.properties.where((p) => p.name == 'themeData').map((p) => p.toDescription()).first; - expect(description, contains('ZetaThemeData')); - - final themeMode = - diagnostics.properties.where((p) => p.name == 'initialThemeMode').map((p) => p.toDescription()).first; - expect(themeMode, 'system'); - - final contrast = - diagnostics.properties.where((p) => p.name == 'initialContrast').map((p) => p.toDescription()).first; - expect(contrast, 'aa'); - - final themeService = - diagnostics.properties.where((p) => p.name == 'themeService').map((p) => p.toDescription()).first; - expect(themeService, isNotNull); - }); - - testWidgets('debugFillProperties works correctly', (WidgetTester tester) async { - final diagnostics = DiagnosticPropertiesBuilder(); - - await tester.pumpWidget( - ZetaProvider( - builder: (context, themeData, themeMode) => Container(), - initialThemeData: initialThemeData, - ), - ); - - // Rebuild the widget tree - await tester.pumpAndSettle(); - - tester.state(find.byType(ZetaProvider)).debugFillProperties(diagnostics); - - final description = - diagnostics.properties.where((p) => p.name == 'themeData').map((p) => p.toDescription()).first; - expect(description, contains('ZetaThemeData')); - - final contrast = diagnostics.properties.where((p) => p.name == 'contrast').map((p) => p.toDescription()).first; - expect(contrast, 'aa'); - - final themeMode = diagnostics.properties.where((p) => p.name == 'themeMode').map((p) => p.toDescription()).first; - expect(themeMode, 'system'); - }); - }); -} diff --git a/test/src/zeta_test.dart b/test/src/zeta_test.dart deleted file mode 100644 index 98b95eb9..00000000 --- a/test/src/zeta_test.dart +++ /dev/null @@ -1,176 +0,0 @@ -import 'package:flutter/foundation.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:zeta_flutter/src/theme/contrast.dart'; -import 'package:zeta_flutter/src/theme/theme_data.dart'; -import 'package:zeta_flutter/src/utils/zeta.dart'; - -void main() { - group('Zeta InheritedWidget', () { - testWidgets('provides correct colors in light mode', (WidgetTester tester) async { - final themeData = ZetaThemeData(); - - await tester.pumpWidget( - Zeta( - mediaBrightness: Brightness.light, - contrast: ZetaContrast.aa, - themeMode: ThemeMode.light, - themeData: themeData, - child: Container(), - ), - ); - - await tester.pumpAndSettle(); - - final zeta = Zeta.of(tester.element(find.byType(Container))); - expect(zeta.colors, themeData.colorsLight); - }); - - testWidgets('provides correct colors in dark mode', (WidgetTester tester) async { - final themeData = ZetaThemeData(); - - await tester.pumpWidget( - Zeta( - mediaBrightness: Brightness.dark, - contrast: ZetaContrast.aa, - themeMode: ThemeMode.dark, - themeData: themeData, - child: Container(), - ), - ); - - await tester.pumpAndSettle(); - - final zeta = Zeta.of(tester.element(find.byType(Container))); - expect(zeta.colors, themeData.colorsDark); - }); - - testWidgets('provides correct colors in system mode with light media brightness', (WidgetTester tester) async { - final themeData = ZetaThemeData(); - - await tester.pumpWidget( - Zeta( - mediaBrightness: Brightness.light, - contrast: ZetaContrast.aa, - themeMode: ThemeMode.system, - themeData: themeData, - child: Container(), - ), - ); - - await tester.pumpAndSettle(); - - final zeta = Zeta.of(tester.element(find.byType(Container))); - expect(zeta.colors, themeData.colorsLight); - }); - - testWidgets('provides correct colors in system mode with dark media brightness', (WidgetTester tester) async { - final themeData = ZetaThemeData(); - - await tester.pumpWidget( - Zeta( - mediaBrightness: Brightness.dark, - contrast: ZetaContrast.aa, - themeMode: ThemeMode.system, - themeData: themeData, - child: Container(), - ), - ); - - await tester.pumpAndSettle(); - - final zeta = Zeta.of(tester.element(find.byType(Container))); - expect(zeta.colors, themeData.colorsDark); - }); - - testWidgets('throws FlutterError if Zeta is not found in widget tree', (WidgetTester tester) async { - await tester.pumpWidget(Container()); - await tester.pumpAndSettle(); - expect(() => Zeta.of(tester.element(find.byType(Container))), throwsA(isA())); - }); - }); - - group('Zeta properties', () { - testWidgets('brightness getter works correctly', (WidgetTester tester) async { - final themeData = ZetaThemeData(); - - await tester.pumpWidget( - Zeta( - mediaBrightness: Brightness.light, - contrast: ZetaContrast.aa, - themeMode: ThemeMode.system, - themeData: themeData, - child: Container(), - ), - ); - - final zeta = Zeta.of(tester.element(find.byType(Container))); - expect(zeta.brightness, Brightness.light); - - await tester.pumpWidget( - Zeta( - mediaBrightness: Brightness.dark, - contrast: ZetaContrast.aa, - themeMode: ThemeMode.dark, - themeData: themeData, - child: Builder( - builder: (context) { - return Container(); - }, - ), - ), - ); - - final zetaDark = Zeta.of(tester.element(find.byType(Container))); - expect(zetaDark.brightness, Brightness.dark); - - await tester.pumpWidget( - Zeta( - mediaBrightness: Brightness.light, - contrast: ZetaContrast.aa, - themeMode: ThemeMode.light, - themeData: themeData, - child: Container(), - ), - ); - - final zetaLight = Zeta.of(tester.element(find.byType(Container))); - expect(zetaLight.brightness, Brightness.light); - }); - - testWidgets('debugFillProperties works correctly', (WidgetTester tester) async { - final themeData = ZetaThemeData(); - - final diagnostics = DiagnosticPropertiesBuilder(); - Zeta( - mediaBrightness: Brightness.light, - contrast: ZetaContrast.aa, - themeMode: ThemeMode.system, - themeData: themeData, - child: Container(), - ).debugFillProperties(diagnostics); - - final description = diagnostics.properties.where((p) => p.name == 'contrast').map((p) => p.toDescription()).first; - expect(description, 'aa'); - - final themeMode = diagnostics.properties.where((p) => p.name == 'themeMode').map((p) => p.toDescription()).first; - expect(themeMode, 'system'); - - final thData = diagnostics.properties.where((p) => p.name == 'themeData').map((p) => p.toDescription()).first; - expect(thData, contains('ZetaThemeData')); - - final colors = diagnostics.properties.where((p) => p.name == 'colors').map((p) => p.toDescription()).first; - expect(colors, contains('ZetaColors')); - - final brightness = - diagnostics.properties.where((p) => p.name == 'brightness').map((p) => p.toDescription()).first; - expect(brightness, 'light'); - - final radius = diagnostics.properties.where((p) => p.name == 'radius').map((p) => p.toDescription()).first; - expect(radius, "Instance of 'ZetaRadiiAA'"); - - final spacing = diagnostics.properties.where((p) => p.name == 'spacing').map((p) => p.toDescription()).first; - expect(spacing, "Instance of 'ZetaSpacingAA'"); - }); - }); -} diff --git a/test/test_utils/test_app.dart b/test/test_utils/test_app.dart index 97272772..00526431 100644 --- a/test/test_utils/test_app.dart +++ b/test/test_utils/test_app.dart @@ -10,6 +10,7 @@ class TestApp extends StatelessWidget { this.themeMode, this.removeBody = true, this.rounded, + this.contrast, }); final Widget home; @@ -17,18 +18,22 @@ class TestApp extends StatelessWidget { final ThemeMode? themeMode; final bool removeBody; final bool? rounded; + final ZetaContrast? contrast; @override Widget build(BuildContext context) { - return ZetaProvider.base( + return ZetaProvider( initialThemeMode: themeMode ?? ThemeMode.system, initialRounded: rounded ?? true, + customLoadingWidget: const SizedBox(), + initialContrast: contrast ?? ZetaContrast.aa, builder: (context, lightTheme, darkTheme, themeMode) { return MaterialApp( theme: lightTheme, darkTheme: darkTheme, themeMode: themeMode, home: Scaffold( + backgroundColor: Zeta.of(context).colors.surfaceWarm, body: removeBody ? home : SizedBox( @@ -52,6 +57,7 @@ class TestApp extends StatelessWidget { ..add(DiagnosticsProperty('screenSize', screenSize)) ..add(EnumProperty('themeMode', themeMode)) ..add(DiagnosticsProperty('removeBody', removeBody)) - ..add(DiagnosticsProperty('rounded', rounded)); + ..add(DiagnosticsProperty('rounded', rounded)) + ..add(EnumProperty('contrast', contrast)); } }