Unverified Commit deb4184f authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

Remove CupertinoSystemColors in favor of CupertinoColors (#40566)

parent 61c6c292
......@@ -296,7 +296,7 @@ class CupertinoActionSheetAction extends StatelessWidget {
Widget build(BuildContext context) {
TextStyle style = _kActionSheetActionStyle.copyWith(
color: isDestructiveAction
? CupertinoSystemColors.of(context).systemRed
? CupertinoDynamicColor.resolve(CupertinoColors.systemRed, context)
: CupertinoTheme.of(context).primaryColor,
);
......@@ -362,7 +362,7 @@ class _CupertinoActionSheetCancelButtonState extends State<_CupertinoActionSheet
Widget build(BuildContext context) {
final Color backgroundColor = isBeingPressed
? _kCancelPressedColor
: CupertinoSystemColors.of(context).secondarySystemGroupedBackground;
: CupertinoColors.secondarySystemGroupedBackground;
return GestureDetector(
excludeFromSemantics: true,
onTapDown: _onTapDown,
......
......@@ -273,50 +273,47 @@ class _CupertinoAppState extends State<CupertinoApp> {
data: CupertinoUserInterfaceLevelData.base,
child: CupertinoTheme(
data: effectiveThemeData,
child: CupertinoSystemColors(
data: CupertinoSystemColors.of(context, useFallbackValues: true),
child: Builder(
builder: (BuildContext context) {
return WidgetsApp(
key: GlobalObjectKey(this),
navigatorKey: widget.navigatorKey,
navigatorObservers: _navigatorObservers,
pageRouteBuilder: <T>(RouteSettings settings, WidgetBuilder builder) =>
CupertinoPageRoute<T>(settings: settings, builder: builder),
home: widget.home,
routes: widget.routes,
initialRoute: widget.initialRoute,
onGenerateRoute: widget.onGenerateRoute,
onUnknownRoute: widget.onUnknownRoute,
builder: widget.builder,
title: widget.title,
onGenerateTitle: widget.onGenerateTitle,
textStyle: effectiveThemeData.textTheme.textStyle,
color: CupertinoDynamicColor.resolve(widget.color ?? effectiveThemeData.primaryColor, context),
locale: widget.locale,
localizationsDelegates: _localizationsDelegates,
localeResolutionCallback: widget.localeResolutionCallback,
localeListResolutionCallback: widget.localeListResolutionCallback,
supportedLocales: widget.supportedLocales,
showPerformanceOverlay: widget.showPerformanceOverlay,
checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages,
checkerboardOffscreenLayers: widget.checkerboardOffscreenLayers,
showSemanticsDebugger: widget.showSemanticsDebugger,
debugShowCheckedModeBanner: widget.debugShowCheckedModeBanner,
inspectorSelectButtonBuilder: (BuildContext context, VoidCallback onPressed) {
return CupertinoButton.filled(
child: const Icon(
CupertinoIcons.search,
size: 28.0,
color: CupertinoColors.white,
),
padding: EdgeInsets.zero,
onPressed: onPressed,
);
},
);
},
),
child: Builder(
builder: (BuildContext context) {
return WidgetsApp(
key: GlobalObjectKey(this),
navigatorKey: widget.navigatorKey,
navigatorObservers: _navigatorObservers,
pageRouteBuilder: <T>(RouteSettings settings, WidgetBuilder builder) =>
CupertinoPageRoute<T>(settings: settings, builder: builder),
home: widget.home,
routes: widget.routes,
initialRoute: widget.initialRoute,
onGenerateRoute: widget.onGenerateRoute,
onUnknownRoute: widget.onUnknownRoute,
builder: widget.builder,
title: widget.title,
onGenerateTitle: widget.onGenerateTitle,
textStyle: effectiveThemeData.textTheme.textStyle,
color: CupertinoDynamicColor.resolve(widget.color ?? effectiveThemeData.primaryColor, context),
locale: widget.locale,
localizationsDelegates: _localizationsDelegates,
localeResolutionCallback: widget.localeResolutionCallback,
localeListResolutionCallback: widget.localeListResolutionCallback,
supportedLocales: widget.supportedLocales,
showPerformanceOverlay: widget.showPerformanceOverlay,
checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages,
checkerboardOffscreenLayers: widget.checkerboardOffscreenLayers,
showSemanticsDebugger: widget.showSemanticsDebugger,
debugShowCheckedModeBanner: widget.debugShowCheckedModeBanner,
inspectorSelectButtonBuilder: (BuildContext context, VoidCallback onPressed) {
return CupertinoButton.filled(
child: const Icon(
CupertinoIcons.search,
size: 28.0,
color: CupertinoColors.white,
),
padding: EdgeInsets.zero,
onPressed: onPressed,
);
},
);
},
),
),
),
......
......@@ -31,12 +31,13 @@ class CupertinoButton extends StatefulWidget {
@required this.child,
this.padding,
this.color,
this.disabledColor,
this.disabledColor = CupertinoColors.quaternarySystemFill,
this.minSize = kMinInteractiveDimensionCupertino,
this.pressedOpacity = 0.1,
this.borderRadius = const BorderRadius.all(Radius.circular(8.0)),
@required this.onPressed,
}) : assert(pressedOpacity == null || (pressedOpacity >= 0.0 && pressedOpacity <= 1.0)),
assert(disabledColor != null),
_filled = false,
super(key: key);
......@@ -50,12 +51,13 @@ class CupertinoButton extends StatefulWidget {
Key key,
@required this.child,
this.padding,
this.disabledColor,
this.disabledColor = CupertinoColors.quaternarySystemFill,
this.minSize = kMinInteractiveDimensionCupertino,
this.pressedOpacity = 0.1,
this.borderRadius = const BorderRadius.all(Radius.circular(8.0)),
@required this.onPressed,
}) : assert(pressedOpacity == null || (pressedOpacity >= 0.0 && pressedOpacity <= 1.0)),
assert(disabledColor != null),
color = null,
_filled = true,
super(key: key);
......@@ -82,8 +84,8 @@ class CupertinoButton extends StatefulWidget {
///
/// Ignored if the [CupertinoButton] doesn't also have a [color].
///
/// Defaults to [CupertinoSystemColors.quaternarySystemFill] when [color] is
/// specified and [disabledColor] is null.
/// Defaults to [CupertinoColors.quaternarySystemFill] when [color] is
/// specified. Must not be null.
final Color disabledColor;
/// The callback that is called when the button is tapped or otherwise activated.
......@@ -214,7 +216,7 @@ class _CupertinoButtonState extends State<CupertinoButton> with SingleTickerProv
? themeData.primaryContrastingColor
: enabled
? primaryColor
: CupertinoDynamicColor.resolve(CupertinoSystemColors.of(context).placeholderText, context);
: CupertinoDynamicColor.resolve(CupertinoColors.placeholderText, context);
final TextStyle textStyle = themeData.textTheme.textStyle.copyWith(color: foregroundColor);
......@@ -239,7 +241,7 @@ class _CupertinoButtonState extends State<CupertinoButton> with SingleTickerProv
decoration: BoxDecoration(
borderRadius: widget.borderRadius,
color: backgroundColor != null && !enabled
? CupertinoDynamicColor.resolve(widget.disabledColor ?? CupertinoSystemColors.of(context).quaternarySystemFill, context)
? CupertinoDynamicColor.resolve(widget.disabledColor, context)
: backgroundColor,
),
child: Padding(
......
......@@ -21,24 +21,23 @@ import 'theme.dart';
class CupertinoColors {
CupertinoColors._();
/// iOS 10's default blue color. Used to indicate active elements such as
/// iOS 13's default blue color. Used to indicate active elements such as
/// buttons, selected tabs and your own chat bubbles.
///
/// This is SystemBlue in the iOS palette.
static const Color activeBlue = Color(0xFF007AFF);
static const CupertinoDynamicColor activeBlue = systemBlue;
/// iOS 10's default green color. Used to indicate active accents such as
/// iOS 13's default green color. Used to indicate active accents such as
/// the switch in its on state and some accent buttons such as the call button
/// and Apple Map's 'Go' button.
///
/// This is SystemGreen in the iOS palette.
static const Color activeGreen = Color(0xFF4CD964);
static const CupertinoDynamicColor activeGreen = systemGreen;
/// iOS 12's default dark mode color. Used in place of the [activeBlue] color
/// as the default active elements' color when the theme's brightness is dark.
/// iOS 13's orange color.
///
/// This is SystemOrange in the iOS palette.
static const Color activeOrange = Color(0xFFFF9500);
static const CupertinoDynamicColor activeOrange = systemOrange;
/// Opaque white color. Used for backgrounds and fonts against dark backgrounds.
///
......@@ -78,7 +77,7 @@ class CupertinoColors {
/// Used in iOS 13 for unselected selectables such as tab bar items in their
/// inactive state or de-emphasized subtitles and details text.
///
/// Not the same gray as disabled buttons etc.
/// Not the same grey as disabled buttons etc.
///
/// This is the disabled color in the iOS palette.
static const Color inactiveGray = CupertinoDynamicColor.withBrightness(
......@@ -86,251 +85,690 @@ class CupertinoColors {
darkColor: Color(0xFF757575),
);
/// Used for iOS 10 for destructive actions such as the delete actions in
/// Used for iOS 13 for destructive actions such as the delete actions in
/// table view cells and dialogs.
///
/// Not the same red as the camera shutter or springboard icon notifications
/// or the foreground red theme in various native apps such as HealthKit.
///
/// This is SystemRed in the iOS palette.
static const Color destructiveRed = Color(0xFFFF3B30);
}
static const Color destructiveRed = systemRed;
/// A [Color] subclass that represents a family of colors, and the currect effective
/// color in the color family.
///
/// When used as a regular color, `CupertinoDynamicColor` is equivalent to the
/// effective color (i.e. [CupertinoDynamicColor.value] will come from the effective
/// color), which is determined by the [BuildContext] it is last resolved against.
/// If it has never been resolved, the light, normal contrast, base elevation variant
/// [CupertinoDynamicColor.color] will be the effective color.
// TODO(LongCatIsLooong): publicize once all Cupertino components have adopted this.
// {@tool sample}
//
// The following snippet will create a [CupertinoButton] whose background color
// is _lightModeColor_ in light mode but _darkModeColor_ in dark mode.
//
//
// ```dart
// CupertinoButton(
// child: child,
// color: CupertinoDynamicColor.withVibrancy(
// color: lightModeColor,
// darkColor: darkModeColor,
// ),
// onTap: () => null,
// )
// ```
// {@end-tool}
//
// When a Cupertino component is provided with a `CupertinoDynamicColor`, either
// directly in its constructor, or from an [InheritedWidget] it depends on (for example,
// [DefaultTextStyle]), the component will automatically resolve the color by calling
// [CupertinoDynamicColor.resolve], using their own [BuildContext].
//
// When used outside of a Cupertino component, such color resolution will not happen
// automatically. It's essential to call [CupertinoDynamicColor.resolve] with the
// correct [BuildContext] before using the color to paint, in order to get the
// desired effect.
///
/// See also:
///
/// * [CupertinoUserInterfaceLevel], an [InheritedWidget] that may affect color
/// resolution of a `CupertinoDynamicColor`.
/// * [CupertinoSystemColors], an [InheritedWidget] that exposes system colors
/// of iOS 13+.
/// * https://developer.apple.com/documentation/uikit/uicolor/3238042-resolvedcolor.
@immutable
class CupertinoDynamicColor extends Color {
/// Creates an adaptive [Color] that changes its effective color based on the
/// [BuildContext] given. The default effective color is [color].
/// A blue color that can adapt to the given [BuildContext].
///
/// All the colors must not be null.
const CupertinoDynamicColor({
@required Color color,
@required Color darkColor,
@required Color highContrastColor,
@required Color darkHighContrastColor,
@required Color elevatedColor,
@required Color darkElevatedColor,
@required Color highContrastElevatedColor,
@required Color darkHighContrastElevatedColor,
}) : this._(
color,
color,
darkColor,
highContrastColor,
darkHighContrastColor,
elevatedColor,
darkElevatedColor,
highContrastElevatedColor,
darkHighContrastElevatedColor,
);
/// Creates an adaptive [Color] that changes its effective color based on the
/// given [BuildContext]'s brightness (from [MediaQueryData.platformBrightness]
/// or [CupertinoThemeData.brightness]) and accessibility contrast setting
/// ([MediaQueryData.highContrast]). The default effective color is [color].
/// See also:
///
/// All the colors must not be null.
const CupertinoDynamicColor.withBrightnessAndContrast({
@required Color color,
@required Color darkColor,
@required Color highContrastColor,
@required Color darkHighContrastColor,
}) : this(
color: color,
darkColor: darkColor,
highContrastColor: highContrastColor,
darkHighContrastColor: darkHighContrastColor,
elevatedColor: color,
darkElevatedColor: darkColor,
highContrastElevatedColor: highContrastColor,
darkHighContrastElevatedColor: darkHighContrastColor,
/// * [UIColor.systemBlue](https://developer.apple.com/documentation/uikit/uicolor/3173141-systemblue),
/// the `UIKit` equivalent.
static const CupertinoDynamicColor systemBlue = CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 0, 122, 255),
darkColor: Color.fromARGB(255, 10, 132, 255),
highContrastColor: Color.fromARGB(255, 0, 64, 221),
darkHighContrastColor: Color.fromARGB(255, 64, 156, 255),
);
/// Creates an adaptive [Color] that changes its effective color based on the given
/// [BuildContext]'s brightness (from [MediaQueryData.platformBrightness] or
/// [CupertinoThemeData.brightness]). The default effective color is [color].
/// A green color that can adapt to the given [BuildContext].
///
/// All the colors must not be null.
const CupertinoDynamicColor.withBrightness({
@required Color color,
@required Color darkColor,
}) : this(
color: color,
darkColor: darkColor,
highContrastColor: color,
darkHighContrastColor: darkColor,
elevatedColor: color,
darkElevatedColor: darkColor,
highContrastElevatedColor: color,
darkHighContrastElevatedColor: darkColor,
/// See also:
///
/// * [UIColor.systemGreen](https://developer.apple.com/documentation/uikit/uicolor/3173144-systemgreen),
/// the `UIKit` equivalent.
static const CupertinoDynamicColor systemGreen = CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 52, 199, 89),
darkColor: Color.fromARGB(255, 48, 209, 88),
highContrastColor: Color.fromARGB(255, 36, 138, 61),
darkHighContrastColor: Color.fromARGB(255, 48, 219, 91),
);
const CupertinoDynamicColor._(
this._effectiveColor,
this.color,
this.darkColor,
this.highContrastColor,
this.darkHighContrastColor,
this.elevatedColor,
this.darkElevatedColor,
this.highContrastElevatedColor,
this.darkHighContrastElevatedColor,
) : assert(color != null),
assert(darkColor != null),
assert(highContrastColor != null),
assert(darkHighContrastColor != null),
assert(elevatedColor != null),
assert(darkElevatedColor != null),
assert(highContrastElevatedColor != null),
assert(darkHighContrastElevatedColor != null),
assert(_effectiveColor != null),
// The super constructor has to be called with a dummy value in order to mark
// this constructor const.
// The field `value` is overriden in the class implementation.
super(0);
final Color _effectiveColor;
@override
int get value => _effectiveColor.value;
/// The color to use when the [BuildContext] implies a combination of light mode,
/// normal contrast, and base interface elevation.
/// An indigo color that can adapt to the given [BuildContext].
///
/// In other words, this color will be the effective color of the `CupertinoDynamicColor`
/// after it is resolved against a [BuildContext] that:
/// - has a [CupertinoTheme] whose [brightness] is [PlatformBrightness.light],
/// or a [MediaQuery] whose [MediaQueryData.platformBrightness] is [PlatformBrightness.light].
/// - has a [MediaQuery] whose [MediaQueryData.highContrast] is `false`.
/// - has a [CupertinoUserInterfaceLevel] that indicates [CupertinoUserInterfaceLevelData.base].
final Color color;
/// The color to use when the [BuildContext] implies a combination of dark mode,
/// normal contrast, and base interface elevation.
/// See also:
///
/// In other words, this color will be the effective color of the `CupertinoDynamicColor`
/// after it is resolved against a [BuildContext] that:
/// - has a [CupertinoTheme] whose [brightness] is [PlatformBrightness.dark],
/// or a [MediaQuery] whose [MediaQueryData.platformBrightness] is [PlatformBrightness.dark].
/// - has a [MediaQuery] whose [MediaQueryData.highContrast] is `false`.
/// - has a [CupertinoUserInterfaceLevel] that indicates [CupertinoUserInterfaceLevelData.base].
final Color darkColor;
/// * [UIColor.systemIndigo](https://developer.apple.com/documentation/uikit/uicolor/3173146-systemindigo),
/// the `UIKit` equivalent.
static const CupertinoDynamicColor systemIndigo = CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 88, 86, 214),
darkColor: Color.fromARGB(255, 94, 92, 230),
highContrastColor: Color.fromARGB(255, 54, 52, 163),
darkHighContrastColor: Color.fromARGB(255, 125, 122, 255),
);
/// The color to use when the [BuildContext] implies a combination of light mode,
/// high contrast, and base interface elevation.
/// An orange color that can adapt to the given [BuildContext].
///
/// In other words, this color will be the effective color of the `CupertinoDynamicColor`
/// after it is resolved against a [BuildContext] that:
/// - has a [CupertinoTheme] whose [brightness] is [PlatformBrightness.light],
/// or a [MediaQuery] whose [MediaQueryData.platformBrightness] is [PlatformBrightness.light].
/// - has a [MediaQuery] whose [MediaQueryData.highContrast] is `true`.
/// - has a [CupertinoUserInterfaceLevel] that indicates [CupertinoUserInterfaceLevelData.base].
final Color highContrastColor;
/// The color to use when the [BuildContext] implies a combination of dark mode,
/// high contrast, and base interface elevation.
/// See also:
///
/// In other words, this color will be the effective color of the `CupertinoDynamicColor`
/// after it is resolved against a [BuildContext] that:
/// - has a [CupertinoTheme] whose [brightness] is [PlatformBrightness.dark],
/// or a [MediaQuery] whose [MediaQueryData.platformBrightness] is [PlatformBrightness.dark].
/// - has a [MediaQuery] whose [MediaQueryData.highContrast] is `true`.
/// - has a [CupertinoUserInterfaceLevel] that indicates [CupertinoUserInterfaceLevelData.base].
final Color darkHighContrastColor;
/// * [UIColor.systemOrange](https://developer.apple.com/documentation/uikit/uicolor/3173147-systemorange),
/// the `UIKit` equivalent.
static const CupertinoDynamicColor systemOrange = CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 255, 149, 0),
darkColor: Color.fromARGB(255, 255, 159, 10),
highContrastColor: Color.fromARGB(255, 201, 52, 0),
darkHighContrastColor: Color.fromARGB(255, 255, 179, 64),
);
/// The color to use when the [BuildContext] implies a combination of light mode,
/// normal contrast, and elevated interface elevation.
/// A pink color that can adapt to the given [BuildContext].
///
/// In other words, this color will be the effective color of the `CupertinoDynamicColor`
/// after it is resolved against a [BuildContext] that:
/// - has a [CupertinoTheme] whose [brightness] is [PlatformBrightness.light],
/// or a [MediaQuery] whose [MediaQueryData.platformBrightness] is [PlatformBrightness.light].
/// - has a [MediaQuery] whose [MediaQueryData.highContrast] is `false`.
/// - has a [CupertinoUserInterfaceLevel] that indicates [CupertinoUserInterfaceLevelData.elevated].
final Color elevatedColor;
/// The color to use when the [BuildContext] implies a combination of dark mode,
/// normal contrast, and elevated interface elevation.
/// See also:
///
/// In other words, this color will be the effective color of the `CupertinoDynamicColor`
/// after it is resolved against a [BuildContext] that:
/// - has a [CupertinoTheme] whose [brightness] is [PlatformBrightness.dark],
/// or a [MediaQuery] whose [MediaQueryData.platformBrightness] is [PlatformBrightness.dark].
/// - has a [MediaQuery] whose [MediaQueryData.highContrast] is `false`.
/// - has a [CupertinoUserInterfaceLevel] that indicates [CupertinoUserInterfaceLevelData.elevated].
final Color darkElevatedColor;
/// * [UIColor.systemPink](https://developer.apple.com/documentation/uikit/uicolor/3173148-systempink),
/// the `UIKit` equivalent.
static const CupertinoDynamicColor systemPink = CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 255, 45, 85),
darkColor: Color.fromARGB(255, 255, 55, 95),
highContrastColor: Color.fromARGB(255, 211, 15, 69),
darkHighContrastColor: Color.fromARGB(255, 255, 100, 130),
);
/// The color to use when the [BuildContext] implies a combination of light mode,
/// high contrast, and elevated interface elevation.
/// A purple color that can adapt to the given [BuildContext].
///
/// In other words, this color will be the effective color of the `CupertinoDynamicColor`
/// after it is resolved against a [BuildContext] that:
/// - has a [CupertinoTheme] whose [brightness] is [PlatformBrightness.light],
/// or a [MediaQuery] whose [MediaQueryData.platformBrightness] is [PlatformBrightness.light].
/// - has a [MediaQuery] whose [MediaQueryData.highContrast] is `true`.
/// - has a [CupertinoUserInterfaceLevel] that indicates [CupertinoUserInterfaceLevelData.elevated].
final Color highContrastElevatedColor;
/// The color to use when the [BuildContext] implies a combination of dark mode,
/// high contrast, and elevated interface elevation.
/// See also:
///
/// In other words, this color will be the effective color of the `CupertinoDynamicColor`
/// after it is resolved against a [BuildContext] that:
/// - has a [CupertinoTheme] whose [brightness] is [PlatformBrightness.dark],
/// or a [MediaQuery] whose [MediaQueryData.platformBrightness] is [PlatformBrightness.dark].
/// - has a [MediaQuery] whose [MediaQueryData.highContrast] is `true`.
/// - has a [CupertinoUserInterfaceLevel] that indicates [CupertinoUserInterfaceLevelData.elevated].
final Color darkHighContrastElevatedColor;
/// * [UIColor.systemPurple](https://developer.apple.com/documentation/uikit/uicolor/3173149-systempurple),
/// the `UIKit` equivalent.
static const CupertinoDynamicColor systemPurple = CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 175, 82, 222),
darkColor: Color.fromARGB(255, 191, 90, 242),
highContrastColor: Color.fromARGB(255, 137, 68, 171),
darkHighContrastColor: Color.fromARGB(255, 218, 143, 255),
);
/// Resolves the given [Color] by calling [resolveFrom].
/// A red color that can adapt to the given [BuildContext].
///
/// If the given color is already a concrete [Color], it will be returned as is.
/// If the given color is null, returns null.
/// If the given color is a [CupertinoDynamicColor], but the given [BuildContext]
/// lacks the dependencies required to the color resolution, the default trait
/// See also:
///
/// * [UIColor.systemRed](https://developer.apple.com/documentation/uikit/uicolor/3173150-systemred),
/// the `UIKit` equivalent.
static const CupertinoDynamicColor systemRed = CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 255, 59, 48),
darkColor: Color.fromARGB(255, 255, 69, 58),
highContrastColor: Color.fromARGB(255, 215, 0, 21),
darkHighContrastColor: Color.fromARGB(255, 255, 105, 97),
);
/// A teal color that can adapt to the given [BuildContext].
///
/// See also:
///
/// * [UIColor.systemTeal](https://developer.apple.com/documentation/uikit/uicolor/3173151-systemteal),
/// the `UIKit` equivalent.
static const CupertinoDynamicColor systemTeal = CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 90, 200, 250),
darkColor: Color.fromARGB(255, 100, 210, 255),
highContrastColor: Color.fromARGB(255, 0, 113, 164),
darkHighContrastColor: Color.fromARGB(255, 112, 215, 255),
);
/// A yellow color that can adapt to the given [BuildContext].
///
/// See also:
///
/// * [UIColor.systemYellow](https://developer.apple.com/documentation/uikit/uicolor/3173152-systemyellow),
/// the `UIKit` equivalent.
static const CupertinoDynamicColor systemYellow = CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 255, 204, 0),
darkColor: Color.fromARGB(255, 255, 214, 10),
highContrastColor: Color.fromARGB(255, 160, 90, 0),
darkHighContrastColor: Color.fromARGB(255, 255, 212, 38),
);
/// The base grey color.
///
/// See also:
///
/// * [UIColor.systemGray](https://developer.apple.com/documentation/uikit/uicolor/3173143-systemgray),
/// the `UIKit` equivalent.
static const CupertinoDynamicColor systemGrey = CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 142, 142, 147),
darkColor: Color.fromARGB(255, 142, 142, 147),
highContrastColor: Color.fromARGB(255, 108, 108, 112),
darkHighContrastColor: Color.fromARGB(255, 174, 174, 178),
);
/// A second-level shade of grey.
///
/// See also:
///
/// * [UIColor.systemGray2](https://developer.apple.com/documentation/uikit/uicolor/3255071-systemgray2),
/// the `UIKit` equivalent.
static const CupertinoDynamicColor systemGrey2 = CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 174, 174, 178),
darkColor: Color.fromARGB(255, 99, 99, 102),
highContrastColor: Color.fromARGB(255, 142, 142, 147),
darkHighContrastColor: Color.fromARGB(255, 124, 124, 128),
);
/// A third-level shade of grey.
///
/// See also:
///
/// * [UIColor.systemGray3](https://developer.apple.com/documentation/uikit/uicolor/3255072-systemgray3),
/// the `UIKit` equivalent.
static const CupertinoDynamicColor systemGrey3 = CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 199, 199, 204),
darkColor: Color.fromARGB(255, 72, 72, 74),
highContrastColor: Color.fromARGB(255, 174, 174, 178),
darkHighContrastColor: Color.fromARGB(255, 84, 84, 86),
);
/// A fourth-level shade of grey.
///
/// See also:
///
/// * [UIColor.systemGray4](https://developer.apple.com/documentation/uikit/uicolor/3255073-systemgray4),
/// the `UIKit` equivalent.
static const CupertinoDynamicColor systemGrey4 = CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 209, 209, 214),
darkColor: Color.fromARGB(255, 58, 58, 60),
highContrastColor: Color.fromARGB(255, 188, 188, 192),
darkHighContrastColor: Color.fromARGB(255, 68, 68, 70),
);
/// A fifth-level shade of grey.
///
/// See also:
///
/// * [UIColor.systemGray5](https://developer.apple.com/documentation/uikit/uicolor/3255074-systemgray5),
/// the `UIKit` equivalent.
static const CupertinoDynamicColor systemGrey5 = CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 229, 229, 234),
darkColor: Color.fromARGB(255, 44, 44, 46),
highContrastColor: Color.fromARGB(255, 216, 216, 220),
darkHighContrastColor: Color.fromARGB(255, 54, 54, 56),
);
/// A sixth-level shade of grey.
///
/// See also:
///
/// * [UIColor.systemGray6](https://developer.apple.com/documentation/uikit/uicolor/3255075-systemgray6),
/// the `UIKit` equivalent.
static const CupertinoDynamicColor systemGrey6 = CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 242, 242, 247),
darkColor: Color.fromARGB(255, 28, 28, 30),
highContrastColor: Color.fromARGB(255, 235, 235, 240),
darkHighContrastColor: Color.fromARGB(255, 36, 36, 38),
);
/// 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(
color: Color.fromARGB(255, 0, 0, 0),
darkColor: Color.fromARGB(255, 255, 255, 255),
highContrastColor: Color.fromARGB(255, 0, 0, 0),
darkHighContrastColor: Color.fromARGB(255, 255, 255, 255),
elevatedColor: Color.fromARGB(255, 0, 0, 0),
darkElevatedColor: Color.fromARGB(255, 255, 255, 255),
highContrastElevatedColor: Color.fromARGB(255, 0, 0, 0),
darkHighContrastElevatedColor: Color.fromARGB(255, 255, 255, 255),
);
/// 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(
color: Color.fromARGB(255, 0, 0, 0),
darkColor: Color.fromARGB(255, 255, 255, 255),
highContrastColor: Color.fromARGB(255, 0, 0, 0),
darkHighContrastColor: Color.fromARGB(255, 255, 255, 255),
elevatedColor: Color.fromARGB(255, 0, 0, 0),
darkElevatedColor: Color.fromARGB(255, 255, 255, 255),
highContrastElevatedColor: Color.fromARGB(255, 0, 0, 0),
darkHighContrastElevatedColor: Color.fromARGB(255, 255, 255, 255),
);
/// 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(
color: Color.fromARGB(76, 60, 60, 67),
darkColor: Color.fromARGB(76, 235, 235, 245),
highContrastColor: Color.fromARGB(96, 60, 60, 67),
darkHighContrastColor: Color.fromARGB(96, 235, 235, 245),
elevatedColor: Color.fromARGB(76, 60, 60, 67),
darkElevatedColor: Color.fromARGB(76, 235, 235, 245),
highContrastElevatedColor: Color.fromARGB(96, 60, 60, 67),
darkHighContrastElevatedColor: Color.fromARGB(96, 235, 235, 245),
);
/// 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(
color: Color.fromARGB(45, 60, 60, 67),
darkColor: Color.fromARGB(40, 235, 235, 245),
highContrastColor: Color.fromARGB(66, 60, 60, 67),
darkHighContrastColor: Color.fromARGB(61, 235, 235, 245),
elevatedColor: Color.fromARGB(45, 60, 60, 67),
darkElevatedColor: Color.fromARGB(40, 235, 235, 245),
highContrastElevatedColor: Color.fromARGB(66, 60, 60, 67),
darkHighContrastElevatedColor: Color.fromARGB(61, 235, 235, 245),
);
/// 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(
color: Color.fromARGB(51, 120, 120, 128),
darkColor: Color.fromARGB(91, 120, 120, 128),
highContrastColor: Color.fromARGB(71, 120, 120, 128),
darkHighContrastColor: Color.fromARGB(112, 120, 120, 128),
elevatedColor: Color.fromARGB(51, 120, 120, 128),
darkElevatedColor: Color.fromARGB(91, 120, 120, 128),
highContrastElevatedColor: Color.fromARGB(71, 120, 120, 128),
darkHighContrastElevatedColor: Color.fromARGB(112, 120, 120, 128),
);
/// 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(
color: Color.fromARGB(40, 120, 120, 128),
darkColor: Color.fromARGB(81, 120, 120, 128),
highContrastColor: Color.fromARGB(61, 120, 120, 128),
darkHighContrastColor: Color.fromARGB(102, 120, 120, 128),
elevatedColor: Color.fromARGB(40, 120, 120, 128),
darkElevatedColor: Color.fromARGB(81, 120, 120, 128),
highContrastElevatedColor: Color.fromARGB(61, 120, 120, 128),
darkHighContrastElevatedColor: Color.fromARGB(102, 120, 120, 128),
);
/// 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(
color: Color.fromARGB(30, 118, 118, 128),
darkColor: Color.fromARGB(61, 118, 118, 128),
highContrastColor: Color.fromARGB(51, 118, 118, 128),
darkHighContrastColor: Color.fromARGB(81, 118, 118, 128),
elevatedColor: Color.fromARGB(30, 118, 118, 128),
darkElevatedColor: Color.fromARGB(61, 118, 118, 128),
highContrastElevatedColor: Color.fromARGB(51, 118, 118, 128),
darkHighContrastElevatedColor: Color.fromARGB(81, 118, 118, 128),
);
/// 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(
color: Color.fromARGB(20, 116, 116, 128),
darkColor: Color.fromARGB(45, 118, 118, 128),
highContrastColor: Color.fromARGB(40, 116, 116, 128),
darkHighContrastColor: Color.fromARGB(66, 118, 118, 128),
elevatedColor: Color.fromARGB(20, 116, 116, 128),
darkElevatedColor: Color.fromARGB(45, 118, 118, 128),
highContrastElevatedColor: Color.fromARGB(40, 116, 116, 128),
darkHighContrastElevatedColor: Color.fromARGB(66, 118, 118, 128),
);
/// 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(
color: Color.fromARGB(76, 60, 60, 67),
darkColor: Color.fromARGB(76, 235, 235, 245),
highContrastColor: Color.fromARGB(96, 60, 60, 67),
darkHighContrastColor: Color.fromARGB(96, 235, 235, 245),
elevatedColor: Color.fromARGB(76, 60, 60, 67),
darkElevatedColor: Color.fromARGB(76, 235, 235, 245),
highContrastElevatedColor: Color.fromARGB(96, 60, 60, 67),
darkHighContrastElevatedColor: Color.fromARGB(96, 235, 235, 245),
);
/// The color for the main background of your interface, equivalent to
/// [UIColor.systemBackground](https://developer.apple.com/documentation/uikit/uicolor/3173140-systembackground).
///
/// Typically used for designs that have a white primary background in a light environment.
static const CupertinoDynamicColor systemBackground = CupertinoDynamicColor(
color: Color.fromARGB(255, 255, 255, 255),
darkColor: Color.fromARGB(255, 0, 0, 0),
highContrastColor: Color.fromARGB(255, 255, 255, 255),
darkHighContrastColor: Color.fromARGB(255, 0, 0, 0),
elevatedColor: Color.fromARGB(255, 255, 255, 255),
darkElevatedColor: Color.fromARGB(255, 28, 28, 30),
highContrastElevatedColor: Color.fromARGB(255, 255, 255, 255),
darkHighContrastElevatedColor: Color.fromARGB(255, 36, 36, 38),
);
/// The color for content layered on top of the main background, equivalent to
/// [UIColor.secondarySystemBackground](https://developer.apple.com/documentation/uikit/uicolor/3173137-secondarysystembackground).
///
/// Typically used for designs that have a white primary background in a light environment.
static const CupertinoDynamicColor secondarySystemBackground = CupertinoDynamicColor(
color: Color.fromARGB(255, 242, 242, 247),
darkColor: Color.fromARGB(255, 28, 28, 30),
highContrastColor: Color.fromARGB(255, 235, 235, 240),
darkHighContrastColor: Color.fromARGB(255, 36, 36, 38),
elevatedColor: Color.fromARGB(255, 242, 242, 247),
darkElevatedColor: Color.fromARGB(255, 44, 44, 46),
highContrastElevatedColor: Color.fromARGB(255, 235, 235, 240),
darkHighContrastElevatedColor: Color.fromARGB(255, 54, 54, 56),
);
/// The color for content layered on top of secondary backgrounds, equivalent
/// to [UIColor.tertiarySystemBackground](https://developer.apple.com/documentation/uikit/uicolor/3173154-tertiarysystembackground).
///
/// Typically used for designs that have a white primary background in a light environment.
static const CupertinoDynamicColor tertiarySystemBackground = CupertinoDynamicColor(
color: Color.fromARGB(255, 255, 255, 255),
darkColor: Color.fromARGB(255, 44, 44, 46),
highContrastColor: Color.fromARGB(255, 255, 255, 255),
darkHighContrastColor: Color.fromARGB(255, 54, 54, 56),
elevatedColor: Color.fromARGB(255, 255, 255, 255),
darkElevatedColor: Color.fromARGB(255, 58, 58, 60),
highContrastElevatedColor: Color.fromARGB(255, 255, 255, 255),
darkHighContrastElevatedColor: Color.fromARGB(255, 68, 68, 70),
);
/// The color for the main background of your grouped interface, equivalent to
/// [UIColor.systemGroupedBackground](https://developer.apple.com/documentation/uikit/uicolor/3173145-systemgroupedbackground).
///
/// Typically used for grouped content, including table views and platter-based designs.
static const CupertinoDynamicColor systemGroupedBackground = CupertinoDynamicColor(
color: Color.fromARGB(255, 242, 242, 247),
darkColor: Color.fromARGB(255, 0, 0, 0),
highContrastColor: Color.fromARGB(255, 235, 235, 240),
darkHighContrastColor: Color.fromARGB(255, 0, 0, 0),
elevatedColor: Color.fromARGB(255, 242, 242, 247),
darkElevatedColor: Color.fromARGB(255, 28, 28, 30),
highContrastElevatedColor: Color.fromARGB(255, 235, 235, 240),
darkHighContrastElevatedColor: Color.fromARGB(255, 36, 36, 38),
);
/// The color for content layered on top of the main background of your grouped interface,
/// equivalent to [UIColor.secondarySystemGroupedBackground](https://developer.apple.com/documentation/uikit/uicolor/3173138-secondarysystemgroupedbackground).
///
/// Typically used for grouped content, including table views and platter-based designs.
static const CupertinoDynamicColor secondarySystemGroupedBackground = CupertinoDynamicColor(
color: Color.fromARGB(255, 255, 255, 255),
darkColor: Color.fromARGB(255, 28, 28, 30),
highContrastColor: Color.fromARGB(255, 255, 255, 255),
darkHighContrastColor: Color.fromARGB(255, 36, 36, 38),
elevatedColor: Color.fromARGB(255, 255, 255, 255),
darkElevatedColor: Color.fromARGB(255, 44, 44, 46),
highContrastElevatedColor: Color.fromARGB(255, 255, 255, 255),
darkHighContrastElevatedColor: Color.fromARGB(255, 54, 54, 56),
);
/// The color for content layered on top of secondary backgrounds of your grouped interface,
/// equivalent to [UIColor.tertiarySystemGroupedBackground](https://developer.apple.com/documentation/uikit/uicolor/3173155-tertiarysystemgroupedbackground).
///
/// Typically used for grouped content, including table views and platter-based designs.
static const CupertinoDynamicColor tertiarySystemGroupedBackground = CupertinoDynamicColor(
color: Color.fromARGB(255, 242, 242, 247),
darkColor: Color.fromARGB(255, 44, 44, 46),
highContrastColor: Color.fromARGB(255, 235, 235, 240),
darkHighContrastColor: Color.fromARGB(255, 54, 54, 56),
elevatedColor: Color.fromARGB(255, 242, 242, 247),
darkElevatedColor: Color.fromARGB(255, 58, 58, 60),
highContrastElevatedColor: Color.fromARGB(255, 235, 235, 240),
darkHighContrastElevatedColor: Color.fromARGB(255, 68, 68, 70),
);
/// 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(
color: Color.fromARGB(73, 60, 60, 67),
darkColor: Color.fromARGB(153, 84, 84, 88),
highContrastColor: Color.fromARGB(94, 60, 60, 67),
darkHighContrastColor: Color.fromARGB(173, 84, 84, 88),
elevatedColor: Color.fromARGB(73, 60, 60, 67),
darkElevatedColor: Color.fromARGB(153, 84, 84, 88),
highContrastElevatedColor: Color.fromARGB(94, 60, 60, 67),
darkHighContrastElevatedColor: Color.fromARGB(173, 84, 84, 88),
);
/// 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(
color: Color.fromARGB(255, 198, 198, 200),
darkColor: Color.fromARGB(255, 56, 56, 58),
highContrastColor: Color.fromARGB(255, 198, 198, 200),
darkHighContrastColor: Color.fromARGB(255, 56, 56, 58),
elevatedColor: Color.fromARGB(255, 198, 198, 200),
darkElevatedColor: Color.fromARGB(255, 56, 56, 58),
highContrastElevatedColor: Color.fromARGB(255, 198, 198, 200),
darkHighContrastElevatedColor: Color.fromARGB(255, 56, 56, 58),
);
/// The color for links, equivalent to
/// [UIColor.link](https://developer.apple.com/documentation/uikit/uicolor/3173132-link).
static const CupertinoDynamicColor link = CupertinoDynamicColor(
color: Color.fromARGB(255, 0, 122, 255),
darkColor: Color.fromARGB(255, 9, 132, 255),
highContrastColor: Color.fromARGB(255, 0, 122, 255),
darkHighContrastColor: Color.fromARGB(255, 9, 132, 255),
elevatedColor: Color.fromARGB(255, 0, 122, 255),
darkElevatedColor: Color.fromARGB(255, 9, 132, 255),
highContrastElevatedColor: Color.fromARGB(255, 0, 122, 255),
darkHighContrastElevatedColor: Color.fromARGB(255, 9, 132, 255),
);
}
/// A [Color] subclass that represents a family of colors, and the currect effective
/// color in the color family.
///
/// When used as a regular color, `CupertinoDynamicColor` is equivalent to the
/// effective color (i.e. [CupertinoDynamicColor.value] will come from the effective
/// color), which is determined by the [BuildContext] it is last resolved against.
/// If it has never been resolved, the light, normal contrast, base elevation variant
/// [CupertinoDynamicColor.color] will be the effective color.
// TODO(LongCatIsLooong): publicize once all Cupertino components have adopted this.
// {@tool sample}
//
// The following snippet will create a [CupertinoButton] whose background color
// is _lightModeColor_ in light mode but _darkModeColor_ in dark mode.
//
//
// ```dart
// CupertinoButton(
// child: child,
// color: CupertinoDynamicColor.withVibrancy(
// color: lightModeColor,
// darkColor: darkModeColor,
// ),
// onTap: () => null,
// )
// ```
// {@end-tool}
//
// When a Cupertino component is provided with a `CupertinoDynamicColor`, either
// directly in its constructor, or from an [InheritedWidget] it depends on (for example,
// [DefaultTextStyle]), the component will automatically resolve the color by calling
// [CupertinoDynamicColor.resolve], using their own [BuildContext].
//
// When used outside of a Cupertino component, such color resolution will not happen
// automatically. It's essential to call [CupertinoDynamicColor.resolve] with the
// correct [BuildContext] before using the color to paint, in order to get the
// desired effect.
///
/// See also:
///
/// * [CupertinoUserInterfaceLevel], an [InheritedWidget] that may affect color
/// resolution of a `CupertinoDynamicColor`.
/// * https://developer.apple.com/documentation/uikit/uicolor/3238042-resolvedcolor.
@immutable
class CupertinoDynamicColor extends Color {
/// 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({
@required Color color,
@required Color darkColor,
@required Color highContrastColor,
@required Color darkHighContrastColor,
@required Color elevatedColor,
@required Color darkElevatedColor,
@required Color highContrastElevatedColor,
@required Color darkHighContrastElevatedColor,
}) : this._(
color,
color,
darkColor,
highContrastColor,
darkHighContrastColor,
elevatedColor,
darkElevatedColor,
highContrastElevatedColor,
darkHighContrastElevatedColor,
);
/// Creates an adaptive [Color] that changes its effective color based on the
/// given [BuildContext]'s brightness (from [MediaQueryData.platformBrightness]
/// or [CupertinoThemeData.brightness]) and accessibility contrast setting
/// ([MediaQueryData.highContrast]). The default effective color is [color].
///
/// All the colors must not be null.
const CupertinoDynamicColor.withBrightnessAndContrast({
@required Color color,
@required Color darkColor,
@required Color highContrastColor,
@required Color darkHighContrastColor,
}) : this(
color: color,
darkColor: darkColor,
highContrastColor: highContrastColor,
darkHighContrastColor: darkHighContrastColor,
elevatedColor: color,
darkElevatedColor: darkColor,
highContrastElevatedColor: highContrastColor,
darkHighContrastElevatedColor: darkHighContrastColor,
);
/// Creates an adaptive [Color] that changes its effective color based on the given
/// [BuildContext]'s brightness (from [MediaQueryData.platformBrightness] or
/// [CupertinoThemeData.brightness]). The default effective color is [color].
///
/// All the colors must not be null.
const CupertinoDynamicColor.withBrightness({
@required Color color,
@required Color darkColor,
}) : this(
color: color,
darkColor: darkColor,
highContrastColor: color,
darkHighContrastColor: darkColor,
elevatedColor: color,
darkElevatedColor: darkColor,
highContrastElevatedColor: color,
darkHighContrastElevatedColor: darkColor,
);
const CupertinoDynamicColor._(
this._effectiveColor,
this.color,
this.darkColor,
this.highContrastColor,
this.darkHighContrastColor,
this.elevatedColor,
this.darkElevatedColor,
this.highContrastElevatedColor,
this.darkHighContrastElevatedColor,
) : assert(color != null),
assert(darkColor != null),
assert(highContrastColor != null),
assert(darkHighContrastColor != null),
assert(elevatedColor != null),
assert(darkElevatedColor != null),
assert(highContrastElevatedColor != null),
assert(darkHighContrastElevatedColor != null),
assert(_effectiveColor != null),
// The super constructor has to be called with a dummy value in order to mark
// this constructor const.
// The field `value` is overriden in the class implementation.
super(0);
final Color _effectiveColor;
@override
int get value => _effectiveColor.value;
/// The color to use when the [BuildContext] implies a combination of light mode,
/// normal contrast, and base interface elevation.
///
/// In other words, this color will be the effective color of the `CupertinoDynamicColor`
/// after it is resolved against a [BuildContext] that:
/// - has a [CupertinoTheme] whose [brightness] is [PlatformBrightness.light],
/// or a [MediaQuery] whose [MediaQueryData.platformBrightness] is [PlatformBrightness.light].
/// - has a [MediaQuery] whose [MediaQueryData.highContrast] is `false`.
/// - has a [CupertinoUserInterfaceLevel] that indicates [CupertinoUserInterfaceLevelData.base].
final Color color;
/// The color to use when the [BuildContext] implies a combination of dark mode,
/// normal contrast, and base interface elevation.
///
/// In other words, this color will be the effective color of the `CupertinoDynamicColor`
/// after it is resolved against a [BuildContext] that:
/// - has a [CupertinoTheme] whose [brightness] is [PlatformBrightness.dark],
/// or a [MediaQuery] whose [MediaQueryData.platformBrightness] is [PlatformBrightness.dark].
/// - has a [MediaQuery] whose [MediaQueryData.highContrast] is `false`.
/// - has a [CupertinoUserInterfaceLevel] that indicates [CupertinoUserInterfaceLevelData.base].
final Color darkColor;
/// The color to use when the [BuildContext] implies a combination of light mode,
/// high contrast, and base interface elevation.
///
/// In other words, this color will be the effective color of the `CupertinoDynamicColor`
/// after it is resolved against a [BuildContext] that:
/// - has a [CupertinoTheme] whose [brightness] is [PlatformBrightness.light],
/// or a [MediaQuery] whose [MediaQueryData.platformBrightness] is [PlatformBrightness.light].
/// - has a [MediaQuery] whose [MediaQueryData.highContrast] is `true`.
/// - has a [CupertinoUserInterfaceLevel] that indicates [CupertinoUserInterfaceLevelData.base].
final Color highContrastColor;
/// The color to use when the [BuildContext] implies a combination of dark mode,
/// high contrast, and base interface elevation.
///
/// In other words, this color will be the effective color of the `CupertinoDynamicColor`
/// after it is resolved against a [BuildContext] that:
/// - has a [CupertinoTheme] whose [brightness] is [PlatformBrightness.dark],
/// or a [MediaQuery] whose [MediaQueryData.platformBrightness] is [PlatformBrightness.dark].
/// - has a [MediaQuery] whose [MediaQueryData.highContrast] is `true`.
/// - has a [CupertinoUserInterfaceLevel] that indicates [CupertinoUserInterfaceLevelData.base].
final Color darkHighContrastColor;
/// The color to use when the [BuildContext] implies a combination of light mode,
/// normal contrast, and elevated interface elevation.
///
/// In other words, this color will be the effective color of the `CupertinoDynamicColor`
/// after it is resolved against a [BuildContext] that:
/// - has a [CupertinoTheme] whose [brightness] is [PlatformBrightness.light],
/// or a [MediaQuery] whose [MediaQueryData.platformBrightness] is [PlatformBrightness.light].
/// - has a [MediaQuery] whose [MediaQueryData.highContrast] is `false`.
/// - has a [CupertinoUserInterfaceLevel] that indicates [CupertinoUserInterfaceLevelData.elevated].
final Color elevatedColor;
/// The color to use when the [BuildContext] implies a combination of dark mode,
/// normal contrast, and elevated interface elevation.
///
/// In other words, this color will be the effective color of the `CupertinoDynamicColor`
/// after it is resolved against a [BuildContext] that:
/// - has a [CupertinoTheme] whose [brightness] is [PlatformBrightness.dark],
/// or a [MediaQuery] whose [MediaQueryData.platformBrightness] is [PlatformBrightness.dark].
/// - has a [MediaQuery] whose [MediaQueryData.highContrast] is `false`.
/// - has a [CupertinoUserInterfaceLevel] that indicates [CupertinoUserInterfaceLevelData.elevated].
final Color darkElevatedColor;
/// The color to use when the [BuildContext] implies a combination of light mode,
/// high contrast, and elevated interface elevation.
///
/// In other words, this color will be the effective color of the `CupertinoDynamicColor`
/// after it is resolved against a [BuildContext] that:
/// - has a [CupertinoTheme] whose [brightness] is [PlatformBrightness.light],
/// or a [MediaQuery] whose [MediaQueryData.platformBrightness] is [PlatformBrightness.light].
/// - has a [MediaQuery] whose [MediaQueryData.highContrast] is `true`.
/// - has a [CupertinoUserInterfaceLevel] that indicates [CupertinoUserInterfaceLevelData.elevated].
final Color highContrastElevatedColor;
/// The color to use when the [BuildContext] implies a combination of dark mode,
/// high contrast, and elevated interface elevation.
///
/// In other words, this color will be the effective color of the `CupertinoDynamicColor`
/// after it is resolved against a [BuildContext] that:
/// - has a [CupertinoTheme] whose [brightness] is [PlatformBrightness.dark],
/// or a [MediaQuery] whose [MediaQueryData.platformBrightness] is [PlatformBrightness.dark].
/// - has a [MediaQuery] whose [MediaQueryData.highContrast] is `true`.
/// - has a [CupertinoUserInterfaceLevel] that indicates [CupertinoUserInterfaceLevelData.elevated].
final Color darkHighContrastElevatedColor;
/// Resolves the given [Color] by calling [resolveFrom].
///
/// If the given color is already a concrete [Color], it will be returned as is.
/// If the given color is null, returns null.
/// If the given color is a [CupertinoDynamicColor], but the given [BuildContext]
/// lacks the dependencies required to the color resolution, the default trait
/// value will be used ([Brightness.light] platform brightness, normal contrast,
/// [CupertinoUserInterfaceLevelData.base] elevation level), unless [nullOk] is
/// set to false, in which case an exception will be thrown.
......@@ -432,303 +870,13 @@ class CupertinoDynamicColor extends Color {
return CupertinoDynamicColor._(
resolved,
color,
darkColor,
highContrastColor,
darkHighContrastColor,
elevatedColor,
darkElevatedColor,
highContrastElevatedColor,
darkHighContrastElevatedColor,
);
}
@override
bool operator ==(dynamic other) {
if (identical(this, other))
return true;
return other.runtimeType == runtimeType
&& value == other.value
&& color == other.color
&& darkColor == other.darkColor
&& highContrastColor == other.highContrastColor
&& darkHighContrastColor == other.darkHighContrastColor
&& elevatedColor == other.elevatedColor
&& darkElevatedColor == other.darkElevatedColor
&& highContrastElevatedColor == other.highContrastElevatedColor
&& darkHighContrastElevatedColor == other.darkHighContrastElevatedColor;
}
@override
int get hashCode {
return hashValues(
value,
color,
darkColor,
highContrastColor,
elevatedColor,
darkElevatedColor,
darkHighContrastColor,
darkHighContrastElevatedColor,
highContrastElevatedColor,
);
}
@override
String toString() {
String toString(String name, Color color) {
final String marker = color.value == value ? '*' : '';
return '$marker$name = $color$marker';
}
final List<String> xs = <String>[toString('color', color),
if (_isPlatformBrightnessDependent) toString('darkColor', darkColor),
if (_isHighContrastDependent) toString('highContrastColor', highContrastColor),
if (_isPlatformBrightnessDependent && _isHighContrastDependent) toString('darkHighContrastColor', darkHighContrastColor),
if (_isInterfaceElevationDependent) toString('elevatedColor', elevatedColor),
if (_isPlatformBrightnessDependent && _isInterfaceElevationDependent) toString('darkElevatedColor', darkElevatedColor),
if (_isHighContrastDependent && _isInterfaceElevationDependent) toString('highContrastElevatedColor', highContrastElevatedColor),
if (_isPlatformBrightnessDependent && _isHighContrastDependent && _isInterfaceElevationDependent) toString('darkHighContrastElevatedColor', darkHighContrastElevatedColor),
];
return '$runtimeType(${xs.join(', ')})';
}
}
/// A color palette that typically matches iOS 13+ system colors.
///
/// Generally you should not create a [CupertinoSystemColorsData] yourself.
/// Use [CupertinoSystemColors.of] to get the [CupertinoSystemColorsData] from the
/// current [BuildContext] if possible, or [CupertinoSystemColors.fromSystem]
/// when the current [BuildContext] is not available (e.g., in [CupertinoApp]'s
/// constructor).
@immutable
class CupertinoSystemColorsData extends Diagnosticable {
/// Creates a color palette.
///
/// Generally you should not create your own `CupertinoSystemColorsData`.
/// Use [CupertinoSystemColors.of] to get the [CupertinoSystemColorsData] from the
/// current [BuildContext] if possible, or [CupertinoSystemColors.fromSystem]
/// when the current [BuildContext] is not available (e.g., in [CupertinoApp]'s
/// constructor).
const CupertinoSystemColorsData({
@required this.label,
@required this.secondaryLabel,
@required this.tertiaryLabel,
@required this.quaternaryLabel,
@required this.systemFill,
@required this.secondarySystemFill,
@required this.tertiarySystemFill,
@required this.quaternarySystemFill,
@required this.placeholderText,
@required this.systemBackground,
@required this.secondarySystemBackground,
@required this.tertiarySystemBackground,
@required this.systemGroupedBackground,
@required this.secondarySystemGroupedBackground,
@required this.tertiarySystemGroupedBackground,
@required this.separator,
@required this.opaqueSeparator,
@required this.link,
@required this.systemBlue,
@required this.systemGreen,
@required this.systemIndigo,
@required this.systemOrange,
@required this.systemPink,
@required this.systemPurple,
@required this.systemRed,
@required this.systemTeal,
@required this.systemYellow,
@required this.systemGray,
@required this.systemGray2,
@required this.systemGray3,
@required this.systemGray4,
@required this.systemGray5,
@required this.systemGray6,
}) : assert(label != null),
assert(secondaryLabel != null),
assert(tertiaryLabel != null),
assert(quaternaryLabel != null),
assert(systemFill != null),
assert(secondarySystemFill != null),
assert(tertiarySystemFill != null),
assert(quaternarySystemFill != null),
assert(placeholderText != null),
assert(systemBackground != null),
assert(secondarySystemBackground != null),
assert(tertiarySystemBackground != null),
assert(systemGroupedBackground != null),
assert(secondarySystemGroupedBackground != null),
assert(tertiarySystemGroupedBackground != null),
assert(separator != null),
assert(opaqueSeparator != null),
assert(link != null),
assert(systemBlue != null),
assert(systemGreen != null),
assert(systemIndigo != null),
assert(systemOrange != null),
assert(systemPink != null),
assert(systemPurple != null),
assert(systemRed != null),
assert(systemTeal != null),
assert(systemYellow != null),
assert(systemGray != null),
assert(systemGray2 != null),
assert(systemGray3 != null),
assert(systemGray4 != null),
assert(systemGray5 != null),
assert(systemGray6 != null),
super();
/// The color for text labels containing primary content.
final CupertinoDynamicColor label;
/// The color for text labels containing secondary content.
final CupertinoDynamicColor secondaryLabel;
/// The color for text labels containing tertiary content.
final CupertinoDynamicColor tertiaryLabel;
/// The color for text labels containing quaternary content.
final CupertinoDynamicColor quaternaryLabel;
/// An overlay fill color for thin and small shapes.
final CupertinoDynamicColor systemFill;
/// An overlay fill color for medium-size shapes.
final CupertinoDynamicColor secondarySystemFill;
/// An overlay fill color for large shapes.
final CupertinoDynamicColor tertiarySystemFill;
/// An overlay fill color for large areas containing complex content.
final CupertinoDynamicColor quaternarySystemFill;
/// The color for placeholder text in controls or text views.
final CupertinoDynamicColor placeholderText;
/// The color for the main background of your interface.
///
/// Typically used for designs that have a white primary background in a light environment.
final CupertinoDynamicColor systemBackground;
/// The color for content layered on top of the main background.
///
/// Typically used for designs that have a white primary background in a light environment.
final CupertinoDynamicColor secondarySystemBackground;
/// The color for content layered on top of secondary backgrounds.
///
/// Typically used for designs that have a white primary background in a light environment.
final CupertinoDynamicColor tertiarySystemBackground;
/// The color for the main background of your grouped interface.
///
/// Typically used for grouped content, including table views and platter-based designs.
final CupertinoDynamicColor systemGroupedBackground;
/// The color for content layered on top of the main background of your grouped interface.
///
/// Typically used for grouped content, including table views and platter-based designs.
final CupertinoDynamicColor secondarySystemGroupedBackground;
/// The color for content layered on top of secondary backgrounds of your grouped interface.
///
/// Typically used for grouped content, including table views and platter-based designs.
final CupertinoDynamicColor tertiarySystemGroupedBackground;
/// The color for thin borders or divider lines that allows some underlying content to be visible.
final CupertinoDynamicColor separator;
/// The color for borders or divider lines that hide any underlying content.
final CupertinoDynamicColor opaqueSeparator;
/// The color for links.
final CupertinoDynamicColor link;
/// A blue color that can adapt to the given [BuildContext].
final CupertinoDynamicColor systemBlue;
/// A green color that can adapt to the given [BuildContext].
final CupertinoDynamicColor systemGreen;
/// An indigo color that can adapt to the given [BuildContext].
final CupertinoDynamicColor systemIndigo;
/// An orange color that can adapt to the given [BuildContext].
final CupertinoDynamicColor systemOrange;
/// A pink color that can adapt to the given [BuildContext].
final CupertinoDynamicColor systemPink;
/// A purple color that can adapt to the given [BuildContext].
final CupertinoDynamicColor systemPurple;
/// A red color that can adapt to the given [BuildContext].
final CupertinoDynamicColor systemRed;
/// A teal color that can adapt to the given [BuildContext].
final CupertinoDynamicColor systemTeal;
/// A yellow color that can adapt to the given [BuildContext].
final CupertinoDynamicColor systemYellow;
/// The base gray color.
final CupertinoDynamicColor systemGray;
/// A second-level shade of grey.
final CupertinoDynamicColor systemGray2;
/// A third-level shade of grey.
final CupertinoDynamicColor systemGray3;
/// A fourth-level shade of grey.
final CupertinoDynamicColor systemGray4;
/// A fifth-level shade of grey.
final CupertinoDynamicColor systemGray5;
/// A sixth-level shade of grey.
final CupertinoDynamicColor systemGray6;
/// Resolve every color in the palette using the given [BuildContext], by calling
/// [CupertinoDynamicColor.resolve], and return a new [CupertinoSystemColorsData]
/// with all the resolved colors.
CupertinoSystemColorsData resolveColors(BuildContext context) {
return CupertinoSystemColorsData(
label: CupertinoDynamicColor.resolve(label, context),
secondaryLabel: CupertinoDynamicColor.resolve(secondaryLabel, context),
tertiaryLabel: CupertinoDynamicColor.resolve(tertiaryLabel, context),
quaternaryLabel: CupertinoDynamicColor.resolve(quaternaryLabel, context),
systemFill: CupertinoDynamicColor.resolve(systemFill, context),
secondarySystemFill: CupertinoDynamicColor.resolve(secondarySystemFill, context),
tertiarySystemFill: CupertinoDynamicColor.resolve(tertiarySystemFill, context),
quaternarySystemFill: CupertinoDynamicColor.resolve(quaternarySystemFill, context),
placeholderText: CupertinoDynamicColor.resolve(placeholderText, context),
systemBackground: CupertinoDynamicColor.resolve(systemBackground, context),
secondarySystemBackground: CupertinoDynamicColor.resolve(secondarySystemBackground, context),
tertiarySystemBackground: CupertinoDynamicColor.resolve(tertiarySystemBackground, context),
systemGroupedBackground: CupertinoDynamicColor.resolve(systemGroupedBackground, context),
secondarySystemGroupedBackground: CupertinoDynamicColor.resolve(secondarySystemGroupedBackground, context),
tertiarySystemGroupedBackground: CupertinoDynamicColor.resolve(tertiarySystemGroupedBackground, context),
separator: CupertinoDynamicColor.resolve(separator, context),
opaqueSeparator: CupertinoDynamicColor.resolve(opaqueSeparator, context),
link: CupertinoDynamicColor.resolve(link, context),
systemBlue: CupertinoDynamicColor.resolve(systemBlue, context),
systemGreen: CupertinoDynamicColor.resolve(systemGreen, context),
systemIndigo: CupertinoDynamicColor.resolve(systemIndigo, context),
systemOrange: CupertinoDynamicColor.resolve(systemOrange, context),
systemPink: CupertinoDynamicColor.resolve(systemPink, context),
systemPurple: CupertinoDynamicColor.resolve(systemPurple, context),
systemRed: CupertinoDynamicColor.resolve(systemRed, context),
systemTeal: CupertinoDynamicColor.resolve(systemTeal, context),
systemYellow: CupertinoDynamicColor.resolve(systemYellow, context),
systemGray: CupertinoDynamicColor.resolve(systemGray, context),
systemGray2: CupertinoDynamicColor.resolve(systemGray2, context),
systemGray3: CupertinoDynamicColor.resolve(systemGray3, context),
systemGray4: CupertinoDynamicColor.resolve(systemGray4, context),
systemGray5: CupertinoDynamicColor.resolve(systemGray5, context),
systemGray6: CupertinoDynamicColor.resolve(systemGray6, context),
darkColor,
highContrastColor,
darkHighContrastColor,
elevatedColor,
darkElevatedColor,
highContrastElevatedColor,
darkHighContrastElevatedColor,
);
}
......@@ -736,501 +884,51 @@ class CupertinoSystemColorsData extends Diagnosticable {
bool operator ==(dynamic other) {
if (identical(this, other))
return true;
return other.runtimeType == runtimeType
&& other.label == label
&& other.secondaryLabel == secondaryLabel
&& other.tertiaryLabel == tertiaryLabel
&& other.quaternaryLabel == quaternaryLabel
&& other.systemFill == systemFill
&& other.secondarySystemFill == secondarySystemFill
&& other.tertiarySystemFill == tertiarySystemFill
&& other.quaternarySystemFill == quaternarySystemFill
&& other.placeholderText == placeholderText
&& other.systemBackground == systemBackground
&& other.secondarySystemBackground == secondarySystemBackground
&& other.tertiarySystemBackground == tertiarySystemBackground
&& other.systemGroupedBackground == systemGroupedBackground
&& other.secondarySystemGroupedBackground == secondarySystemGroupedBackground
&& other.tertiarySystemGroupedBackground == tertiarySystemGroupedBackground
&& other.separator == separator
&& other.opaqueSeparator== opaqueSeparator
&& other.link == link
&& other.systemBlue == systemBlue
&& other.systemGreen == systemGreen
&& other.systemIndigo == systemIndigo
&& other.systemOrange == systemOrange
&& other.systemPink == systemPink
&& other.systemPurple == systemPurple
&& other.systemRed == systemRed
&& other.systemTeal == systemTeal
&& other.systemYellow == systemYellow
&& other.systemGray == systemGray
&& other.systemGray2 == systemGray2
&& other.systemGray3 == systemGray3
&& other.systemGray4 == systemGray4
&& other.systemGray5 == systemGray5
&& other.systemGray6 == systemGray6;
&& value == other.value
&& color == other.color
&& darkColor == other.darkColor
&& highContrastColor == other.highContrastColor
&& darkHighContrastColor == other.darkHighContrastColor
&& elevatedColor == other.elevatedColor
&& darkElevatedColor == other.darkElevatedColor
&& highContrastElevatedColor == other.highContrastElevatedColor
&& darkHighContrastElevatedColor == other.darkHighContrastElevatedColor;
}
@override
int get hashCode {
return hashList(
<Color>[
label,
secondaryLabel,
tertiaryLabel,
quaternaryLabel,
systemFill,
secondarySystemFill,
tertiarySystemFill,
quaternarySystemFill,
placeholderText,
systemBackground,
secondarySystemBackground,
tertiarySystemBackground,
systemGroupedBackground,
secondarySystemGroupedBackground,
tertiarySystemGroupedBackground,
separator,
opaqueSeparator,
link,
systemBlue,
systemGreen,
systemIndigo,
systemOrange,
systemPink,
systemPurple,
systemRed,
systemTeal,
systemYellow,
systemGray,
systemGray2,
systemGray3,
systemGray4,
systemGray5,
systemGray6,
]);
}
/// Creates a copy of this CupertinoSystemColorsData but with the given fields
/// replace with the new values.
CupertinoSystemColorsData copyWith({
CupertinoDynamicColor label,
CupertinoDynamicColor secondaryLabel,
CupertinoDynamicColor tertiaryLabel,
CupertinoDynamicColor quaternaryLabel,
CupertinoDynamicColor systemFill,
CupertinoDynamicColor secondarySystemFill,
CupertinoDynamicColor tertiarySystemFill,
CupertinoDynamicColor quaternarySystemFill,
CupertinoDynamicColor placeholderText,
CupertinoDynamicColor systemBackground,
CupertinoDynamicColor secondarySystemBackground,
CupertinoDynamicColor tertiarySystemBackground,
CupertinoDynamicColor systemGroupedBackground,
CupertinoDynamicColor secondarySystemGroupedBackground,
CupertinoDynamicColor tertiarySystemGroupedBackground,
CupertinoDynamicColor separator,
CupertinoDynamicColor opaqueSeparator,
CupertinoDynamicColor link,
CupertinoDynamicColor systemBlue,
CupertinoDynamicColor systemGreen,
CupertinoDynamicColor systemIndigo,
CupertinoDynamicColor systemOrange,
CupertinoDynamicColor systemPink,
CupertinoDynamicColor systemPurple,
CupertinoDynamicColor systemRed,
CupertinoDynamicColor systemTeal,
CupertinoDynamicColor systemYellow,
CupertinoDynamicColor systemGray,
CupertinoDynamicColor systemGray2,
CupertinoDynamicColor systemGray3,
CupertinoDynamicColor systemGray4,
CupertinoDynamicColor systemGray5,
CupertinoDynamicColor systemGray6,
}) {
return CupertinoSystemColorsData(
label: label ?? this.label,
secondaryLabel: secondaryLabel ?? this.secondaryLabel,
tertiaryLabel: tertiaryLabel ?? this.tertiaryLabel,
quaternaryLabel: quaternaryLabel ?? this.quaternaryLabel,
systemFill: systemFill ?? this.systemFill,
secondarySystemFill: secondarySystemFill ?? this.secondarySystemFill,
tertiarySystemFill: tertiarySystemFill ?? this.tertiarySystemFill,
quaternarySystemFill: quaternarySystemFill ?? this.quaternarySystemFill,
placeholderText: placeholderText ?? this.placeholderText,
systemBackground: systemBackground ?? this.systemBackground,
secondarySystemBackground: secondarySystemBackground ?? this.secondarySystemBackground,
tertiarySystemBackground: tertiarySystemBackground ?? this.tertiarySystemBackground,
systemGroupedBackground: systemGroupedBackground ?? this.systemGroupedBackground,
secondarySystemGroupedBackground: secondarySystemGroupedBackground ?? this.secondarySystemGroupedBackground,
tertiarySystemGroupedBackground: tertiarySystemGroupedBackground ?? this.tertiarySystemGroupedBackground,
separator: separator ?? this.separator,
opaqueSeparator: opaqueSeparator ?? this.opaqueSeparator,
link: link ?? this.link,
systemBlue: systemBlue ?? this.systemBlue,
systemGreen: systemGreen ?? this.systemGreen,
systemIndigo: systemIndigo ?? this.systemIndigo,
systemOrange: systemOrange ?? this.systemOrange,
systemPink: systemPink ?? this.systemPink,
systemPurple: systemPurple ?? this.systemPurple,
systemRed: systemRed ?? this.systemRed,
systemTeal: systemTeal ?? this.systemTeal,
systemYellow: systemYellow ?? this.systemYellow,
systemGray: systemGray ?? this.systemGray,
systemGray2: systemGray2 ?? this.systemGray2,
systemGray3: systemGray3 ?? this.systemGray3,
systemGray4: systemGray4 ?? this.systemGray4,
systemGray5: systemGray5 ?? this.systemGray5,
systemGray6: systemGray6 ?? this.systemGray6,
return hashValues(
value,
color,
darkColor,
highContrastColor,
elevatedColor,
darkElevatedColor,
darkHighContrastColor,
darkHighContrastElevatedColor,
highContrastElevatedColor,
);
}
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(ColorProperty('label', label));
properties.add(ColorProperty('secondaryLabel', secondaryLabel));
properties.add(ColorProperty('tertiaryLabel', tertiaryLabel));
properties.add(ColorProperty('quaternaryLabel', quaternaryLabel));
properties.add(ColorProperty('systemFill', systemFill));
properties.add(ColorProperty('secondarySystemFill', secondarySystemFill));
properties.add(ColorProperty('tertiarySystemFill', tertiarySystemFill));
properties.add(ColorProperty('quaternarySystemFill', quaternarySystemFill));
properties.add(ColorProperty('placeholderText', placeholderText));
properties.add(ColorProperty('systemBackground', systemBackground));
properties.add(ColorProperty('secondarySystemBackground', secondarySystemBackground));
properties.add(ColorProperty('tertiarySystemBackground', tertiarySystemBackground));
properties.add(ColorProperty('systemGroupedBackground', systemGroupedBackground));
properties.add(ColorProperty('secondarySystemGroupedBackground', secondarySystemGroupedBackground));
properties.add(ColorProperty('tertiarySystemGroupedBackground', tertiarySystemGroupedBackground));
properties.add(ColorProperty('separator', separator));
properties.add(ColorProperty('opaqueSeparator', opaqueSeparator));
properties.add(ColorProperty('link', link));
properties.add(ColorProperty('systemBlue', systemBlue));
properties.add(ColorProperty('systemGreen', systemGreen));
properties.add(ColorProperty('systemIndigo', systemIndigo));
properties.add(ColorProperty('systemOrange', systemOrange));
properties.add(ColorProperty('systemPink', systemPink));
properties.add(ColorProperty('systemPurple', systemPurple));
properties.add(ColorProperty('systemRed', systemRed));
properties.add(ColorProperty('systemTeal', systemTeal));
properties.add(ColorProperty('systemYellow', systemYellow));
properties.add(ColorProperty('systemGray', systemGray));
properties.add(ColorProperty('systemGray2', systemGray2));
properties.add(ColorProperty('systemGray3', systemGray3));
properties.add(ColorProperty('systemGray4', systemGray4));
properties.add(ColorProperty('systemGray5', systemGray5));
properties.add(ColorProperty('systemGray6', systemGray6));
}
}
/// Establishes a subtree where iOS system colors resolve to the given data.
///
/// Typically the given [CupertinoSystemColorsData] is resolved against its own
/// [BuildContext] using [CupertinoSystemColorsData.resolveColors].
class CupertinoSystemColors extends InheritedWidget {
/// Creates a widget that provides a given [CupertinoSystemColorsData] to its
/// descendants.
const CupertinoSystemColors({
Key key,
@required CupertinoSystemColorsData data,
Widget child,
}) : _data = data,
assert(data != null),
super(key: key, child: child);
final CupertinoSystemColorsData _data;
String toString() {
String toString(String name, Color color) {
final String marker = color.value == value ? '*' : '';
return '$marker$name = $color$marker';
}
@override
bool updateShouldNotify(CupertinoSystemColors oldWidget) => oldWidget._data != _data;
final List<String> xs = <String>[toString('color', color),
if (_isPlatformBrightnessDependent) toString('darkColor', darkColor),
if (_isHighContrastDependent) toString('highContrastColor', highContrastColor),
if (_isPlatformBrightnessDependent && _isHighContrastDependent) toString('darkHighContrastColor', darkHighContrastColor),
if (_isInterfaceElevationDependent) toString('elevatedColor', elevatedColor),
if (_isPlatformBrightnessDependent && _isInterfaceElevationDependent) toString('darkElevatedColor', darkElevatedColor),
if (_isHighContrastDependent && _isInterfaceElevationDependent) toString('highContrastElevatedColor', highContrastElevatedColor),
if (_isPlatformBrightnessDependent && _isHighContrastDependent && _isInterfaceElevationDependent) toString('darkHighContrastElevatedColor', darkHighContrastElevatedColor),
];
/// Retrieves the iOS system colors from the given [BuildContext].
///
/// Falls back to [fromSystem] if a [CupertinoSystemColors] widget couldn't be
/// found in the ancestry tree. When [fromSystem] returns null, setting [useFallbackValues]
/// to true will make the method return a set of default system colors extracted
/// from iOS 13 beta.
static CupertinoSystemColorsData of(BuildContext context, { bool useFallbackValues = true }) {
assert(context != null);
assert(useFallbackValues != null);
final CupertinoSystemColors widget = context.inheritFromWidgetOfExactType(CupertinoSystemColors);
return widget?._data ?? (useFallbackValues ? _kSystemColorsFallback : null);
return '$runtimeType(${xs.join(', ')})';
}
}
// Fallback System Colors, extracted from:
// https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/color/#dynamic-system-colors
// and iOS 13 beta.
const CupertinoSystemColorsData _kSystemColorsFallback = CupertinoSystemColorsData(
label: CupertinoDynamicColor(
color: Color.fromARGB(255, 0, 0, 0),
darkColor: Color.fromARGB(255, 255, 255, 255),
highContrastColor: Color.fromARGB(255, 0, 0, 0),
darkHighContrastColor: Color.fromARGB(255, 255, 255, 255),
elevatedColor: Color.fromARGB(255, 0, 0, 0),
darkElevatedColor: Color.fromARGB(255, 255, 255, 255),
highContrastElevatedColor: Color.fromARGB(255, 0, 0, 0),
darkHighContrastElevatedColor: Color.fromARGB(255, 255, 255, 255),
),
secondaryLabel: CupertinoDynamicColor(
color: Color.fromARGB(255, 0, 0, 0),
darkColor: Color.fromARGB(255, 255, 255, 255),
highContrastColor: Color.fromARGB(255, 0, 0, 0),
darkHighContrastColor: Color.fromARGB(255, 255, 255, 255),
elevatedColor: Color.fromARGB(255, 0, 0, 0),
darkElevatedColor: Color.fromARGB(255, 255, 255, 255),
highContrastElevatedColor: Color.fromARGB(255, 0, 0, 0),
darkHighContrastElevatedColor: Color.fromARGB(255, 255, 255, 255),
),
tertiaryLabel: CupertinoDynamicColor(
color: Color.fromARGB(76, 60, 60, 67),
darkColor: Color.fromARGB(76, 235, 235, 245),
highContrastColor: Color.fromARGB(96, 60, 60, 67),
darkHighContrastColor: Color.fromARGB(96, 235, 235, 245),
elevatedColor: Color.fromARGB(76, 60, 60, 67),
darkElevatedColor: Color.fromARGB(76, 235, 235, 245),
highContrastElevatedColor: Color.fromARGB(96, 60, 60, 67),
darkHighContrastElevatedColor: Color.fromARGB(96, 235, 235, 245),
),
quaternaryLabel: CupertinoDynamicColor(
color: Color.fromARGB(45, 60, 60, 67),
darkColor: Color.fromARGB(40, 235, 235, 245),
highContrastColor: Color.fromARGB(66, 60, 60, 67),
darkHighContrastColor: Color.fromARGB(61, 235, 235, 245),
elevatedColor: Color.fromARGB(45, 60, 60, 67),
darkElevatedColor: Color.fromARGB(40, 235, 235, 245),
highContrastElevatedColor: Color.fromARGB(66, 60, 60, 67),
darkHighContrastElevatedColor: Color.fromARGB(61, 235, 235, 245),
),
systemFill: CupertinoDynamicColor(
color: Color.fromARGB(51, 120, 120, 128),
darkColor: Color.fromARGB(91, 120, 120, 128),
highContrastColor: Color.fromARGB(71, 120, 120, 128),
darkHighContrastColor: Color.fromARGB(112, 120, 120, 128),
elevatedColor: Color.fromARGB(51, 120, 120, 128),
darkElevatedColor: Color.fromARGB(91, 120, 120, 128),
highContrastElevatedColor: Color.fromARGB(71, 120, 120, 128),
darkHighContrastElevatedColor: Color.fromARGB(112, 120, 120, 128),
),
secondarySystemFill: CupertinoDynamicColor(
color: Color.fromARGB(40, 120, 120, 128),
darkColor: Color.fromARGB(81, 120, 120, 128),
highContrastColor: Color.fromARGB(61, 120, 120, 128),
darkHighContrastColor: Color.fromARGB(102, 120, 120, 128),
elevatedColor: Color.fromARGB(40, 120, 120, 128),
darkElevatedColor: Color.fromARGB(81, 120, 120, 128),
highContrastElevatedColor: Color.fromARGB(61, 120, 120, 128),
darkHighContrastElevatedColor: Color.fromARGB(102, 120, 120, 128),
),
tertiarySystemFill: CupertinoDynamicColor(
color: Color.fromARGB(30, 118, 118, 128),
darkColor: Color.fromARGB(61, 118, 118, 128),
highContrastColor: Color.fromARGB(51, 118, 118, 128),
darkHighContrastColor: Color.fromARGB(81, 118, 118, 128),
elevatedColor: Color.fromARGB(30, 118, 118, 128),
darkElevatedColor: Color.fromARGB(61, 118, 118, 128),
highContrastElevatedColor: Color.fromARGB(51, 118, 118, 128),
darkHighContrastElevatedColor: Color.fromARGB(81, 118, 118, 128),
),
quaternarySystemFill: CupertinoDynamicColor(
color: Color.fromARGB(20, 116, 116, 128),
darkColor: Color.fromARGB(45, 118, 118, 128),
highContrastColor: Color.fromARGB(40, 116, 116, 128),
darkHighContrastColor: Color.fromARGB(66, 118, 118, 128),
elevatedColor: Color.fromARGB(20, 116, 116, 128),
darkElevatedColor: Color.fromARGB(45, 118, 118, 128),
highContrastElevatedColor: Color.fromARGB(40, 116, 116, 128),
darkHighContrastElevatedColor: Color.fromARGB(66, 118, 118, 128),
),
placeholderText: CupertinoDynamicColor(
color: Color.fromARGB(76, 60, 60, 67),
darkColor: Color.fromARGB(76, 235, 235, 245),
highContrastColor: Color.fromARGB(96, 60, 60, 67),
darkHighContrastColor: Color.fromARGB(96, 235, 235, 245),
elevatedColor: Color.fromARGB(76, 60, 60, 67),
darkElevatedColor: Color.fromARGB(76, 235, 235, 245),
highContrastElevatedColor: Color.fromARGB(96, 60, 60, 67),
darkHighContrastElevatedColor: Color.fromARGB(96, 235, 235, 245),
),
systemBackground: CupertinoDynamicColor(
color: Color.fromARGB(255, 255, 255, 255),
darkColor: Color.fromARGB(255, 0, 0, 0),
highContrastColor: Color.fromARGB(255, 255, 255, 255),
darkHighContrastColor: Color.fromARGB(255, 0, 0, 0),
elevatedColor: Color.fromARGB(255, 255, 255, 255),
darkElevatedColor: Color.fromARGB(255, 28, 28, 30),
highContrastElevatedColor: Color.fromARGB(255, 255, 255, 255),
darkHighContrastElevatedColor: Color.fromARGB(255, 36, 36, 38),
),
secondarySystemBackground: CupertinoDynamicColor(
color: Color.fromARGB(255, 242, 242, 247),
darkColor: Color.fromARGB(255, 28, 28, 30),
highContrastColor: Color.fromARGB(255, 235, 235, 240),
darkHighContrastColor: Color.fromARGB(255, 36, 36, 38),
elevatedColor: Color.fromARGB(255, 242, 242, 247),
darkElevatedColor: Color.fromARGB(255, 44, 44, 46),
highContrastElevatedColor: Color.fromARGB(255, 235, 235, 240),
darkHighContrastElevatedColor: Color.fromARGB(255, 54, 54, 56),
),
tertiarySystemBackground: CupertinoDynamicColor(
color: Color.fromARGB(255, 255, 255, 255),
darkColor: Color.fromARGB(255, 44, 44, 46),
highContrastColor: Color.fromARGB(255, 255, 255, 255),
darkHighContrastColor: Color.fromARGB(255, 54, 54, 56),
elevatedColor: Color.fromARGB(255, 255, 255, 255),
darkElevatedColor: Color.fromARGB(255, 58, 58, 60),
highContrastElevatedColor: Color.fromARGB(255, 255, 255, 255),
darkHighContrastElevatedColor: Color.fromARGB(255, 68, 68, 70),
),
systemGroupedBackground: CupertinoDynamicColor(
color: Color.fromARGB(255, 242, 242, 247),
darkColor: Color.fromARGB(255, 0, 0, 0),
highContrastColor: Color.fromARGB(255, 235, 235, 240),
darkHighContrastColor: Color.fromARGB(255, 0, 0, 0),
elevatedColor: Color.fromARGB(255, 242, 242, 247),
darkElevatedColor: Color.fromARGB(255, 28, 28, 30),
highContrastElevatedColor: Color.fromARGB(255, 235, 235, 240),
darkHighContrastElevatedColor: Color.fromARGB(255, 36, 36, 38),
),
secondarySystemGroupedBackground: CupertinoDynamicColor(
color: Color.fromARGB(255, 255, 255, 255),
darkColor: Color.fromARGB(255, 28, 28, 30),
highContrastColor: Color.fromARGB(255, 255, 255, 255),
darkHighContrastColor: Color.fromARGB(255, 36, 36, 38),
elevatedColor: Color.fromARGB(255, 255, 255, 255),
darkElevatedColor: Color.fromARGB(255, 44, 44, 46),
highContrastElevatedColor: Color.fromARGB(255, 255, 255, 255),
darkHighContrastElevatedColor: Color.fromARGB(255, 54, 54, 56),
),
tertiarySystemGroupedBackground: CupertinoDynamicColor(
color: Color.fromARGB(255, 242, 242, 247),
darkColor: Color.fromARGB(255, 44, 44, 46),
highContrastColor: Color.fromARGB(255, 235, 235, 240),
darkHighContrastColor: Color.fromARGB(255, 54, 54, 56),
elevatedColor: Color.fromARGB(255, 242, 242, 247),
darkElevatedColor: Color.fromARGB(255, 58, 58, 60),
highContrastElevatedColor: Color.fromARGB(255, 235, 235, 240),
darkHighContrastElevatedColor: Color.fromARGB(255, 68, 68, 70),
),
separator: CupertinoDynamicColor(
color: Color.fromARGB(73, 60, 60, 67),
darkColor: Color.fromARGB(153, 84, 84, 88),
highContrastColor: Color.fromARGB(94, 60, 60, 67),
darkHighContrastColor: Color.fromARGB(173, 84, 84, 88),
elevatedColor: Color.fromARGB(73, 60, 60, 67),
darkElevatedColor: Color.fromARGB(153, 84, 84, 88),
highContrastElevatedColor: Color.fromARGB(94, 60, 60, 67),
darkHighContrastElevatedColor: Color.fromARGB(173, 84, 84, 88),
),
opaqueSeparator: CupertinoDynamicColor(
color: Color.fromARGB(255, 198, 198, 200),
darkColor: Color.fromARGB(255, 56, 56, 58),
highContrastColor: Color.fromARGB(255, 198, 198, 200),
darkHighContrastColor: Color.fromARGB(255, 56, 56, 58),
elevatedColor: Color.fromARGB(255, 198, 198, 200),
darkElevatedColor: Color.fromARGB(255, 56, 56, 58),
highContrastElevatedColor: Color.fromARGB(255, 198, 198, 200),
darkHighContrastElevatedColor: Color.fromARGB(255, 56, 56, 58),
),
link: CupertinoDynamicColor(
color: Color.fromARGB(255, 0, 122, 255),
darkColor: Color.fromARGB(255, 9, 132, 255),
highContrastColor: Color.fromARGB(255, 0, 122, 255),
darkHighContrastColor: Color.fromARGB(255, 9, 132, 255),
elevatedColor: Color.fromARGB(255, 0, 122, 255),
darkElevatedColor: Color.fromARGB(255, 9, 132, 255),
highContrastElevatedColor: Color.fromARGB(255, 0, 122, 255),
darkHighContrastElevatedColor: Color.fromARGB(255, 9, 132, 255),
),
systemBlue: CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 0, 122, 255),
darkColor: Color.fromARGB(255, 10, 132, 255),
highContrastColor: Color.fromARGB(255, 0, 64, 221),
darkHighContrastColor: Color.fromARGB(255, 64, 156, 255),
),
systemGreen: CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 52, 199, 89),
darkColor: Color.fromARGB(255, 48, 209, 88),
highContrastColor: Color.fromARGB(255, 36, 138, 61),
darkHighContrastColor: Color.fromARGB(255, 48, 219, 91),
),
systemIndigo: CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 88, 86, 214),
darkColor: Color.fromARGB(255, 94, 92, 230),
highContrastColor: Color.fromARGB(255, 54, 52, 163),
darkHighContrastColor: Color.fromARGB(255, 125, 122, 255),
),
systemOrange: CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 255, 149, 0),
darkColor: Color.fromARGB(255, 255, 159, 10),
highContrastColor: Color.fromARGB(255, 201, 52, 0),
darkHighContrastColor: Color.fromARGB(255, 255, 179, 64),
),
systemPink: CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 255, 45, 85),
darkColor: Color.fromARGB(255, 255, 55, 95),
highContrastColor: Color.fromARGB(255, 211, 15, 69),
darkHighContrastColor: Color.fromARGB(255, 255, 100, 130),
),
systemPurple: CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 175, 82, 222),
darkColor: Color.fromARGB(255, 191, 90, 242),
highContrastColor: Color.fromARGB(255, 137, 68, 171),
darkHighContrastColor: Color.fromARGB(255, 218, 143, 255),
),
systemRed: CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 255, 59, 48),
darkColor: Color.fromARGB(255, 255, 69, 58),
highContrastColor: Color.fromARGB(255, 215, 0, 21),
darkHighContrastColor: Color.fromARGB(255, 255, 105, 97),
),
systemTeal: CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 90, 200, 250),
darkColor: Color.fromARGB(255, 100, 210, 255),
highContrastColor: Color.fromARGB(255, 0, 113, 164),
darkHighContrastColor: Color.fromARGB(255, 112, 215, 255),
),
systemYellow: CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 255, 204, 0),
darkColor: Color.fromARGB(255, 255, 214, 10),
highContrastColor: Color.fromARGB(255, 160, 90, 0),
darkHighContrastColor: Color.fromARGB(255, 255, 212, 38),
),
systemGray: CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 142, 142, 147),
darkColor: Color.fromARGB(255, 142, 142, 147),
highContrastColor: Color.fromARGB(255, 108, 108, 112),
darkHighContrastColor: Color.fromARGB(255, 174, 174, 178),
),
systemGray2: CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 174, 174, 178),
darkColor: Color.fromARGB(255, 99, 99, 102),
highContrastColor: Color.fromARGB(255, 142, 142, 147),
darkHighContrastColor: Color.fromARGB(255, 124, 124, 128),
),
systemGray3: CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 199, 199, 204),
darkColor: Color.fromARGB(255, 72, 72, 74),
highContrastColor: Color.fromARGB(255, 174, 174, 178),
darkHighContrastColor: Color.fromARGB(255, 84, 84, 86),
),
systemGray4: CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 209, 209, 214),
darkColor: Color.fromARGB(255, 58, 58, 60),
highContrastColor: Color.fromARGB(255, 188, 188, 192),
darkHighContrastColor: Color.fromARGB(255, 68, 68, 70),
),
systemGray5: CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 229, 229, 234),
darkColor: Color.fromARGB(255, 44, 44, 46),
highContrastColor: Color.fromARGB(255, 216, 216, 220),
darkHighContrastColor: Color.fromARGB(255, 54, 54, 56),
),
systemGray6: CupertinoDynamicColor.withBrightnessAndContrast(
color: Color.fromARGB(255, 242, 242, 247),
darkColor: Color.fromARGB(255, 28, 28, 30),
highContrastColor: Color.fromARGB(255, 235, 235, 240),
darkHighContrastColor: Color.fromARGB(255, 36, 36, 38),
),
);
......@@ -360,7 +360,7 @@ class _CupertinoDialogRenderWidget extends RenderObjectWidget {
return _RenderCupertinoDialog(
dividerThickness: _kDividerThickness / MediaQuery.of(context).devicePixelRatio,
isInAccessibilityMode: _isInAccessibilityMode(context),
dividerColor: CupertinoDynamicColor.resolve(CupertinoSystemColors.of(context).separator, context),
dividerColor: CupertinoDynamicColor.resolve(CupertinoColors.separator, context),
);
}
......@@ -368,7 +368,7 @@ class _CupertinoDialogRenderWidget extends RenderObjectWidget {
void updateRenderObject(BuildContext context, _RenderCupertinoDialog renderObject) {
renderObject
..isInAccessibilityMode = _isInAccessibilityMode(context)
..dividerColor = CupertinoDynamicColor.resolve(CupertinoSystemColors.of(context).separator, context);
..dividerColor = CupertinoDynamicColor.resolve(CupertinoColors.separator, context);
}
@override
......@@ -858,7 +858,7 @@ class _CupertinoAlertContentSection extends StatelessWidget {
),
child: DefaultTextStyle(
style: _kCupertinoDialogTitleStyle.copyWith(
color: CupertinoDynamicColor.resolve(CupertinoSystemColors.of(context).label, context),
color: CupertinoDynamicColor.resolve(CupertinoColors.label, context),
),
textAlign: TextAlign.center,
child: title,
......@@ -874,7 +874,7 @@ class _CupertinoAlertContentSection extends StatelessWidget {
),
child: DefaultTextStyle(
style: _kCupertinoDialogContentStyle.copyWith(
color: CupertinoDynamicColor.resolve(CupertinoSystemColors.of(context).label, context),
color: CupertinoDynamicColor.resolve(CupertinoColors.label, context),
),
textAlign: TextAlign.center,
child: content,
......@@ -1158,7 +1158,7 @@ class CupertinoDialogAction extends StatelessWidget {
Widget build(BuildContext context) {
TextStyle style = _kCupertinoDialogActionStyle.copyWith(
color: CupertinoDynamicColor.resolve(
isDestructiveAction ? CupertinoSystemColors.of(context).systemRed : CupertinoSystemColors.of(context).systemBlue,
isDestructiveAction ? CupertinoColors.systemRed : CupertinoColors.systemBlue,
context,
),
);
......@@ -1233,7 +1233,7 @@ class _CupertinoDialogActionsRenderWidget extends MultiChildRenderObjectWidget {
dividerThickness: _dividerThickness,
dialogColor: CupertinoDynamicColor.resolve(_kDialogColor, context),
dialogPressedColor: CupertinoDynamicColor.resolve(_kDialogPressedColor, context),
dividerColor: CupertinoDynamicColor.resolve(CupertinoSystemColors.of(context).separator, context),
dividerColor: CupertinoDynamicColor.resolve(CupertinoColors.separator, context),
);
}
......@@ -1246,7 +1246,7 @@ class _CupertinoDialogActionsRenderWidget extends MultiChildRenderObjectWidget {
..dividerThickness = _dividerThickness
..dialogColor = CupertinoDynamicColor.resolve(_kDialogColor, context)
..dialogPressedColor = CupertinoDynamicColor.resolve(_kDialogPressedColor, context)
..dividerColor = CupertinoDynamicColor.resolve(CupertinoSystemColors.of(context).separator, context);
..dividerColor = CupertinoDynamicColor.resolve(CupertinoColors.separator, context);
}
}
......
......@@ -268,7 +268,7 @@ class _CupertinoSliderRenderObjectWidget extends LeafRenderObjectWidget {
value: value,
divisions: divisions,
activeColor: activeColor,
trackColor: CupertinoDynamicColor.resolve(CupertinoSystemColors.of(context).systemFill, context),
trackColor: CupertinoDynamicColor.resolve(CupertinoColors.systemFill, context),
onChanged: onChanged,
onChangeStart: onChangeStart,
onChangeEnd: onChangeEnd,
......@@ -283,7 +283,7 @@ class _CupertinoSliderRenderObjectWidget extends LeafRenderObjectWidget {
..value = value
..divisions = divisions
..activeColor = activeColor
..trackColor = CupertinoDynamicColor.resolve(CupertinoSystemColors.of(context).systemFill, context)
..trackColor = CupertinoDynamicColor.resolve(CupertinoColors.systemFill, context)
..onChanged = onChanged
..onChangeStart = onChangeStart
..onChangeEnd = onChangeEnd
......
......@@ -96,7 +96,7 @@ class CupertinoSwitch extends StatefulWidget {
/// The color to use when this switch is on.
///
/// Defaults to [CupertinoSystemColorsData.systemGreen] when null and ignores
/// Defaults to [CupertinoColors.systemGreen] when null and ignores
/// the [CupertinoTheme] in accordance to native iOS behavior.
final Color activeColor;
......@@ -141,7 +141,7 @@ class _CupertinoSwitchState extends State<CupertinoSwitch> with TickerProviderSt
child: _CupertinoSwitchRenderObjectWidget(
value: widget.value,
activeColor: CupertinoDynamicColor.resolve(
widget.activeColor ?? CupertinoSystemColors.of(context).systemGreen,
widget.activeColor ?? CupertinoColors.systemGreen,
context,
),
onChanged: widget.onChanged,
......@@ -173,7 +173,7 @@ class _CupertinoSwitchRenderObjectWidget extends LeafRenderObjectWidget {
return _RenderCupertinoSwitch(
value: value,
activeColor: activeColor,
trackColor: CupertinoDynamicColor.resolve(CupertinoSystemColors.of(context).secondarySystemFill, context),
trackColor: CupertinoDynamicColor.resolve(CupertinoColors.secondarySystemFill, context),
onChanged: onChanged,
textDirection: Directionality.of(context),
vsync: vsync,
......@@ -186,7 +186,7 @@ class _CupertinoSwitchRenderObjectWidget extends LeafRenderObjectWidget {
renderObject
..value = value
..activeColor = activeColor
..trackColor = CupertinoDynamicColor.resolve(CupertinoSystemColors.of(context).secondarySystemFill, context)
..trackColor = CupertinoDynamicColor.resolve(CupertinoColors.secondarySystemFill, context)
..onChanged = onChanged
..textDirection = Directionality.of(context)
..vsync = vsync
......
......@@ -217,8 +217,8 @@ void main() {
of: find.text('Tab 2'),
matching: find.byType(RichText),
));
expect(actualActive.text.style.color, CupertinoColors.activeOrange);
expect(actualActive.text.style.color.value, CupertinoColors.activeOrange.darkColor.value);
});
testWidgets('Use active icon', (WidgetTester tester) async {
......
......@@ -327,7 +327,7 @@ void main() {
),
),
);
expect(textStyle.color, CupertinoColors.activeOrange);
expect(textStyle.color.value, CupertinoColors.activeOrange.darkColor.value);
await tester.pumpWidget(
CupertinoApp(
......@@ -348,7 +348,7 @@ void main() {
matching: find.byType(DecoratedBox),
)
).decoration;
expect(decoration.color, CupertinoColors.activeOrange);
expect(decoration.color.value, CupertinoColors.activeOrange.darkColor.value);
});
}
......
......@@ -415,76 +415,6 @@ void main() {
expect(find.byType(DependentWidget), paints..rect(color: color7));
});
group('CupertinoSystemColors widget', () {
CupertinoSystemColorsData colors;
setUp(() { colors = null; });
Widget systemColorGetter(BuildContext context) {
colors = CupertinoSystemColors.of(context);
return const Placeholder();
}
const CupertinoDynamicColor kSystemBackground = CupertinoDynamicColor(
color: Color.fromARGB(255, 255, 255, 255),
darkColor: Color.fromARGB(255, 0, 0, 0),
highContrastColor: Color.fromARGB(255, 255, 255, 255),
darkHighContrastColor: Color.fromARGB(255, 0, 0, 0),
elevatedColor: Color.fromARGB(255, 255, 255, 255),
darkElevatedColor: Color.fromARGB(255, 28, 28, 30),
highContrastElevatedColor: Color.fromARGB(255, 255, 255, 255),
darkHighContrastElevatedColor: Color.fromARGB(255, 36, 36, 38),
);
testWidgets('exists in CupertinoApp', (WidgetTester tester) async {
await tester.pumpWidget(CupertinoApp(home: Builder(builder: systemColorGetter)));
expect(colors.systemBackground, kSystemBackground);
});
testWidgets('resolves against its own BuildContext', (WidgetTester tester) async {
await tester.pumpWidget(
CupertinoApp(
theme: const CupertinoThemeData(brightness: Brightness.dark),
home: CupertinoUserInterfaceLevel(
data: CupertinoUserInterfaceLevelData.elevated,
child: Builder(
builder: (BuildContext context) {
return CupertinoSystemColors(
child: Builder(builder: systemColorGetter),
data: CupertinoSystemColors.of(context).resolveColors(context),
);
},
),
),
),
);
// In widget tests the OS colors should fallback to `fallbackValues`.
expect(colors.systemBackground, isNot(kSystemBackground));
expect(colors.systemBackground.value, kSystemBackground.darkElevatedColor.value);
colors = null;
// Changing dependencies works.
await tester.pumpWidget(
CupertinoApp(
theme: const CupertinoThemeData(brightness: Brightness.light),
home: Builder(
builder: (BuildContext context) {
return CupertinoUserInterfaceLevel(
data: CupertinoUserInterfaceLevelData.elevated,
child: CupertinoSystemColors(
child: Builder(builder: systemColorGetter),
data: CupertinoSystemColors.of(context).resolveColors(context),
),
);
},
),
),
);
expect(colors.systemBackground.value, kSystemBackground.elevatedColor.value);
});
});
testWidgets('CupertinoDynamicColor used in a CupertinoTheme', (WidgetTester tester) async {
CupertinoDynamicColor color;
await tester.pumpWidget(
......@@ -652,114 +582,4 @@ void main() {
expect(color, isNot(dynamicColor.darkHighContrastElevatedColor));
});
});
group('CupertinoSystemColors', () {
const Color dynamicColor0 = CupertinoDynamicColor.withBrightness(
color: Color(0x00000000),
darkColor: Color(0x00000000),
);
const Color dynamicColor1 = CupertinoDynamicColor.withBrightness(
color: Color(0x00000001),
darkColor: Color(0x00000000),
);
const CupertinoSystemColorsData system0 = CupertinoSystemColorsData(
label: dynamicColor0,
secondaryLabel: dynamicColor0,
tertiaryLabel: dynamicColor0,
quaternaryLabel: dynamicColor0,
systemFill: dynamicColor0,
secondarySystemFill: dynamicColor0,
tertiarySystemFill: dynamicColor0,
quaternarySystemFill: dynamicColor0,
placeholderText: dynamicColor0,
systemBackground: dynamicColor0,
secondarySystemBackground: dynamicColor0,
tertiarySystemBackground: dynamicColor0,
systemGroupedBackground: dynamicColor0,
secondarySystemGroupedBackground: dynamicColor0,
tertiarySystemGroupedBackground: dynamicColor0,
separator: dynamicColor0,
opaqueSeparator: dynamicColor0,
link: dynamicColor0,
systemBlue: dynamicColor0,
systemGreen: dynamicColor0,
systemIndigo: dynamicColor0,
systemOrange: dynamicColor0,
systemPink: dynamicColor0,
systemPurple: dynamicColor0,
systemRed: dynamicColor0,
systemTeal: dynamicColor0,
systemYellow: dynamicColor0,
systemGray: dynamicColor0,
systemGray2: dynamicColor0,
systemGray3: dynamicColor0,
systemGray4: dynamicColor0,
systemGray5: dynamicColor0,
systemGray6: dynamicColor0,
);
test('CupertinoSystemColorsData.== and CupertinoSystemColorsData.copyWith', () {
expect(system0, system0);
expect(system0, system0.copyWith());
expect(system0, system0.copyWith(link: dynamicColor0));
final CupertinoSystemColorsData withDifferentLink = system0.copyWith(link: dynamicColor1);
expect(withDifferentLink.link, dynamicColor1);
expect(system0, isNot(withDifferentLink));
});
test('CupertinoSystemColorsData.hashCode', () {
expect(system0.hashCode, system0.hashCode);
expect(system0.hashCode, system0.copyWith().hashCode);
expect(system0.hashCode, system0.copyWith(link: dynamicColor0).hashCode);
expect(system0.hashCode, isNot(system0.copyWith(link: dynamicColor1).hashCode));
});
test('CupertinoSystemColorsData.debugFillProperties', () {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
system0.debugFillProperties(builder);
expect(
builder.properties
.where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info))
.map((DiagnosticsNode node) => node.toString())
.toList(),
<String>[
'label: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'secondaryLabel: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'tertiaryLabel: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'quaternaryLabel: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'systemFill: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'secondarySystemFill: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'tertiarySystemFill: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'quaternarySystemFill: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'placeholderText: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'systemBackground: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'secondarySystemBackground: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'tertiarySystemBackground: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'systemGroupedBackground: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'secondarySystemGroupedBackground: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'tertiarySystemGroupedBackground: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'separator: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'opaqueSeparator: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'link: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'systemBlue: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'systemGreen: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'systemIndigo: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'systemOrange: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'systemPink: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'systemPurple: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'systemRed: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'systemTeal: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'systemYellow: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'systemGray: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'systemGray2: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'systemGray3: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'systemGray4: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'systemGray5: CupertinoDynamicColor(*color = Color(0x00000000)*)',
'systemGray6: CupertinoDynamicColor(*color = Color(0x00000000)*)',
],
);
});
});
}
......@@ -60,7 +60,7 @@ void main() {
final DefaultTextStyle widget = tester.widget(find.byType(DefaultTextStyle));
expect(widget.style.color.withAlpha(255), CupertinoColors.destructiveRed);
expect(widget.style.color.withAlpha(255).value, CupertinoColors.destructiveRed.value);
});
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), CupertinoColors.destructiveRed);
expect(widget.style.color.withAlpha(255).value, CupertinoColors.destructiveRed.value);
expect(widget.style.fontWeight, equals(FontWeight.w600));
});
......
......@@ -171,7 +171,7 @@ void main() {
of: find.text('Tab 2'),
matching: find.byType(RichText),
));
expect(tab2.text.style.color, CupertinoColors.destructiveRed);
expect(tab2.text.style.color.value, CupertinoColors.systemRed.darkColor.value);
});
testWidgets('Does not lose state when focusing on text input', (WidgetTester tester) async {
......
......@@ -188,18 +188,19 @@ void main() {
testWidgets('Nav bar respects themes', (WidgetTester tester) async {
count = 0x000000;
const CupertinoDynamicColor orange = CupertinoColors.activeOrange;
await tester.pumpWidget(
CupertinoApp(
theme: const CupertinoThemeData(brightness: Brightness.dark),
home: CupertinoNavigationBar(
leading: CupertinoButton(
onPressed: () { },
child: const _ExpectStyles(color: CupertinoColors.activeOrange, index: 0x000001),
child: _ExpectStyles(color: orange.darkColor, index: 0x000001),
),
middle: const _ExpectStyles(color: CupertinoColors.white, index: 0x000100),
trailing: CupertinoButton(
onPressed: () { },
child: const _ExpectStyles(color: CupertinoColors.activeOrange, index: 0x010000),
child: _ExpectStyles(color: orange.darkColor, index: 0x010000),
),
),
),
......@@ -1134,7 +1135,7 @@ class _ExpectStyles extends StatelessWidget {
@override
Widget build(BuildContext context) {
final TextStyle style = DefaultTextStyle.of(context).style;
expect(style.color, color);
expect(style.color.value, color.value);
expect(style.fontFamily, '.SF Pro Text');
expect(style.fontSize, 17.0);
expect(style.letterSpacing, -0.41);
......
......@@ -246,14 +246,14 @@ void main() {
// Move animation further a bit.
await tester.pump(const Duration(milliseconds: 200));
expect(bottomMiddle.text.style.color, const Color(0xffffa01a));
expect(bottomMiddle.text.style.color, const Color(0xffffa923));
expect(bottomMiddle.text.style.fontWeight, FontWeight.w400);
expect(bottomMiddle.text.style.fontFamily, '.SF Pro Text');
expect(bottomMiddle.text.style.letterSpacing, -0.41);
checkOpacity(tester, flying(tester, find.text('Page 1')).first, 0.0);
expect(topBackLabel.text.style.color, const Color(0xffffa01a));
expect(topBackLabel.text.style.color, const Color(0xffffa923));
expect(topBackLabel.text.style.fontWeight, FontWeight.w400);
expect(topBackLabel.text.style.fontFamily, '.SF Pro Text');
expect(topBackLabel.text.style.letterSpacing, -0.41);
......
......@@ -335,7 +335,7 @@ void main() {
IconThemeData iconTheme = IconTheme.of(tester.element(find.byIcon(const IconData(1))));
expect(textStyle.style.color, CupertinoColors.black);
expect(iconTheme.color, CupertinoColors.activeOrange);
expect(iconTheme.color.value, CupertinoColors.activeOrange.darkColor.value);
await tester.tap(find.byIcon(const IconData(1)));
await tester.pump();
......@@ -344,7 +344,7 @@ void main() {
textStyle = tester.widget(find.widgetWithText(DefaultTextStyle, 'Child 1').first);
iconTheme = IconTheme.of(tester.element(find.byIcon(const IconData(1))));
expect(textStyle.style.color, CupertinoColors.activeOrange);
expect(textStyle.style.color.value, CupertinoColors.activeOrange.darkColor.value);
expect(iconTheme.color, CupertinoColors.black);
},
);
......
......@@ -412,7 +412,7 @@ void main() {
expect(
find.byType(CupertinoSlider),
// First line it paints is blue.
paints..rrect(color: CupertinoColors.activeBlue),
paints..rrect(color: CupertinoColors.systemBlue.color),
);
await tester.pumpWidget(
......@@ -426,9 +426,11 @@ void main() {
),
),
);
const CupertinoDynamicColor orange = CupertinoColors.activeOrange;
expect(
find.byType(CupertinoSlider),
paints..rrect(color: CupertinoColors.activeOrange),
paints..rrect(color: orange.darkColor),
);
});
......@@ -447,7 +449,7 @@ void main() {
);
expect(
find.byType(CupertinoSlider),
paints..rrect(color: CupertinoColors.activeGreen),
paints..rrect(color: CupertinoColors.systemGreen.darkColor),
);
});
......
......@@ -378,7 +378,7 @@ void main() {
of: find.text('Tab 2'),
matching: find.byType(RichText),
));
expect(tab2.text.style.color, CupertinoColors.destructiveRed);
expect(tab2.text.style.color.value, CupertinoColors.systemRed.darkColor.value);
});
testWidgets('Tab contents are padded when there are view insets', (WidgetTester tester) async {
......
......@@ -2807,7 +2807,7 @@ void main() {
tester.firstState(find.byType(EditableText));
final RenderEditable renderEditable = editableTextState.renderEditable;
expect(renderEditable.cursorColor, CupertinoColors.activeBlue);
expect(renderEditable.cursorColor, CupertinoColors.activeBlue.color);
await tester.pumpWidget(
const CupertinoApp(
......@@ -2819,7 +2819,7 @@ void main() {
);
await tester.pump();
expect(renderEditable.cursorColor, CupertinoColors.activeOrange);
expect(renderEditable.cursorColor, CupertinoColors.activeOrange.darkColor);
await tester.pumpWidget(
const CupertinoApp(
......
......@@ -129,10 +129,10 @@ void main() {
));
expect(theme.brightness, Brightness.dark);
expect(theme.primaryColor, CupertinoColors.activeGreen);
expect(theme.primaryColor.value, CupertinoColors.systemGreen.darkColor.value);
// Now check calculated derivatives.
expect(theme.textTheme.actionTextStyle.color, CupertinoColors.activeGreen);
expect(theme.scaffoldBackgroundColor, CupertinoColors.black);
expect(theme.textTheme.actionTextStyle.color.value, CupertinoColors.systemGreen.darkColor.value);
expect(theme.scaffoldBackgroundColor.value, CupertinoColors.black.value);
},
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment