From 62db22d152b7a4c8f7d0a6836fb18412cc988274 Mon Sep 17 00:00:00 2001 From: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com> Date: Thu, 7 Nov 2019 13:14:08 -0800 Subject: [PATCH] CupertinoDynamicColor improvements (#44317) --- .../cupertino/cupertino_refresh_demo.dart | 12 +- packages/flutter/lib/src/cupertino/app.dart | 2 +- .../lib/src/cupertino/bottom_tab_bar.dart | 5 +- .../flutter/lib/src/cupertino/colors.dart | 129 +++++++++++++++++- .../lib/src/cupertino/icon_theme_data.dart | 20 ++- .../lib/src/cupertino/interface_level.dart | 8 ++ .../flutter/lib/src/cupertino/text_field.dart | 2 +- .../flutter/lib/src/cupertino/text_theme.dart | 71 +++++----- packages/flutter/lib/src/cupertino/theme.dart | 24 ++-- .../flutter/lib/src/widgets/icon_theme.dart | 10 +- .../flutter/test/cupertino/colors_test.dart | 36 ++--- .../test/cupertino/date_picker_test.dart | 6 +- .../flutter/test/cupertino/dialog_test.dart | 4 +- .../flutter/test/cupertino/nav_bar_test.dart | 4 +- .../cupertino/segmented_control_test.dart | 12 +- .../test/cupertino/text_field_test.dart | 2 +- .../flutter/test/cupertino/theme_test.dart | 43 +++++- packages/flutter_test/lib/src/matchers.dart | 2 +- 18 files changed, 294 insertions(+), 98 deletions(-) diff --git a/examples/flutter_gallery/lib/demo/cupertino/cupertino_refresh_demo.dart b/examples/flutter_gallery/lib/demo/cupertino/cupertino_refresh_demo.dart index b05fbba077..fb77ccae8c 100644 --- a/examples/flutter_gallery/lib/demo/cupertino/cupertino_refresh_demo.dart +++ b/examples/flutter_gallery/lib/demo/cupertino/cupertino_refresh_demo.dart @@ -165,11 +165,11 @@ class _ListItem extends StatelessWidget { Container( width: 38.0, child: called - ? const Align( + ? Align( alignment: Alignment.topCenter, child: Icon( CupertinoIcons.phone_solid, - color: CupertinoColors.inactiveGray, + color: CupertinoColors.inactiveGray.resolveFrom(context), size: 18.0, ), ) @@ -203,10 +203,10 @@ class _ListItem extends StatelessWidget { place, maxLines: 1, overflow: TextOverflow.ellipsis, - style: const TextStyle( + style: TextStyle( fontSize: 15.0, letterSpacing: -0.24, - color: CupertinoColors.inactiveGray, + color: CupertinoColors.inactiveGray.resolveFrom(context), ), ), ], @@ -214,8 +214,8 @@ class _ListItem extends StatelessWidget { ), Text( date, - style: const TextStyle( - color: CupertinoColors.inactiveGray, + style: TextStyle( + color: CupertinoColors.inactiveGray.resolveFrom(context), fontSize: 15.0, letterSpacing: -0.41, ), diff --git a/packages/flutter/lib/src/cupertino/app.dart b/packages/flutter/lib/src/cupertino/app.dart index 57e7c63be2..288c1f1e7b 100644 --- a/packages/flutter/lib/src/cupertino/app.dart +++ b/packages/flutter/lib/src/cupertino/app.dart @@ -289,7 +289,7 @@ class _CupertinoAppState extends State { builder: widget.builder, title: widget.title, onGenerateTitle: widget.onGenerateTitle, - textStyle: effectiveThemeData.textTheme.textStyle, + textStyle: CupertinoTheme.of(context).textTheme.textStyle, color: CupertinoDynamicColor.resolve(widget.color ?? effectiveThemeData.primaryColor, context), locale: widget.locale, localizationsDelegates: _localizationsDelegates, diff --git a/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart b/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart index 338872d28c..1f966356c1 100644 --- a/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart +++ b/packages/flutter/lib/src/cupertino/bottom_tab_bar.dart @@ -16,10 +16,7 @@ const Color _kDefaultTabBarBorderColor = CupertinoDynamicColor.withBrightness( color: Color(0x4C000000), darkColor: Color(0x29000000), ); -const Color _kDefaultTabBarInactiveColor = CupertinoDynamicColor.withBrightness( - color: Color(0xFF999999), - darkColor: Color(0xFF757575), -); +const Color _kDefaultTabBarInactiveColor = CupertinoColors.inactiveGray; /// An iOS-styled bottom navigation tab bar. /// diff --git a/packages/flutter/lib/src/cupertino/colors.dart b/packages/flutter/lib/src/cupertino/colors.dart index e369610bcb..518b31a73c 100644 --- a/packages/flutter/lib/src/cupertino/colors.dart +++ b/packages/flutter/lib/src/cupertino/colors.dart @@ -79,7 +79,8 @@ class CupertinoColors { /// Not the same grey as disabled buttons etc. /// /// This is the disabled color in the iOS palette. - static const Color inactiveGray = CupertinoDynamicColor.withBrightness( + static const CupertinoDynamicColor inactiveGray = CupertinoDynamicColor.withBrightness( + debugLabel: 'inactiveGray', color: Color(0xFF999999), darkColor: Color(0xFF757575), ); @@ -100,6 +101,7 @@ class CupertinoColors { /// * [UIColor.systemBlue](https://developer.apple.com/documentation/uikit/uicolor/3173141-systemblue), /// the `UIKit` equivalent. static const CupertinoDynamicColor systemBlue = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemBlue', color: Color.fromARGB(255, 0, 122, 255), darkColor: Color.fromARGB(255, 10, 132, 255), highContrastColor: Color.fromARGB(255, 0, 64, 221), @@ -113,6 +115,7 @@ class CupertinoColors { /// * [UIColor.systemGreen](https://developer.apple.com/documentation/uikit/uicolor/3173144-systemgreen), /// the `UIKit` equivalent. static const CupertinoDynamicColor systemGreen = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemGreen', color: Color.fromARGB(255, 52, 199, 89), darkColor: Color.fromARGB(255, 48, 209, 88), highContrastColor: Color.fromARGB(255, 36, 138, 61), @@ -126,6 +129,7 @@ class CupertinoColors { /// * [UIColor.systemIndigo](https://developer.apple.com/documentation/uikit/uicolor/3173146-systemindigo), /// the `UIKit` equivalent. static const CupertinoDynamicColor systemIndigo = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemIndigo', color: Color.fromARGB(255, 88, 86, 214), darkColor: Color.fromARGB(255, 94, 92, 230), highContrastColor: Color.fromARGB(255, 54, 52, 163), @@ -139,6 +143,7 @@ class CupertinoColors { /// * [UIColor.systemOrange](https://developer.apple.com/documentation/uikit/uicolor/3173147-systemorange), /// the `UIKit` equivalent. static const CupertinoDynamicColor systemOrange = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemOrange', color: Color.fromARGB(255, 255, 149, 0), darkColor: Color.fromARGB(255, 255, 159, 10), highContrastColor: Color.fromARGB(255, 201, 52, 0), @@ -152,6 +157,7 @@ class CupertinoColors { /// * [UIColor.systemPink](https://developer.apple.com/documentation/uikit/uicolor/3173148-systempink), /// the `UIKit` equivalent. static const CupertinoDynamicColor systemPink = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemPink', color: Color.fromARGB(255, 255, 45, 85), darkColor: Color.fromARGB(255, 255, 55, 95), highContrastColor: Color.fromARGB(255, 211, 15, 69), @@ -165,6 +171,7 @@ class CupertinoColors { /// * [UIColor.systemPurple](https://developer.apple.com/documentation/uikit/uicolor/3173149-systempurple), /// the `UIKit` equivalent. static const CupertinoDynamicColor systemPurple = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemPurple', color: Color.fromARGB(255, 175, 82, 222), darkColor: Color.fromARGB(255, 191, 90, 242), highContrastColor: Color.fromARGB(255, 137, 68, 171), @@ -178,6 +185,7 @@ class CupertinoColors { /// * [UIColor.systemRed](https://developer.apple.com/documentation/uikit/uicolor/3173150-systemred), /// the `UIKit` equivalent. static const CupertinoDynamicColor systemRed = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemRed', color: Color.fromARGB(255, 255, 59, 48), darkColor: Color.fromARGB(255, 255, 69, 58), highContrastColor: Color.fromARGB(255, 215, 0, 21), @@ -191,6 +199,7 @@ class CupertinoColors { /// * [UIColor.systemTeal](https://developer.apple.com/documentation/uikit/uicolor/3173151-systemteal), /// the `UIKit` equivalent. static const CupertinoDynamicColor systemTeal = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemTeal', color: Color.fromARGB(255, 90, 200, 250), darkColor: Color.fromARGB(255, 100, 210, 255), highContrastColor: Color.fromARGB(255, 0, 113, 164), @@ -204,6 +213,7 @@ class CupertinoColors { /// * [UIColor.systemYellow](https://developer.apple.com/documentation/uikit/uicolor/3173152-systemyellow), /// the `UIKit` equivalent. static const CupertinoDynamicColor systemYellow = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemYellow', color: Color.fromARGB(255, 255, 204, 0), darkColor: Color.fromARGB(255, 255, 214, 10), highContrastColor: Color.fromARGB(255, 160, 90, 0), @@ -217,6 +227,7 @@ class CupertinoColors { /// * [UIColor.systemGray](https://developer.apple.com/documentation/uikit/uicolor/3173143-systemgray), /// the `UIKit` equivalent. static const CupertinoDynamicColor systemGrey = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemGrey', color: Color.fromARGB(255, 142, 142, 147), darkColor: Color.fromARGB(255, 142, 142, 147), highContrastColor: Color.fromARGB(255, 108, 108, 112), @@ -230,6 +241,7 @@ class CupertinoColors { /// * [UIColor.systemGray2](https://developer.apple.com/documentation/uikit/uicolor/3255071-systemgray2), /// the `UIKit` equivalent. static const CupertinoDynamicColor systemGrey2 = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemGrey2', color: Color.fromARGB(255, 174, 174, 178), darkColor: Color.fromARGB(255, 99, 99, 102), highContrastColor: Color.fromARGB(255, 142, 142, 147), @@ -243,6 +255,7 @@ class CupertinoColors { /// * [UIColor.systemGray3](https://developer.apple.com/documentation/uikit/uicolor/3255072-systemgray3), /// the `UIKit` equivalent. static const CupertinoDynamicColor systemGrey3 = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemGrey3', color: Color.fromARGB(255, 199, 199, 204), darkColor: Color.fromARGB(255, 72, 72, 74), highContrastColor: Color.fromARGB(255, 174, 174, 178), @@ -256,6 +269,7 @@ class CupertinoColors { /// * [UIColor.systemGray4](https://developer.apple.com/documentation/uikit/uicolor/3255073-systemgray4), /// the `UIKit` equivalent. static const CupertinoDynamicColor systemGrey4 = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemGrey4', color: Color.fromARGB(255, 209, 209, 214), darkColor: Color.fromARGB(255, 58, 58, 60), highContrastColor: Color.fromARGB(255, 188, 188, 192), @@ -269,6 +283,7 @@ class CupertinoColors { /// * [UIColor.systemGray5](https://developer.apple.com/documentation/uikit/uicolor/3255074-systemgray5), /// the `UIKit` equivalent. static const CupertinoDynamicColor systemGrey5 = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemGrey5', color: Color.fromARGB(255, 229, 229, 234), darkColor: Color.fromARGB(255, 44, 44, 46), highContrastColor: Color.fromARGB(255, 216, 216, 220), @@ -282,6 +297,7 @@ class CupertinoColors { /// * [UIColor.systemGray6](https://developer.apple.com/documentation/uikit/uicolor/3255075-systemgray6), /// the `UIKit` equivalent. static const CupertinoDynamicColor systemGrey6 = CupertinoDynamicColor.withBrightnessAndContrast( + debugLabel: 'systemGrey6', color: Color.fromARGB(255, 242, 242, 247), darkColor: Color.fromARGB(255, 28, 28, 30), highContrastColor: Color.fromARGB(255, 235, 235, 240), @@ -291,6 +307,7 @@ class CupertinoColors { /// The color for text labels containing primary content, equivalent to /// [UIColor.label](https://developer.apple.com/documentation/uikit/uicolor/3173131-label). static const CupertinoDynamicColor label = CupertinoDynamicColor( + debugLabel: 'label', color: Color.fromARGB(255, 0, 0, 0), darkColor: Color.fromARGB(255, 255, 255, 255), highContrastColor: Color.fromARGB(255, 0, 0, 0), @@ -304,6 +321,7 @@ class CupertinoColors { /// The color for text labels containing secondary content, equivalent to /// [UIColor.secondaryLabel](https://developer.apple.com/documentation/uikit/uicolor/3173136-secondarylabel). static const CupertinoDynamicColor secondaryLabel = CupertinoDynamicColor( + debugLabel: 'secondaryLabel', color: Color.fromARGB(153, 60, 60, 67), darkColor: Color.fromARGB(153, 235, 235, 245), highContrastColor: Color.fromARGB(173, 60, 60, 67), @@ -317,6 +335,7 @@ class CupertinoColors { /// The color for text labels containing tertiary content, equivalent to /// [UIColor.tertiaryLabel](https://developer.apple.com/documentation/uikit/uicolor/3173153-tertiarylabel). static const CupertinoDynamicColor tertiaryLabel = CupertinoDynamicColor( + debugLabel: 'tertiaryLabel', color: Color.fromARGB(76, 60, 60, 67), darkColor: Color.fromARGB(76, 235, 235, 245), highContrastColor: Color.fromARGB(96, 60, 60, 67), @@ -330,6 +349,7 @@ class CupertinoColors { /// The color for text labels containing quaternary content, equivalent to /// [UIColor.quaternaryLabel](https://developer.apple.com/documentation/uikit/uicolor/3173135-quaternarylabel). static const CupertinoDynamicColor quaternaryLabel = CupertinoDynamicColor( + debugLabel: 'quaternaryLabel', color: Color.fromARGB(45, 60, 60, 67), darkColor: Color.fromARGB(40, 235, 235, 245), highContrastColor: Color.fromARGB(66, 60, 60, 67), @@ -343,6 +363,7 @@ class CupertinoColors { /// An overlay fill color for thin and small shapes, equivalent to /// [UIColor.systemFill](https://developer.apple.com/documentation/uikit/uicolor/3255070-systemfill). static const CupertinoDynamicColor systemFill = CupertinoDynamicColor( + debugLabel: 'systemFill', color: Color.fromARGB(51, 120, 120, 128), darkColor: Color.fromARGB(91, 120, 120, 128), highContrastColor: Color.fromARGB(71, 120, 120, 128), @@ -356,6 +377,7 @@ class CupertinoColors { /// An overlay fill color for medium-size shapes, equivalent to /// [UIColor.secondarySystemFill](https://developer.apple.com/documentation/uikit/uicolor/3255069-secondarysystemfill). static const CupertinoDynamicColor secondarySystemFill = CupertinoDynamicColor( + debugLabel: 'secondarySystemFill', color: Color.fromARGB(40, 120, 120, 128), darkColor: Color.fromARGB(81, 120, 120, 128), highContrastColor: Color.fromARGB(61, 120, 120, 128), @@ -369,6 +391,7 @@ class CupertinoColors { /// An overlay fill color for large shapes, equivalent to /// [UIColor.tertiarySystemFill](https://developer.apple.com/documentation/uikit/uicolor/3255076-tertiarysystemfill). static const CupertinoDynamicColor tertiarySystemFill = CupertinoDynamicColor( + debugLabel: 'tertiarySystemFill', color: Color.fromARGB(30, 118, 118, 128), darkColor: Color.fromARGB(61, 118, 118, 128), highContrastColor: Color.fromARGB(51, 118, 118, 128), @@ -382,6 +405,7 @@ class CupertinoColors { /// An overlay fill color for large areas containing complex content, equivalent /// to [UIColor.quaternarySystemFill](https://developer.apple.com/documentation/uikit/uicolor/3255068-quaternarysystemfill). static const CupertinoDynamicColor quaternarySystemFill = CupertinoDynamicColor( + debugLabel: 'quaternarySystemFill', color: Color.fromARGB(20, 116, 116, 128), darkColor: Color.fromARGB(45, 118, 118, 128), highContrastColor: Color.fromARGB(40, 116, 116, 128), @@ -395,6 +419,7 @@ class CupertinoColors { /// The color for placeholder text in controls or text views, equivalent to /// [UIColor.placeholderText](https://developer.apple.com/documentation/uikit/uicolor/3173134-placeholdertext). static const CupertinoDynamicColor placeholderText = CupertinoDynamicColor( + debugLabel: 'placeholderText', color: Color.fromARGB(76, 60, 60, 67), darkColor: Color.fromARGB(76, 235, 235, 245), highContrastColor: Color.fromARGB(96, 60, 60, 67), @@ -410,6 +435,7 @@ class CupertinoColors { /// /// Typically used for designs that have a white primary background in a light environment. static const CupertinoDynamicColor systemBackground = CupertinoDynamicColor( + debugLabel: 'systemBackground', color: Color.fromARGB(255, 255, 255, 255), darkColor: Color.fromARGB(255, 0, 0, 0), highContrastColor: Color.fromARGB(255, 255, 255, 255), @@ -425,6 +451,7 @@ class CupertinoColors { /// /// Typically used for designs that have a white primary background in a light environment. static const CupertinoDynamicColor secondarySystemBackground = CupertinoDynamicColor( + debugLabel: 'secondarySystemBackground', color: Color.fromARGB(255, 242, 242, 247), darkColor: Color.fromARGB(255, 28, 28, 30), highContrastColor: Color.fromARGB(255, 235, 235, 240), @@ -440,6 +467,7 @@ class CupertinoColors { /// /// Typically used for designs that have a white primary background in a light environment. static const CupertinoDynamicColor tertiarySystemBackground = CupertinoDynamicColor( + debugLabel: 'tertiarySystemBackground', color: Color.fromARGB(255, 255, 255, 255), darkColor: Color.fromARGB(255, 44, 44, 46), highContrastColor: Color.fromARGB(255, 255, 255, 255), @@ -455,6 +483,7 @@ class CupertinoColors { /// /// Typically used for grouped content, including table views and platter-based designs. static const CupertinoDynamicColor systemGroupedBackground = CupertinoDynamicColor( + debugLabel: 'systemGroupedBackground', color: Color.fromARGB(255, 242, 242, 247), darkColor: Color.fromARGB(255, 0, 0, 0), highContrastColor: Color.fromARGB(255, 235, 235, 240), @@ -470,6 +499,7 @@ class CupertinoColors { /// /// Typically used for grouped content, including table views and platter-based designs. static const CupertinoDynamicColor secondarySystemGroupedBackground = CupertinoDynamicColor( + debugLabel: 'secondarySystemGroupedBackground', color: Color.fromARGB(255, 255, 255, 255), darkColor: Color.fromARGB(255, 28, 28, 30), highContrastColor: Color.fromARGB(255, 255, 255, 255), @@ -485,6 +515,7 @@ class CupertinoColors { /// /// Typically used for grouped content, including table views and platter-based designs. static const CupertinoDynamicColor tertiarySystemGroupedBackground = CupertinoDynamicColor( + debugLabel: 'tertiarySystemGroupedBackground', color: Color.fromARGB(255, 242, 242, 247), darkColor: Color.fromARGB(255, 44, 44, 46), highContrastColor: Color.fromARGB(255, 235, 235, 240), @@ -498,6 +529,7 @@ class CupertinoColors { /// The color for thin borders or divider lines that allows some underlying content to be visible, /// equivalent to [UIColor.separator](https://developer.apple.com/documentation/uikit/uicolor/3173139-separator). static const CupertinoDynamicColor separator = CupertinoDynamicColor( + debugLabel: 'separator', color: Color.fromARGB(73, 60, 60, 67), darkColor: Color.fromARGB(153, 84, 84, 88), highContrastColor: Color.fromARGB(94, 60, 60, 67), @@ -511,6 +543,7 @@ class CupertinoColors { /// The color for borders or divider lines that hide any underlying content, /// equivalent to [UIColor.opaqueSeparator](https://developer.apple.com/documentation/uikit/uicolor/3173133-opaqueseparator). static const CupertinoDynamicColor opaqueSeparator = CupertinoDynamicColor( + debugLabel: 'opaqueSeparator', color: Color.fromARGB(255, 198, 198, 200), darkColor: Color.fromARGB(255, 56, 56, 58), highContrastColor: Color.fromARGB(255, 198, 198, 200), @@ -524,6 +557,7 @@ class CupertinoColors { /// The color for links, equivalent to /// [UIColor.link](https://developer.apple.com/documentation/uikit/uicolor/3173132-link). static const CupertinoDynamicColor link = CupertinoDynamicColor( + debugLabel: 'link', color: Color.fromARGB(255, 0, 122, 255), darkColor: Color.fromARGB(255, 9, 132, 255), highContrastColor: Color.fromARGB(255, 0, 122, 255), @@ -547,7 +581,7 @@ class CupertinoColors { /// Sometimes manually resolving a [CupertinoDynamicColor] is not necessary, because /// the Cupertino Library provides built-in support for it. /// -/// ### Using a [CupertinoDynamicColor] in a Cupertino widget +/// ### Using [CupertinoDynamicColor] in a Cupertino widget /// /// When a Cupertino widget is provided with a [CupertinoDynamicColor], either /// directly in its constructor, or from an [InheritedWidget] it depends on (for example, @@ -638,12 +672,13 @@ class CupertinoColors { /// * [CupertinoTheme.of], a static method that retrieves the ambient [CupertinoThemeData], /// and then resolves [CupertinoDynamicColor]s used in the retrieved data. @immutable -class CupertinoDynamicColor extends Color { +class CupertinoDynamicColor extends Color with DiagnosticableMixin implements Diagnosticable { /// Creates an adaptive [Color] that changes its effective color based on the /// [BuildContext] given. The default effective color is [color]. /// /// All the colors must not be null. const CupertinoDynamicColor({ + String debugLabel, @required Color color, @required Color darkColor, @required Color highContrastColor, @@ -662,6 +697,8 @@ class CupertinoDynamicColor extends Color { darkElevatedColor, highContrastElevatedColor, darkHighContrastElevatedColor, + null, + debugLabel, ); /// Creates an adaptive [Color] that changes its effective color based on the @@ -671,11 +708,13 @@ class CupertinoDynamicColor extends Color { /// /// All the colors must not be null. const CupertinoDynamicColor.withBrightnessAndContrast({ + String debugLabel, @required Color color, @required Color darkColor, @required Color highContrastColor, @required Color darkHighContrastColor, }) : this( + debugLabel: debugLabel, color: color, darkColor: darkColor, highContrastColor: highContrastColor, @@ -692,9 +731,11 @@ class CupertinoDynamicColor extends Color { /// /// All the colors must not be null. const CupertinoDynamicColor.withBrightness({ + String debugLabel, @required Color color, @required Color darkColor, }) : this( + debugLabel: debugLabel, color: color, darkColor: darkColor, highContrastColor: color, @@ -715,6 +756,8 @@ class CupertinoDynamicColor extends Color { this.darkElevatedColor, this.highContrastElevatedColor, this.darkHighContrastElevatedColor, + this._debugResolveContext, + this._debugLabel, ) : assert(color != null), assert(darkColor != null), assert(highContrastColor != null), @@ -729,11 +772,19 @@ class CupertinoDynamicColor extends Color { // The field `value` is overriden in the class implementation. super(0); + /// The current effective color. + /// + /// Must not be null. Defaults to [color] if this [CupertinoDynamicColor] has + /// never been resolved. final Color _effectiveColor; @override int get value => _effectiveColor.value; + final String _debugLabel; + + final Element _debugResolveContext; + /// The color to use when the [BuildContext] implies a combination of light mode, /// normal contrast, and base interface elevation. /// @@ -925,7 +976,11 @@ class CupertinoDynamicColor extends Color { } } - assert(resolved != null); + Element _debugContext; + assert(() { + _debugContext = context; + return true; + }()); return CupertinoDynamicColor._( resolved, color, @@ -936,6 +991,8 @@ class CupertinoDynamicColor extends Color { darkElevatedColor, highContrastElevatedColor, darkHighContrastElevatedColor, + _debugContext, + _debugLabel, ); } @@ -972,9 +1029,9 @@ class CupertinoDynamicColor extends Color { } @override - String toString() { + String toString({ DiagnosticLevel minLevel = DiagnosticLevel.debug }) { String toString(String name, Color color) { - final String marker = color.value == value ? '*' : ''; + final String marker = color == _effectiveColor ? '*' : ''; return '$marker$name = $color$marker'; } @@ -988,6 +1045,64 @@ class CupertinoDynamicColor extends Color { if (_isPlatformBrightnessDependent && _isHighContrastDependent && _isInterfaceElevationDependent) toString('darkHighContrastElevatedColor', darkHighContrastElevatedColor), ]; - return '$runtimeType(${xs.join(', ')})'; + return '${_debugLabel ?? runtimeType.toString()}(${xs.join(', ')}, resolved by: ${_debugResolveContext?.widget ?? "UNRESOLVED"})'; + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + if (_debugLabel != null) + properties.add(MessageProperty('debugLabel', _debugLabel)); + properties.add(createCupertinoColorProperty('color', color)); + if (_isPlatformBrightnessDependent) + properties.add(createCupertinoColorProperty('darkColor', darkColor)); + if (_isHighContrastDependent) + properties.add(createCupertinoColorProperty('highContrastColor', highContrastColor)); + if (_isPlatformBrightnessDependent && _isHighContrastDependent) + properties.add(createCupertinoColorProperty('darkHighContrastColor', darkHighContrastColor)); + if (_isInterfaceElevationDependent) + properties.add(createCupertinoColorProperty('elevatedColor', elevatedColor)); + if (_isPlatformBrightnessDependent && _isInterfaceElevationDependent) + properties.add(createCupertinoColorProperty('darkElevatedColor', darkElevatedColor)); + if (_isHighContrastDependent && _isInterfaceElevationDependent) + properties.add(createCupertinoColorProperty('highContrastElevatedColor', highContrastElevatedColor)); + if (_isPlatformBrightnessDependent && _isHighContrastDependent && _isInterfaceElevationDependent) + properties.add(createCupertinoColorProperty('darkHighContrastElevatedColor', darkHighContrastElevatedColor)); + + if (_debugResolveContext != null) + properties.add(DiagnosticsProperty('last resolved', _debugResolveContext)); + } +} + +/// Creates a diagnostics property for [CupertinoDynamicColor]. +/// +/// The [showName], [style], and [level] arguments must not be null. +DiagnosticsProperty createCupertinoColorProperty( + String name, + Color value, { + bool showName = true, + Object defaultValue = kNoDefaultValue, + DiagnosticsTreeStyle style = DiagnosticsTreeStyle.shallow, + DiagnosticLevel level = DiagnosticLevel.info, +}) { + if (value is CupertinoDynamicColor) { + return DiagnosticsProperty( + name, + value, + description: value._debugLabel, + showName: showName, + defaultValue: defaultValue, + style: style, + level: level, + ); + } else { + return ColorProperty( + name, + value, + showName: showName, + defaultValue: defaultValue, + style: style, + level: level, + ); } } diff --git a/packages/flutter/lib/src/cupertino/icon_theme_data.dart b/packages/flutter/lib/src/cupertino/icon_theme_data.dart index 4e437b4b5f..e80f93e90c 100644 --- a/packages/flutter/lib/src/cupertino/icon_theme_data.dart +++ b/packages/flutter/lib/src/cupertino/icon_theme_data.dart @@ -2,12 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; import 'colors.dart'; /// An [IconThemeData] subclass that automatically resolves its [color] when retrieved /// using [IconTheme.of]. -class CupertinoIconThemeData extends IconThemeData { +class CupertinoIconThemeData extends IconThemeData with DiagnosticableMixin { /// Creates a [CupertinoIconThemeData]. /// /// The opacity applies to both explicit and default icon colors. The value @@ -24,4 +25,21 @@ class CupertinoIconThemeData extends IconThemeData { final Color resolvedColor = CupertinoDynamicColor.resolve(color, context); return resolvedColor == color ? this : copyWith(color: resolvedColor); } + + /// Creates a copy of this icon theme but with the given fields replaced with + /// the new values. + @override + CupertinoIconThemeData copyWith({ Color color, double opacity, double size }) { + return CupertinoIconThemeData( + color: color ?? this.color, + opacity: opacity ?? this.opacity, + size: size ?? this.size, + ); + } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(createCupertinoColorProperty('color', color, defaultValue: null)); + } } diff --git a/packages/flutter/lib/src/cupertino/interface_level.dart b/packages/flutter/lib/src/cupertino/interface_level.dart index 74ca5e5270..685f35f7a3 100644 --- a/packages/flutter/lib/src/cupertino/interface_level.dart +++ b/packages/flutter/lib/src/cupertino/interface_level.dart @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:flutter/foundation.dart'; + import '../widgets/framework.dart'; /// Indicates the visual level for a piece of content. Equivalent to `UIUserInterfaceLevel` @@ -73,4 +75,10 @@ class CupertinoUserInterfaceLevel extends InheritedWidget { ' $context' ); } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + properties.add(EnumProperty('user interface level', _data)); + } } diff --git a/packages/flutter/lib/src/cupertino/text_field.dart b/packages/flutter/lib/src/cupertino/text_field.dart index ee52e87953..e35b95ddf2 100644 --- a/packages/flutter/lib/src/cupertino/text_field.dart +++ b/packages/flutter/lib/src/cupertino/text_field.dart @@ -573,7 +573,7 @@ class CupertinoTextField extends StatefulWidget { properties.add(DiagnosticsProperty('expands', expands, defaultValue: false)); properties.add(IntProperty('maxLength', maxLength, defaultValue: null)); properties.add(FlagProperty('maxLengthEnforced', value: maxLengthEnforced, ifTrue: 'max length enforced')); - properties.add(ColorProperty('cursorColor', cursorColor, defaultValue: null)); + properties.add(createCupertinoColorProperty('cursorColor', cursorColor, defaultValue: null)); properties.add(FlagProperty('selectionEnabled', value: selectionEnabled, defaultValue: true, ifFalse: 'selection disabled')); properties.add(DiagnosticsProperty('scrollController', scrollController, defaultValue: null)); properties.add(DiagnosticsProperty('scrollPhysics', scrollPhysics, defaultValue: null)); diff --git a/packages/flutter/lib/src/cupertino/text_theme.dart b/packages/flutter/lib/src/cupertino/text_theme.dart index ca47790bb3..5f8f4a7f43 100644 --- a/packages/flutter/lib/src/cupertino/text_theme.dart +++ b/packages/flutter/lib/src/cupertino/text_theme.dart @@ -8,9 +8,9 @@ import 'package:flutter/widgets.dart'; import 'colors.dart'; -// Please update _DefaultCupertinoTextThemeData and _DefaultCupertinoTextThemeData -// accordingly after changing the default color here, as their implementation -// depends on the default value of the color field. +// Please update _TextThemeDefaultsBuilder accordingly after changing the default +// color here, as their implementation depends on the default value of the color +// field. // // Values derived from https://developer.apple.com/design/resources/. const TextStyle _kDefaultTextStyle = TextStyle( @@ -22,9 +22,9 @@ const TextStyle _kDefaultTextStyle = TextStyle( decoration: TextDecoration.none, ); -// Please update _DefaultCupertinoTextThemeData and _DefaultCupertinoTextThemeData -// accordingly after changing the default color here, as their implementation -// depends on the default value of the color field. +// Please update _TextThemeDefaultsBuilder accordingly after changing the default +// color here, as their implementation depends on the default value of the color +// field. // // Values derived from https://developer.apple.com/design/resources/. const TextStyle _kDefaultActionTextStyle = TextStyle( @@ -36,9 +36,9 @@ const TextStyle _kDefaultActionTextStyle = TextStyle( decoration: TextDecoration.none, ); -// Please update _DefaultCupertinoTextThemeData and _DefaultCupertinoTextThemeData -// accordingly after changing the default color here, as their implementation -// depends on the default value of the color field. +// Please update _TextThemeDefaultsBuilder accordingly after changing the default +// color here, as their implementation depends on the default value of the color +// field. // // Values derived from https://developer.apple.com/design/resources/. const TextStyle _kDefaultTabLabelTextStyle = TextStyle( @@ -49,9 +49,6 @@ const TextStyle _kDefaultTabLabelTextStyle = TextStyle( color: CupertinoColors.inactiveGray, ); -// Please update _DefaultCupertinoTextThemeData and _DefaultCupertinoTextThemeData -// accordingly after changing the default color here, as their implementation -// depends on the default value of the color field. const TextStyle _kDefaultMiddleTitleTextStyle = TextStyle( inherit: false, fontFamily: '.SF Pro Text', @@ -61,9 +58,6 @@ const TextStyle _kDefaultMiddleTitleTextStyle = TextStyle( color: CupertinoColors.label, ); -// Please update _DefaultCupertinoTextThemeData and _DefaultCupertinoTextThemeData -// accordingly after changing the default color here, as their implementation -// depends on the default value of the color field. const TextStyle _kDefaultLargeTitleTextStyle = TextStyle( inherit: false, fontFamily: '.SF Pro Display', @@ -73,9 +67,9 @@ const TextStyle _kDefaultLargeTitleTextStyle = TextStyle( color: CupertinoColors.label, ); -// Please update _DefaultCupertinoTextThemeData and _DefaultCupertinoTextThemeData -// accordingly after changing the default color here, as their implementation -// depends on the default value of the color field. +// Please update _TextThemeDefaultsBuilder accordingly after changing the default +// color here, as their implementation depends on the default value of the color +// field. // // Inspected on iOS 13 simulator with "Debug View Hierarchy". // Value extracted from off-center labels. Centered labels have a font size of 25pt. @@ -88,9 +82,9 @@ const TextStyle _kDefaultPickerTextStyle = TextStyle( color: CupertinoColors.label, ); -// Please update _DefaultCupertinoTextThemeData and _DefaultCupertinoTextThemeData -// accordingly after changing the default color here, as their implementation -// depends on the default value of the color field. +// Please update _TextThemeDefaultsBuilder accordingly after changing the default +// color here, as their implementation depends on the default value of the color +// field. // // Inspected on iOS 13 simulator with "Debug View Hierarchy". // Value extracted from off-center labels. Centered labels have a font size of 25pt. @@ -135,7 +129,7 @@ class CupertinoTextThemeData extends Diagnosticable { TextStyle pickerTextStyle, TextStyle dateTimePickerTextStyle, }) : this._raw( - const _DefaultCupertinoTextThemeData(), + const _TextThemeDefaultsBuilder(CupertinoColors.label, CupertinoColors.inactiveGray), primaryColor, textStyle, actionTextStyle, @@ -160,7 +154,7 @@ class CupertinoTextThemeData extends Diagnosticable { this._dateTimePickerTextStyle, ) : assert((_navActionTextStyle != null && _actionTextStyle != null) || _primaryColor != null); - final _DefaultCupertinoTextThemeData _defaults; + final _TextThemeDefaultsBuilder _defaults; final Color _primaryColor; final TextStyle _textStyle; @@ -248,15 +242,30 @@ class CupertinoTextThemeData extends Diagnosticable { dateTimePickerTextStyle ?? _dateTimePickerTextStyle, ); } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + const CupertinoTextThemeData defaultData = CupertinoTextThemeData(); + properties.add(DiagnosticsProperty('textStyle', textStyle, defaultValue: defaultData.textStyle)); + properties.add(DiagnosticsProperty('actionTextStyle', actionTextStyle, defaultValue: defaultData.actionTextStyle)); + properties.add(DiagnosticsProperty('tabLabelTextStyle', tabLabelTextStyle, defaultValue: defaultData.tabLabelTextStyle)); + properties.add(DiagnosticsProperty('navTitleTextStyle', navTitleTextStyle, defaultValue: defaultData.navTitleTextStyle)); + properties.add(DiagnosticsProperty('navLargeTitleTextStyle', navLargeTitleTextStyle, defaultValue: defaultData.navLargeTitleTextStyle)); + properties.add(DiagnosticsProperty('navActionTextStyle', navActionTextStyle, defaultValue: defaultData.navActionTextStyle)); + properties.add(DiagnosticsProperty('pickerTextStyle', pickerTextStyle, defaultValue: defaultData.pickerTextStyle)); + properties.add(DiagnosticsProperty('dateTimePickerTextStyle', dateTimePickerTextStyle, defaultValue: defaultData.dateTimePickerTextStyle)); + } } + @immutable -class _DefaultCupertinoTextThemeData extends Diagnosticable { - const _DefaultCupertinoTextThemeData({ - this.labelColor = CupertinoColors.label, - this.inactiveGrayColor = CupertinoColors.inactiveGray, - }) : assert(labelColor != null), - assert(inactiveGrayColor != null); +class _TextThemeDefaultsBuilder { + const _TextThemeDefaultsBuilder( + this.labelColor, + this.inactiveGrayColor, + ) : assert(labelColor != null), + assert(inactiveGrayColor != null); final Color labelColor; final Color inactiveGrayColor; @@ -277,11 +286,11 @@ class _DefaultCupertinoTextThemeData extends Diagnosticable { TextStyle actionTextStyle({ Color primaryColor }) => _kDefaultActionTextStyle.copyWith(color: primaryColor); TextStyle navActionTextStyle({ Color primaryColor }) => actionTextStyle(primaryColor: primaryColor); - _DefaultCupertinoTextThemeData resolveFrom(BuildContext context, bool nullOk) { + _TextThemeDefaultsBuilder resolveFrom(BuildContext context, bool nullOk) { final Color resolvedLabelColor = CupertinoDynamicColor.resolve(labelColor, context, nullOk: nullOk); final Color resolvedInactiveGray = CupertinoDynamicColor.resolve(inactiveGrayColor, context, nullOk: nullOk); return resolvedLabelColor == labelColor && resolvedInactiveGray == CupertinoColors.inactiveGray ? this - : _DefaultCupertinoTextThemeData(labelColor: resolvedLabelColor, inactiveGrayColor: resolvedInactiveGray); + : _TextThemeDefaultsBuilder(resolvedLabelColor, resolvedInactiveGray); } } diff --git a/packages/flutter/lib/src/cupertino/theme.dart b/packages/flutter/lib/src/cupertino/theme.dart index b6f9442ca1..5d95cf0848 100644 --- a/packages/flutter/lib/src/cupertino/theme.dart +++ b/packages/flutter/lib/src/cupertino/theme.dart @@ -99,6 +99,12 @@ class CupertinoTheme extends StatelessWidget { ), ); } + + @override + void debugFillProperties(DiagnosticPropertiesBuilder properties) { + super.debugFillProperties(properties); + data.debugFillProperties(properties); + } } class _InheritedCupertinoTheme extends InheritedWidget { @@ -284,10 +290,10 @@ class CupertinoThemeData extends Diagnosticable { _brightness, convertColor(_primaryColor), convertColor(_primaryContrastingColor), - textTheme?.resolveFrom(context, nullOk: nullOk), + _textTheme?.resolveFrom(context, nullOk: nullOk), convertColor(_barBackgroundColor), convertColor(_scaffoldBackgroundColor), - _defaults.resolveFrom(context, nullOk: nullOk), + _defaults.resolveFrom(context, _textTheme == null, nullOk: nullOk), ); } @@ -322,11 +328,11 @@ class CupertinoThemeData extends Diagnosticable { super.debugFillProperties(properties); const CupertinoThemeData defaultData = CupertinoThemeData(); properties.add(EnumProperty('brightness', brightness, defaultValue: defaultData.brightness)); - properties.add(ColorProperty('primaryColor', primaryColor, defaultValue: defaultData.primaryColor)); - properties.add(ColorProperty('primaryContrastingColor', primaryContrastingColor, defaultValue: defaultData.primaryContrastingColor)); - properties.add(DiagnosticsProperty('textTheme', textTheme, defaultValue: defaultData.textTheme)); - properties.add(ColorProperty('barBackgroundColor', barBackgroundColor, defaultValue: defaultData.barBackgroundColor)); - properties.add(ColorProperty('scaffoldBackgroundColor', scaffoldBackgroundColor, defaultValue: defaultData.scaffoldBackgroundColor)); + properties.add(createCupertinoColorProperty('primaryColor', primaryColor, defaultValue: defaultData.primaryColor)); + properties.add(createCupertinoColorProperty('primaryContrastingColor', primaryContrastingColor, defaultValue: defaultData.primaryContrastingColor)); + properties.add(createCupertinoColorProperty('barBackgroundColor', barBackgroundColor, defaultValue: defaultData.barBackgroundColor)); + properties.add(createCupertinoColorProperty('scaffoldBackgroundColor', scaffoldBackgroundColor, defaultValue: defaultData.scaffoldBackgroundColor)); + textTheme.debugFillProperties(properties); } } @@ -413,7 +419,7 @@ class _CupertinoThemeDefaults { final Color scaffoldBackgroundColor; final _CupertinoTextThemeDefaults textThemeDefaults; - _CupertinoThemeDefaults resolveFrom(BuildContext context, { @required bool nullOk }) { + _CupertinoThemeDefaults resolveFrom(BuildContext context, bool resolveTextTheme, { @required bool nullOk }) { assert(nullOk != null); Color convertColor(Color color) => CupertinoDynamicColor.resolve(color, context, nullOk: nullOk); @@ -423,7 +429,7 @@ class _CupertinoThemeDefaults { convertColor(primaryContrastingColor), convertColor(barBackgroundColor), convertColor(scaffoldBackgroundColor), - textThemeDefaults?.resolveFrom(context, nullOk: nullOk), + resolveTextTheme ? textThemeDefaults?.resolveFrom(context, nullOk: nullOk) : textThemeDefaults, ); } } diff --git a/packages/flutter/lib/src/widgets/icon_theme.dart b/packages/flutter/lib/src/widgets/icon_theme.dart index 67201e9f03..f74300fb08 100644 --- a/packages/flutter/lib/src/widgets/icon_theme.dart +++ b/packages/flutter/lib/src/widgets/icon_theme.dart @@ -60,7 +60,13 @@ class IconTheme extends InheritedTheme { /// ``` static IconThemeData of(BuildContext context) { final IconThemeData iconThemeData = _getInheritedIconThemeData(context).resolve(context); - return iconThemeData.isConcrete ? iconThemeData : const IconThemeData.fallback().merge(iconThemeData); + return iconThemeData.isConcrete + ? iconThemeData + : iconThemeData.copyWith( + size: iconThemeData.size ?? const IconThemeData.fallback().size, + color: iconThemeData.color ?? const IconThemeData.fallback().color, + opacity: iconThemeData.opacity ?? const IconThemeData.fallback().opacity, + ); } static IconThemeData _getInheritedIconThemeData(BuildContext context) { @@ -80,6 +86,6 @@ class IconTheme extends InheritedTheme { @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); - properties.add(DiagnosticsProperty('data', data, showName: false)); + data.debugFillProperties(properties); } } diff --git a/packages/flutter/test/cupertino/colors_test.dart b/packages/flutter/test/cupertino/colors_test.dart index f16842f4c6..ab53e144aa 100644 --- a/packages/flutter/test/cupertino/colors_test.dart +++ b/packages/flutter/test/cupertino/colors_test.dart @@ -132,19 +132,21 @@ void main() { test('CupertinoDynamicColor.toString() works', () { expect( dynamicColor.toString(), - 'CupertinoDynamicColor(*color = Color(0xff000000)*, ' - 'darkColor = Color(0xff000001), ' - 'highContrastColor = Color(0xff000003), ' - 'darkHighContrastColor = Color(0xff000005), ' - 'elevatedColor = Color(0xff000002), ' - 'darkElevatedColor = Color(0xff000004), ' - 'highContrastElevatedColor = Color(0xff000006), ' - 'darkHighContrastElevatedColor = Color(0xff000007))', + contains( + 'CupertinoDynamicColor(*color = Color(0xff000000)*, ' + 'darkColor = Color(0xff000001), ' + 'highContrastColor = Color(0xff000003), ' + 'darkHighContrastColor = Color(0xff000005), ' + 'elevatedColor = Color(0xff000002), ' + 'darkElevatedColor = Color(0xff000004), ' + 'highContrastElevatedColor = Color(0xff000006), ' + 'darkHighContrastElevatedColor = Color(0xff000007)', + ), ); - expect(notSoDynamicColor1.toString(), 'CupertinoDynamicColor(*color = Color(0xff000000)*)'); - expect(vibrancyDependentColor1.toString(), 'CupertinoDynamicColor(*color = Color(0xff000001)*, darkColor = Color(0xff000000))'); - expect(contrastDependentColor1.toString(), 'CupertinoDynamicColor(*color = Color(0xff000001)*, highContrastColor = Color(0xff000000))'); - expect(elevationDependentColor1.toString(), 'CupertinoDynamicColor(*color = Color(0xff000001)*, elevatedColor = Color(0xff000000))'); + expect(notSoDynamicColor1.toString(), contains('CupertinoDynamicColor(*color = Color(0xff000000)*')); + expect(vibrancyDependentColor1.toString(), contains('CupertinoDynamicColor(*color = Color(0xff000001)*, darkColor = Color(0xff000000)')); + expect(contrastDependentColor1.toString(), contains('CupertinoDynamicColor(*color = Color(0xff000001)*, highContrastColor = Color(0xff000000)')); + expect(elevationDependentColor1.toString(), contains('CupertinoDynamicColor(*color = Color(0xff000001)*, elevatedColor = Color(0xff000000)')); expect( const CupertinoDynamicColor.withBrightnessAndContrast( @@ -153,10 +155,12 @@ void main() { highContrastColor: color2, darkHighContrastColor: color3, ).toString(), - 'CupertinoDynamicColor(*color = Color(0xff000000)*, ' - 'darkColor = Color(0xff000001), ' - 'highContrastColor = Color(0xff000002), ' - 'darkHighContrastColor = Color(0xff000003))', + contains( + 'CupertinoDynamicColor(*color = Color(0xff000000)*, ' + 'darkColor = Color(0xff000001), ' + 'highContrastColor = Color(0xff000002), ' + 'darkHighContrastColor = Color(0xff000003)', + ), ); }); diff --git a/packages/flutter/test/cupertino/date_picker_test.dart b/packages/flutter/test/cupertino/date_picker_test.dart index ae2ae39fb8..c5ab35e6a1 100644 --- a/packages/flutter/test/cupertino/date_picker_test.dart +++ b/packages/flutter/test/cupertino/date_picker_test.dart @@ -692,7 +692,7 @@ void main() { // 2017 has 28 days in Feb so 29 is greyed out. expect( tester.widget(find.text('29')).style.color, - isSameColorAs(CupertinoColors.inactiveGray), + isSameColorAs(CupertinoColors.inactiveGray.color), ); await tester.drag(find.text('2017'), const Offset(0.0, 32.0), touchSlopY: 0.0); @@ -707,7 +707,7 @@ void main() { // 2016 has 29 days in Feb so 29 is not greyed out. expect( tester.widget(find.text('29')).style.color, - isNot(isSameColorAs(CupertinoColors.inactiveGray)), + isNot(isSameColorAs(CupertinoColors.inactiveGray.color)), ); await tester.drag(find.text('2016'), const Offset(0.0, -32.0), touchSlopY: 0.0); @@ -721,7 +721,7 @@ void main() { expect( tester.widget(find.text('29')).style.color, - isSameColorAs(CupertinoColors.inactiveGray), + isSameColorAs(CupertinoColors.inactiveGray.color), ); }); diff --git a/packages/flutter/test/cupertino/dialog_test.dart b/packages/flutter/test/cupertino/dialog_test.dart index 366c383eae..8ff2103547 100644 --- a/packages/flutter/test/cupertino/dialog_test.dart +++ b/packages/flutter/test/cupertino/dialog_test.dart @@ -60,7 +60,7 @@ void main() { final DefaultTextStyle widget = tester.widget(find.byType(DefaultTextStyle)); - expect(widget.style.color.withAlpha(255).value, CupertinoColors.destructiveRed.value); + expect(widget.style.color.withAlpha(255), CupertinoColors.systemRed.color); }); testWidgets('Dialog dark theme', (WidgetTester tester) async { @@ -183,7 +183,7 @@ void main() { final DefaultTextStyle widget = tester.widget(find.byType(DefaultTextStyle)); - expect(widget.style.color.withAlpha(255).value, CupertinoColors.destructiveRed.value); + expect(widget.style.color.withAlpha(255), CupertinoColors.systemRed.color); expect(widget.style.fontWeight, equals(FontWeight.w600)); }); diff --git a/packages/flutter/test/cupertino/nav_bar_test.dart b/packages/flutter/test/cupertino/nav_bar_test.dart index 9c22ff2295..e03eedc9f6 100644 --- a/packages/flutter/test/cupertino/nav_bar_test.dart +++ b/packages/flutter/test/cupertino/nav_bar_test.dart @@ -173,12 +173,12 @@ void main() { home: CupertinoNavigationBar( leading: CupertinoButton( onPressed: () { }, - child: const _ExpectStyles(color: CupertinoColors.activeBlue, index: 0x000001), + child: _ExpectStyles(color: CupertinoColors.systemBlue.color, index: 0x000001), ), middle: const _ExpectStyles(color: CupertinoColors.black, index: 0x000100), trailing: CupertinoButton( onPressed: () { }, - child: const _ExpectStyles(color: CupertinoColors.activeBlue, index: 0x010000), + child: _ExpectStyles(color: CupertinoColors.systemBlue.color, index: 0x010000), ), ), ), diff --git a/packages/flutter/test/cupertino/segmented_control_test.dart b/packages/flutter/test/cupertino/segmented_control_test.dart index 47f547fc94..c801f58ff8 100644 --- a/packages/flutter/test/cupertino/segmented_control_test.dart +++ b/packages/flutter/test/cupertino/segmented_control_test.dart @@ -369,7 +369,7 @@ void main() { }, groupValue: sharedValue, unselectedColor: CupertinoColors.lightBackgroundGray, - selectedColor: CupertinoColors.activeGreen, + selectedColor: CupertinoColors.activeGreen.color, borderColor: CupertinoColors.black, pressedColor: const Color(0x638CFC7B), ), @@ -383,8 +383,8 @@ void main() { expect(getRenderSegmentedControl(tester).borderColor, CupertinoColors.black); expect(textStyle.style.color, CupertinoColors.lightBackgroundGray); - expect(iconTheme.data.color, CupertinoColors.activeGreen); - expect(getBackgroundColor(tester, 0), CupertinoColors.activeGreen); + expect(iconTheme.data.color, CupertinoColors.activeGreen.color); + expect(getBackgroundColor(tester, 0), CupertinoColors.activeGreen.color); expect(getBackgroundColor(tester, 1), CupertinoColors.lightBackgroundGray); await tester.tap(find.widgetWithIcon(IconTheme, const IconData(1))); @@ -393,17 +393,17 @@ void main() { textStyle = tester.widget(find.widgetWithText(DefaultTextStyle, 'Child 1')); iconTheme = tester.widget(find.widgetWithIcon(IconTheme, const IconData(1))); - expect(textStyle.style.color, CupertinoColors.activeGreen); + expect(textStyle.style.color, CupertinoColors.activeGreen.color); expect(iconTheme.data.color, CupertinoColors.lightBackgroundGray); expect(getBackgroundColor(tester, 0), CupertinoColors.lightBackgroundGray); - expect(getBackgroundColor(tester, 1), CupertinoColors.activeGreen); + expect(getBackgroundColor(tester, 1), CupertinoColors.activeGreen.color); final Offset center = tester.getCenter(find.text('Child 1')); await tester.startGesture(center); await tester.pumpAndSettle(); expect(getBackgroundColor(tester, 0), const Color(0x638CFC7B)); - expect(getBackgroundColor(tester, 1), CupertinoColors.activeGreen); + expect(getBackgroundColor(tester, 1), CupertinoColors.activeGreen.color); }); testWidgets('Widgets are centered within segments', (WidgetTester tester) async { diff --git a/packages/flutter/test/cupertino/text_field_test.dart b/packages/flutter/test/cupertino/text_field_test.dart index 51c3d26a85..bf697650fa 100644 --- a/packages/flutter/test/cupertino/text_field_test.dart +++ b/packages/flutter/test/cupertino/text_field_test.dart @@ -3391,7 +3391,7 @@ void main() { children: [ Container( height: 100, - color: CupertinoColors.activeOrange, + color: CupertinoColors.black, ), Expanded( child: Navigator( diff --git a/packages/flutter/test/cupertino/theme_test.dart b/packages/flutter/test/cupertino/theme_test.dart index 8817c692be..11d03486de 100644 --- a/packages/flutter/test/cupertino/theme_test.dart +++ b/packages/flutter/test/cupertino/theme_test.dart @@ -4,6 +4,9 @@ import 'dart:async'; +import 'package:collection/collection.dart' show SetEquality; +import 'package:flutter/foundation.dart'; +import 'package:flutter/painting.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -56,10 +59,10 @@ void main() { testWidgets('Theme attributes cascade', (WidgetTester tester) async { final CupertinoThemeData theme = await testTheme(tester, const CupertinoThemeData( - primaryColor: CupertinoColors.destructiveRed, + primaryColor: CupertinoColors.systemRed, )); - expect(theme.textTheme.actionTextStyle.color, isSameColorAs(CupertinoColors.destructiveRed)); + expect(theme.textTheme.actionTextStyle.color, isSameColorAs(CupertinoColors.systemRed.color)); }); testWidgets('Dependent attribute can be overridden from cascaded value', (WidgetTester tester) async { @@ -137,12 +140,12 @@ void main() { ); testWidgets("Theme has default IconThemeData, which is derived from the theme's primary color", (WidgetTester tester) async { - const CupertinoDynamicColor primaryColor = CupertinoColors.destructiveRed; + const CupertinoDynamicColor primaryColor = CupertinoColors.systemRed; const CupertinoThemeData themeData = CupertinoThemeData(primaryColor: primaryColor); final IconThemeData resultingIconTheme = await testIconTheme(tester, themeData); - expect(resultingIconTheme.color, themeData.primaryColor); + expect(resultingIconTheme.color, isSameColorAs(primaryColor)); // Works in dark mode if primaryColor is a CupertinoDynamicColor. final Color darkColor = (await testIconTheme( @@ -164,6 +167,36 @@ void main() { expect(iconTheme.color, CupertinoColors.activeOrange); }); + testWidgets('CupertinoTheme diagnostics', (WidgetTester tester) async { + final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); + const CupertinoThemeData().debugFillProperties(builder); + + final Set description = builder.properties + .map((DiagnosticsNode node) => node.name.toString()) + .toSet(); + + expect( + const SetEquality().equals( + description, + { 'brightness', + 'primaryColor', + 'primaryContrastingColor', + 'barBackgroundColor', + 'scaffoldBackgroundColor', + 'textStyle', + 'actionTextStyle', + 'tabLabelTextStyle', + 'navTitleTextStyle', + 'navLargeTitleTextStyle', + 'navActionTextStyle', + 'pickerTextStyle', + 'dateTimePickerTextStyle' + } + ), + isTrue, + ); + }); + Brightness currentBrightness; void colorMatches(Color componentColor, CupertinoDynamicColor expectedDynamicColor) { switch (currentBrightness) { @@ -181,7 +214,7 @@ void main() { final CupertinoThemeData data = CupertinoThemeData(brightness: currentBrightness, primaryColor: CupertinoColors.systemRed); final CupertinoThemeData theme = await testTheme(tester, data); - expect(data.primaryColor, isSameColorAs(CupertinoColors.systemRed.color)); + expect(data.primaryColor, isSameColorAs(CupertinoColors.systemRed)); colorMatches(theme.primaryColor, CupertinoColors.systemRed); }); diff --git a/packages/flutter_test/lib/src/matchers.dart b/packages/flutter_test/lib/src/matchers.dart index 0525404177..e5af78da54 100644 --- a/packages/flutter_test/lib/src/matchers.dart +++ b/packages/flutter_test/lib/src/matchers.dart @@ -1625,7 +1625,7 @@ class _ColorMatcher extends Matcher { @override bool matches(dynamic item, Map matchState) { if (item is Color) - return item.value == targetColor.value; + return item == targetColor || item.value == targetColor.value; return false; }