Unverified Commit 62db22d1 authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

CupertinoDynamicColor improvements (#44317)

parent 604f1761
...@@ -165,11 +165,11 @@ class _ListItem extends StatelessWidget { ...@@ -165,11 +165,11 @@ class _ListItem extends StatelessWidget {
Container( Container(
width: 38.0, width: 38.0,
child: called child: called
? const Align( ? Align(
alignment: Alignment.topCenter, alignment: Alignment.topCenter,
child: Icon( child: Icon(
CupertinoIcons.phone_solid, CupertinoIcons.phone_solid,
color: CupertinoColors.inactiveGray, color: CupertinoColors.inactiveGray.resolveFrom(context),
size: 18.0, size: 18.0,
), ),
) )
...@@ -203,10 +203,10 @@ class _ListItem extends StatelessWidget { ...@@ -203,10 +203,10 @@ class _ListItem extends StatelessWidget {
place, place,
maxLines: 1, maxLines: 1,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: const TextStyle( style: TextStyle(
fontSize: 15.0, fontSize: 15.0,
letterSpacing: -0.24, letterSpacing: -0.24,
color: CupertinoColors.inactiveGray, color: CupertinoColors.inactiveGray.resolveFrom(context),
), ),
), ),
], ],
...@@ -214,8 +214,8 @@ class _ListItem extends StatelessWidget { ...@@ -214,8 +214,8 @@ class _ListItem extends StatelessWidget {
), ),
Text( Text(
date, date,
style: const TextStyle( style: TextStyle(
color: CupertinoColors.inactiveGray, color: CupertinoColors.inactiveGray.resolveFrom(context),
fontSize: 15.0, fontSize: 15.0,
letterSpacing: -0.41, letterSpacing: -0.41,
), ),
......
...@@ -289,7 +289,7 @@ class _CupertinoAppState extends State<CupertinoApp> { ...@@ -289,7 +289,7 @@ class _CupertinoAppState extends State<CupertinoApp> {
builder: widget.builder, builder: widget.builder,
title: widget.title, title: widget.title,
onGenerateTitle: widget.onGenerateTitle, onGenerateTitle: widget.onGenerateTitle,
textStyle: effectiveThemeData.textTheme.textStyle, textStyle: CupertinoTheme.of(context).textTheme.textStyle,
color: CupertinoDynamicColor.resolve(widget.color ?? effectiveThemeData.primaryColor, context), color: CupertinoDynamicColor.resolve(widget.color ?? effectiveThemeData.primaryColor, context),
locale: widget.locale, locale: widget.locale,
localizationsDelegates: _localizationsDelegates, localizationsDelegates: _localizationsDelegates,
......
...@@ -16,10 +16,7 @@ const Color _kDefaultTabBarBorderColor = CupertinoDynamicColor.withBrightness( ...@@ -16,10 +16,7 @@ const Color _kDefaultTabBarBorderColor = CupertinoDynamicColor.withBrightness(
color: Color(0x4C000000), color: Color(0x4C000000),
darkColor: Color(0x29000000), darkColor: Color(0x29000000),
); );
const Color _kDefaultTabBarInactiveColor = CupertinoDynamicColor.withBrightness( const Color _kDefaultTabBarInactiveColor = CupertinoColors.inactiveGray;
color: Color(0xFF999999),
darkColor: Color(0xFF757575),
);
/// An iOS-styled bottom navigation tab bar. /// An iOS-styled bottom navigation tab bar.
/// ///
......
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'colors.dart'; import 'colors.dart';
/// An [IconThemeData] subclass that automatically resolves its [color] when retrieved /// An [IconThemeData] subclass that automatically resolves its [color] when retrieved
/// using [IconTheme.of]. /// using [IconTheme.of].
class CupertinoIconThemeData extends IconThemeData { class CupertinoIconThemeData extends IconThemeData with DiagnosticableMixin {
/// Creates a [CupertinoIconThemeData]. /// Creates a [CupertinoIconThemeData].
/// ///
/// The opacity applies to both explicit and default icon colors. The value /// The opacity applies to both explicit and default icon colors. The value
...@@ -24,4 +25,21 @@ class CupertinoIconThemeData extends IconThemeData { ...@@ -24,4 +25,21 @@ class CupertinoIconThemeData extends IconThemeData {
final Color resolvedColor = CupertinoDynamicColor.resolve(color, context); final Color resolvedColor = CupertinoDynamicColor.resolve(color, context);
return resolvedColor == color ? this : copyWith(color: resolvedColor); return resolvedColor == color ? this : copyWith(color: resolvedColor);
} }
/// Creates a copy of this icon theme but with the given fields replaced with
/// the new values.
@override
CupertinoIconThemeData copyWith({ Color color, double opacity, double size }) {
return CupertinoIconThemeData(
color: color ?? this.color,
opacity: opacity ?? this.opacity,
size: size ?? this.size,
);
}
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(createCupertinoColorProperty('color', color, defaultValue: null));
}
} }
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:flutter/foundation.dart';
import '../widgets/framework.dart'; import '../widgets/framework.dart';
/// Indicates the visual level for a piece of content. Equivalent to `UIUserInterfaceLevel` /// Indicates the visual level for a piece of content. Equivalent to `UIUserInterfaceLevel`
...@@ -73,4 +75,10 @@ class CupertinoUserInterfaceLevel extends InheritedWidget { ...@@ -73,4 +75,10 @@ class CupertinoUserInterfaceLevel extends InheritedWidget {
' $context' ' $context'
); );
} }
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(EnumProperty<CupertinoUserInterfaceLevelData>('user interface level', _data));
}
} }
...@@ -573,7 +573,7 @@ class CupertinoTextField extends StatefulWidget { ...@@ -573,7 +573,7 @@ class CupertinoTextField extends StatefulWidget {
properties.add(DiagnosticsProperty<bool>('expands', expands, defaultValue: false)); properties.add(DiagnosticsProperty<bool>('expands', expands, defaultValue: false));
properties.add(IntProperty('maxLength', maxLength, defaultValue: null)); properties.add(IntProperty('maxLength', maxLength, defaultValue: null));
properties.add(FlagProperty('maxLengthEnforced', value: maxLengthEnforced, ifTrue: 'max length enforced')); properties.add(FlagProperty('maxLengthEnforced', value: maxLengthEnforced, ifTrue: 'max length enforced'));
properties.add(ColorProperty('cursorColor', cursorColor, defaultValue: null)); properties.add(createCupertinoColorProperty('cursorColor', cursorColor, defaultValue: null));
properties.add(FlagProperty('selectionEnabled', value: selectionEnabled, defaultValue: true, ifFalse: 'selection disabled')); properties.add(FlagProperty('selectionEnabled', value: selectionEnabled, defaultValue: true, ifFalse: 'selection disabled'));
properties.add(DiagnosticsProperty<ScrollController>('scrollController', scrollController, defaultValue: null)); properties.add(DiagnosticsProperty<ScrollController>('scrollController', scrollController, defaultValue: null));
properties.add(DiagnosticsProperty<ScrollPhysics>('scrollPhysics', scrollPhysics, defaultValue: null)); properties.add(DiagnosticsProperty<ScrollPhysics>('scrollPhysics', scrollPhysics, defaultValue: null));
......
...@@ -8,9 +8,9 @@ import 'package:flutter/widgets.dart'; ...@@ -8,9 +8,9 @@ import 'package:flutter/widgets.dart';
import 'colors.dart'; import 'colors.dart';
// Please update _DefaultCupertinoTextThemeData and _DefaultCupertinoTextThemeData // Please update _TextThemeDefaultsBuilder accordingly after changing the default
// accordingly after changing the default color here, as their implementation // color here, as their implementation depends on the default value of the color
// depends on the default value of the color field. // field.
// //
// Values derived from https://developer.apple.com/design/resources/. // Values derived from https://developer.apple.com/design/resources/.
const TextStyle _kDefaultTextStyle = TextStyle( const TextStyle _kDefaultTextStyle = TextStyle(
...@@ -22,9 +22,9 @@ const TextStyle _kDefaultTextStyle = TextStyle( ...@@ -22,9 +22,9 @@ const TextStyle _kDefaultTextStyle = TextStyle(
decoration: TextDecoration.none, decoration: TextDecoration.none,
); );
// Please update _DefaultCupertinoTextThemeData and _DefaultCupertinoTextThemeData // Please update _TextThemeDefaultsBuilder accordingly after changing the default
// accordingly after changing the default color here, as their implementation // color here, as their implementation depends on the default value of the color
// depends on the default value of the color field. // field.
// //
// Values derived from https://developer.apple.com/design/resources/. // Values derived from https://developer.apple.com/design/resources/.
const TextStyle _kDefaultActionTextStyle = TextStyle( const TextStyle _kDefaultActionTextStyle = TextStyle(
...@@ -36,9 +36,9 @@ const TextStyle _kDefaultActionTextStyle = TextStyle( ...@@ -36,9 +36,9 @@ const TextStyle _kDefaultActionTextStyle = TextStyle(
decoration: TextDecoration.none, decoration: TextDecoration.none,
); );
// Please update _DefaultCupertinoTextThemeData and _DefaultCupertinoTextThemeData // Please update _TextThemeDefaultsBuilder accordingly after changing the default
// accordingly after changing the default color here, as their implementation // color here, as their implementation depends on the default value of the color
// depends on the default value of the color field. // field.
// //
// Values derived from https://developer.apple.com/design/resources/. // Values derived from https://developer.apple.com/design/resources/.
const TextStyle _kDefaultTabLabelTextStyle = TextStyle( const TextStyle _kDefaultTabLabelTextStyle = TextStyle(
...@@ -49,9 +49,6 @@ const TextStyle _kDefaultTabLabelTextStyle = TextStyle( ...@@ -49,9 +49,6 @@ const TextStyle _kDefaultTabLabelTextStyle = TextStyle(
color: CupertinoColors.inactiveGray, color: CupertinoColors.inactiveGray,
); );
// Please update _DefaultCupertinoTextThemeData and _DefaultCupertinoTextThemeData
// accordingly after changing the default color here, as their implementation
// depends on the default value of the color field.
const TextStyle _kDefaultMiddleTitleTextStyle = TextStyle( const TextStyle _kDefaultMiddleTitleTextStyle = TextStyle(
inherit: false, inherit: false,
fontFamily: '.SF Pro Text', fontFamily: '.SF Pro Text',
...@@ -61,9 +58,6 @@ const TextStyle _kDefaultMiddleTitleTextStyle = TextStyle( ...@@ -61,9 +58,6 @@ const TextStyle _kDefaultMiddleTitleTextStyle = TextStyle(
color: CupertinoColors.label, color: CupertinoColors.label,
); );
// Please update _DefaultCupertinoTextThemeData and _DefaultCupertinoTextThemeData
// accordingly after changing the default color here, as their implementation
// depends on the default value of the color field.
const TextStyle _kDefaultLargeTitleTextStyle = TextStyle( const TextStyle _kDefaultLargeTitleTextStyle = TextStyle(
inherit: false, inherit: false,
fontFamily: '.SF Pro Display', fontFamily: '.SF Pro Display',
...@@ -73,9 +67,9 @@ const TextStyle _kDefaultLargeTitleTextStyle = TextStyle( ...@@ -73,9 +67,9 @@ const TextStyle _kDefaultLargeTitleTextStyle = TextStyle(
color: CupertinoColors.label, color: CupertinoColors.label,
); );
// Please update _DefaultCupertinoTextThemeData and _DefaultCupertinoTextThemeData // Please update _TextThemeDefaultsBuilder accordingly after changing the default
// accordingly after changing the default color here, as their implementation // color here, as their implementation depends on the default value of the color
// depends on the default value of the color field. // field.
// //
// Inspected on iOS 13 simulator with "Debug View Hierarchy". // Inspected on iOS 13 simulator with "Debug View Hierarchy".
// Value extracted from off-center labels. Centered labels have a font size of 25pt. // Value extracted from off-center labels. Centered labels have a font size of 25pt.
...@@ -88,9 +82,9 @@ const TextStyle _kDefaultPickerTextStyle = TextStyle( ...@@ -88,9 +82,9 @@ const TextStyle _kDefaultPickerTextStyle = TextStyle(
color: CupertinoColors.label, color: CupertinoColors.label,
); );
// Please update _DefaultCupertinoTextThemeData and _DefaultCupertinoTextThemeData // Please update _TextThemeDefaultsBuilder accordingly after changing the default
// accordingly after changing the default color here, as their implementation // color here, as their implementation depends on the default value of the color
// depends on the default value of the color field. // field.
// //
// Inspected on iOS 13 simulator with "Debug View Hierarchy". // Inspected on iOS 13 simulator with "Debug View Hierarchy".
// Value extracted from off-center labels. Centered labels have a font size of 25pt. // Value extracted from off-center labels. Centered labels have a font size of 25pt.
...@@ -135,7 +129,7 @@ class CupertinoTextThemeData extends Diagnosticable { ...@@ -135,7 +129,7 @@ class CupertinoTextThemeData extends Diagnosticable {
TextStyle pickerTextStyle, TextStyle pickerTextStyle,
TextStyle dateTimePickerTextStyle, TextStyle dateTimePickerTextStyle,
}) : this._raw( }) : this._raw(
const _DefaultCupertinoTextThemeData(), const _TextThemeDefaultsBuilder(CupertinoColors.label, CupertinoColors.inactiveGray),
primaryColor, primaryColor,
textStyle, textStyle,
actionTextStyle, actionTextStyle,
...@@ -160,7 +154,7 @@ class CupertinoTextThemeData extends Diagnosticable { ...@@ -160,7 +154,7 @@ class CupertinoTextThemeData extends Diagnosticable {
this._dateTimePickerTextStyle, this._dateTimePickerTextStyle,
) : assert((_navActionTextStyle != null && _actionTextStyle != null) || _primaryColor != null); ) : assert((_navActionTextStyle != null && _actionTextStyle != null) || _primaryColor != null);
final _DefaultCupertinoTextThemeData _defaults; final _TextThemeDefaultsBuilder _defaults;
final Color _primaryColor; final Color _primaryColor;
final TextStyle _textStyle; final TextStyle _textStyle;
...@@ -248,15 +242,30 @@ class CupertinoTextThemeData extends Diagnosticable { ...@@ -248,15 +242,30 @@ class CupertinoTextThemeData extends Diagnosticable {
dateTimePickerTextStyle ?? _dateTimePickerTextStyle, dateTimePickerTextStyle ?? _dateTimePickerTextStyle,
); );
} }
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
const CupertinoTextThemeData defaultData = CupertinoTextThemeData();
properties.add(DiagnosticsProperty<TextStyle>('textStyle', textStyle, defaultValue: defaultData.textStyle));
properties.add(DiagnosticsProperty<TextStyle>('actionTextStyle', actionTextStyle, defaultValue: defaultData.actionTextStyle));
properties.add(DiagnosticsProperty<TextStyle>('tabLabelTextStyle', tabLabelTextStyle, defaultValue: defaultData.tabLabelTextStyle));
properties.add(DiagnosticsProperty<TextStyle>('navTitleTextStyle', navTitleTextStyle, defaultValue: defaultData.navTitleTextStyle));
properties.add(DiagnosticsProperty<TextStyle>('navLargeTitleTextStyle', navLargeTitleTextStyle, defaultValue: defaultData.navLargeTitleTextStyle));
properties.add(DiagnosticsProperty<TextStyle>('navActionTextStyle', navActionTextStyle, defaultValue: defaultData.navActionTextStyle));
properties.add(DiagnosticsProperty<TextStyle>('pickerTextStyle', pickerTextStyle, defaultValue: defaultData.pickerTextStyle));
properties.add(DiagnosticsProperty<TextStyle>('dateTimePickerTextStyle', dateTimePickerTextStyle, defaultValue: defaultData.dateTimePickerTextStyle));
}
} }
@immutable @immutable
class _DefaultCupertinoTextThemeData extends Diagnosticable { class _TextThemeDefaultsBuilder {
const _DefaultCupertinoTextThemeData({ const _TextThemeDefaultsBuilder(
this.labelColor = CupertinoColors.label, this.labelColor,
this.inactiveGrayColor = CupertinoColors.inactiveGray, this.inactiveGrayColor,
}) : assert(labelColor != null), ) : assert(labelColor != null),
assert(inactiveGrayColor != null); assert(inactiveGrayColor != null);
final Color labelColor; final Color labelColor;
final Color inactiveGrayColor; final Color inactiveGrayColor;
...@@ -277,11 +286,11 @@ class _DefaultCupertinoTextThemeData extends Diagnosticable { ...@@ -277,11 +286,11 @@ class _DefaultCupertinoTextThemeData extends Diagnosticable {
TextStyle actionTextStyle({ Color primaryColor }) => _kDefaultActionTextStyle.copyWith(color: primaryColor); TextStyle actionTextStyle({ Color primaryColor }) => _kDefaultActionTextStyle.copyWith(color: primaryColor);
TextStyle navActionTextStyle({ Color primaryColor }) => actionTextStyle(primaryColor: primaryColor); TextStyle navActionTextStyle({ Color primaryColor }) => actionTextStyle(primaryColor: primaryColor);
_DefaultCupertinoTextThemeData resolveFrom(BuildContext context, bool nullOk) { _TextThemeDefaultsBuilder resolveFrom(BuildContext context, bool nullOk) {
final Color resolvedLabelColor = CupertinoDynamicColor.resolve(labelColor, context, nullOk: nullOk); final Color resolvedLabelColor = CupertinoDynamicColor.resolve(labelColor, context, nullOk: nullOk);
final Color resolvedInactiveGray = CupertinoDynamicColor.resolve(inactiveGrayColor, context, nullOk: nullOk); final Color resolvedInactiveGray = CupertinoDynamicColor.resolve(inactiveGrayColor, context, nullOk: nullOk);
return resolvedLabelColor == labelColor && resolvedInactiveGray == CupertinoColors.inactiveGray return resolvedLabelColor == labelColor && resolvedInactiveGray == CupertinoColors.inactiveGray
? this ? this
: _DefaultCupertinoTextThemeData(labelColor: resolvedLabelColor, inactiveGrayColor: resolvedInactiveGray); : _TextThemeDefaultsBuilder(resolvedLabelColor, resolvedInactiveGray);
} }
} }
...@@ -99,6 +99,12 @@ class CupertinoTheme extends StatelessWidget { ...@@ -99,6 +99,12 @@ class CupertinoTheme extends StatelessWidget {
), ),
); );
} }
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
data.debugFillProperties(properties);
}
} }
class _InheritedCupertinoTheme extends InheritedWidget { class _InheritedCupertinoTheme extends InheritedWidget {
...@@ -284,10 +290,10 @@ class CupertinoThemeData extends Diagnosticable { ...@@ -284,10 +290,10 @@ class CupertinoThemeData extends Diagnosticable {
_brightness, _brightness,
convertColor(_primaryColor), convertColor(_primaryColor),
convertColor(_primaryContrastingColor), convertColor(_primaryContrastingColor),
textTheme?.resolveFrom(context, nullOk: nullOk), _textTheme?.resolveFrom(context, nullOk: nullOk),
convertColor(_barBackgroundColor), convertColor(_barBackgroundColor),
convertColor(_scaffoldBackgroundColor), convertColor(_scaffoldBackgroundColor),
_defaults.resolveFrom(context, nullOk: nullOk), _defaults.resolveFrom(context, _textTheme == null, nullOk: nullOk),
); );
} }
...@@ -322,11 +328,11 @@ class CupertinoThemeData extends Diagnosticable { ...@@ -322,11 +328,11 @@ class CupertinoThemeData extends Diagnosticable {
super.debugFillProperties(properties); super.debugFillProperties(properties);
const CupertinoThemeData defaultData = CupertinoThemeData(); const CupertinoThemeData defaultData = CupertinoThemeData();
properties.add(EnumProperty<Brightness>('brightness', brightness, defaultValue: defaultData.brightness)); properties.add(EnumProperty<Brightness>('brightness', brightness, defaultValue: defaultData.brightness));
properties.add(ColorProperty('primaryColor', primaryColor, defaultValue: defaultData.primaryColor)); properties.add(createCupertinoColorProperty('primaryColor', primaryColor, defaultValue: defaultData.primaryColor));
properties.add(ColorProperty('primaryContrastingColor', primaryContrastingColor, defaultValue: defaultData.primaryContrastingColor)); properties.add(createCupertinoColorProperty('primaryContrastingColor', primaryContrastingColor, defaultValue: defaultData.primaryContrastingColor));
properties.add(DiagnosticsProperty<CupertinoTextThemeData>('textTheme', textTheme, defaultValue: defaultData.textTheme)); properties.add(createCupertinoColorProperty('barBackgroundColor', barBackgroundColor, defaultValue: defaultData.barBackgroundColor));
properties.add(ColorProperty('barBackgroundColor', barBackgroundColor, defaultValue: defaultData.barBackgroundColor)); properties.add(createCupertinoColorProperty('scaffoldBackgroundColor', scaffoldBackgroundColor, defaultValue: defaultData.scaffoldBackgroundColor));
properties.add(ColorProperty('scaffoldBackgroundColor', scaffoldBackgroundColor, defaultValue: defaultData.scaffoldBackgroundColor)); textTheme.debugFillProperties(properties);
} }
} }
...@@ -413,7 +419,7 @@ class _CupertinoThemeDefaults { ...@@ -413,7 +419,7 @@ class _CupertinoThemeDefaults {
final Color scaffoldBackgroundColor; final Color scaffoldBackgroundColor;
final _CupertinoTextThemeDefaults textThemeDefaults; final _CupertinoTextThemeDefaults textThemeDefaults;
_CupertinoThemeDefaults resolveFrom(BuildContext context, { @required bool nullOk }) { _CupertinoThemeDefaults resolveFrom(BuildContext context, bool resolveTextTheme, { @required bool nullOk }) {
assert(nullOk != null); assert(nullOk != null);
Color convertColor(Color color) => CupertinoDynamicColor.resolve(color, context, nullOk: nullOk); Color convertColor(Color color) => CupertinoDynamicColor.resolve(color, context, nullOk: nullOk);
...@@ -423,7 +429,7 @@ class _CupertinoThemeDefaults { ...@@ -423,7 +429,7 @@ class _CupertinoThemeDefaults {
convertColor(primaryContrastingColor), convertColor(primaryContrastingColor),
convertColor(barBackgroundColor), convertColor(barBackgroundColor),
convertColor(scaffoldBackgroundColor), convertColor(scaffoldBackgroundColor),
textThemeDefaults?.resolveFrom(context, nullOk: nullOk), resolveTextTheme ? textThemeDefaults?.resolveFrom(context, nullOk: nullOk) : textThemeDefaults,
); );
} }
} }
......
...@@ -60,7 +60,13 @@ class IconTheme extends InheritedTheme { ...@@ -60,7 +60,13 @@ class IconTheme extends InheritedTheme {
/// ``` /// ```
static IconThemeData of(BuildContext context) { static IconThemeData of(BuildContext context) {
final IconThemeData iconThemeData = _getInheritedIconThemeData(context).resolve(context); final IconThemeData iconThemeData = _getInheritedIconThemeData(context).resolve(context);
return iconThemeData.isConcrete ? iconThemeData : const IconThemeData.fallback().merge(iconThemeData); return iconThemeData.isConcrete
? iconThemeData
: iconThemeData.copyWith(
size: iconThemeData.size ?? const IconThemeData.fallback().size,
color: iconThemeData.color ?? const IconThemeData.fallback().color,
opacity: iconThemeData.opacity ?? const IconThemeData.fallback().opacity,
);
} }
static IconThemeData _getInheritedIconThemeData(BuildContext context) { static IconThemeData _getInheritedIconThemeData(BuildContext context) {
...@@ -80,6 +86,6 @@ class IconTheme extends InheritedTheme { ...@@ -80,6 +86,6 @@ class IconTheme extends InheritedTheme {
@override @override
void debugFillProperties(DiagnosticPropertiesBuilder properties) { void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties); super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<IconThemeData>('data', data, showName: false)); data.debugFillProperties(properties);
} }
} }
...@@ -132,19 +132,21 @@ void main() { ...@@ -132,19 +132,21 @@ void main() {
test('CupertinoDynamicColor.toString() works', () { test('CupertinoDynamicColor.toString() works', () {
expect( expect(
dynamicColor.toString(), dynamicColor.toString(),
'CupertinoDynamicColor(*color = Color(0xff000000)*, ' contains(
'darkColor = Color(0xff000001), ' 'CupertinoDynamicColor(*color = Color(0xff000000)*, '
'highContrastColor = Color(0xff000003), ' 'darkColor = Color(0xff000001), '
'darkHighContrastColor = Color(0xff000005), ' 'highContrastColor = Color(0xff000003), '
'elevatedColor = Color(0xff000002), ' 'darkHighContrastColor = Color(0xff000005), '
'darkElevatedColor = Color(0xff000004), ' 'elevatedColor = Color(0xff000002), '
'highContrastElevatedColor = Color(0xff000006), ' 'darkElevatedColor = Color(0xff000004), '
'darkHighContrastElevatedColor = Color(0xff000007))', 'highContrastElevatedColor = Color(0xff000006), '
'darkHighContrastElevatedColor = Color(0xff000007)',
),
); );
expect(notSoDynamicColor1.toString(), 'CupertinoDynamicColor(*color = Color(0xff000000)*)'); expect(notSoDynamicColor1.toString(), contains('CupertinoDynamicColor(*color = Color(0xff000000)*'));
expect(vibrancyDependentColor1.toString(), 'CupertinoDynamicColor(*color = Color(0xff000001)*, darkColor = Color(0xff000000))'); expect(vibrancyDependentColor1.toString(), contains('CupertinoDynamicColor(*color = Color(0xff000001)*, darkColor = Color(0xff000000)'));
expect(contrastDependentColor1.toString(), 'CupertinoDynamicColor(*color = Color(0xff000001)*, highContrastColor = Color(0xff000000))'); expect(contrastDependentColor1.toString(), contains('CupertinoDynamicColor(*color = Color(0xff000001)*, highContrastColor = Color(0xff000000)'));
expect(elevationDependentColor1.toString(), 'CupertinoDynamicColor(*color = Color(0xff000001)*, elevatedColor = Color(0xff000000))'); expect(elevationDependentColor1.toString(), contains('CupertinoDynamicColor(*color = Color(0xff000001)*, elevatedColor = Color(0xff000000)'));
expect( expect(
const CupertinoDynamicColor.withBrightnessAndContrast( const CupertinoDynamicColor.withBrightnessAndContrast(
...@@ -153,10 +155,12 @@ void main() { ...@@ -153,10 +155,12 @@ void main() {
highContrastColor: color2, highContrastColor: color2,
darkHighContrastColor: color3, darkHighContrastColor: color3,
).toString(), ).toString(),
'CupertinoDynamicColor(*color = Color(0xff000000)*, ' contains(
'darkColor = Color(0xff000001), ' 'CupertinoDynamicColor(*color = Color(0xff000000)*, '
'highContrastColor = Color(0xff000002), ' 'darkColor = Color(0xff000001), '
'darkHighContrastColor = Color(0xff000003))', 'highContrastColor = Color(0xff000002), '
'darkHighContrastColor = Color(0xff000003)',
),
); );
}); });
......
...@@ -692,7 +692,7 @@ void main() { ...@@ -692,7 +692,7 @@ void main() {
// 2017 has 28 days in Feb so 29 is greyed out. // 2017 has 28 days in Feb so 29 is greyed out.
expect( expect(
tester.widget<Text>(find.text('29')).style.color, tester.widget<Text>(find.text('29')).style.color,
isSameColorAs(CupertinoColors.inactiveGray), isSameColorAs(CupertinoColors.inactiveGray.color),
); );
await tester.drag(find.text('2017'), const Offset(0.0, 32.0), touchSlopY: 0.0); await tester.drag(find.text('2017'), const Offset(0.0, 32.0), touchSlopY: 0.0);
...@@ -707,7 +707,7 @@ void main() { ...@@ -707,7 +707,7 @@ void main() {
// 2016 has 29 days in Feb so 29 is not greyed out. // 2016 has 29 days in Feb so 29 is not greyed out.
expect( expect(
tester.widget<Text>(find.text('29')).style.color, tester.widget<Text>(find.text('29')).style.color,
isNot(isSameColorAs(CupertinoColors.inactiveGray)), isNot(isSameColorAs(CupertinoColors.inactiveGray.color)),
); );
await tester.drag(find.text('2016'), const Offset(0.0, -32.0), touchSlopY: 0.0); await tester.drag(find.text('2016'), const Offset(0.0, -32.0), touchSlopY: 0.0);
...@@ -721,7 +721,7 @@ void main() { ...@@ -721,7 +721,7 @@ void main() {
expect( expect(
tester.widget<Text>(find.text('29')).style.color, tester.widget<Text>(find.text('29')).style.color,
isSameColorAs(CupertinoColors.inactiveGray), isSameColorAs(CupertinoColors.inactiveGray.color),
); );
}); });
......
...@@ -60,7 +60,7 @@ void main() { ...@@ -60,7 +60,7 @@ void main() {
final DefaultTextStyle widget = tester.widget(find.byType(DefaultTextStyle)); final DefaultTextStyle widget = tester.widget(find.byType(DefaultTextStyle));
expect(widget.style.color.withAlpha(255).value, CupertinoColors.destructiveRed.value); expect(widget.style.color.withAlpha(255), CupertinoColors.systemRed.color);
}); });
testWidgets('Dialog dark theme', (WidgetTester tester) async { testWidgets('Dialog dark theme', (WidgetTester tester) async {
...@@ -183,7 +183,7 @@ void main() { ...@@ -183,7 +183,7 @@ void main() {
final DefaultTextStyle widget = tester.widget(find.byType(DefaultTextStyle)); final DefaultTextStyle widget = tester.widget(find.byType(DefaultTextStyle));
expect(widget.style.color.withAlpha(255).value, CupertinoColors.destructiveRed.value); expect(widget.style.color.withAlpha(255), CupertinoColors.systemRed.color);
expect(widget.style.fontWeight, equals(FontWeight.w600)); expect(widget.style.fontWeight, equals(FontWeight.w600));
}); });
......
...@@ -173,12 +173,12 @@ void main() { ...@@ -173,12 +173,12 @@ void main() {
home: CupertinoNavigationBar( home: CupertinoNavigationBar(
leading: CupertinoButton( leading: CupertinoButton(
onPressed: () { }, onPressed: () { },
child: const _ExpectStyles(color: CupertinoColors.activeBlue, index: 0x000001), child: _ExpectStyles(color: CupertinoColors.systemBlue.color, index: 0x000001),
), ),
middle: const _ExpectStyles(color: CupertinoColors.black, index: 0x000100), middle: const _ExpectStyles(color: CupertinoColors.black, index: 0x000100),
trailing: CupertinoButton( trailing: CupertinoButton(
onPressed: () { }, onPressed: () { },
child: const _ExpectStyles(color: CupertinoColors.activeBlue, index: 0x010000), child: _ExpectStyles(color: CupertinoColors.systemBlue.color, index: 0x010000),
), ),
), ),
), ),
......
...@@ -369,7 +369,7 @@ void main() { ...@@ -369,7 +369,7 @@ void main() {
}, },
groupValue: sharedValue, groupValue: sharedValue,
unselectedColor: CupertinoColors.lightBackgroundGray, unselectedColor: CupertinoColors.lightBackgroundGray,
selectedColor: CupertinoColors.activeGreen, selectedColor: CupertinoColors.activeGreen.color,
borderColor: CupertinoColors.black, borderColor: CupertinoColors.black,
pressedColor: const Color(0x638CFC7B), pressedColor: const Color(0x638CFC7B),
), ),
...@@ -383,8 +383,8 @@ void main() { ...@@ -383,8 +383,8 @@ void main() {
expect(getRenderSegmentedControl(tester).borderColor, CupertinoColors.black); expect(getRenderSegmentedControl(tester).borderColor, CupertinoColors.black);
expect(textStyle.style.color, CupertinoColors.lightBackgroundGray); expect(textStyle.style.color, CupertinoColors.lightBackgroundGray);
expect(iconTheme.data.color, CupertinoColors.activeGreen); expect(iconTheme.data.color, CupertinoColors.activeGreen.color);
expect(getBackgroundColor(tester, 0), CupertinoColors.activeGreen); expect(getBackgroundColor(tester, 0), CupertinoColors.activeGreen.color);
expect(getBackgroundColor(tester, 1), CupertinoColors.lightBackgroundGray); expect(getBackgroundColor(tester, 1), CupertinoColors.lightBackgroundGray);
await tester.tap(find.widgetWithIcon(IconTheme, const IconData(1))); await tester.tap(find.widgetWithIcon(IconTheme, const IconData(1)));
...@@ -393,17 +393,17 @@ void main() { ...@@ -393,17 +393,17 @@ void main() {
textStyle = tester.widget(find.widgetWithText(DefaultTextStyle, 'Child 1')); textStyle = tester.widget(find.widgetWithText(DefaultTextStyle, 'Child 1'));
iconTheme = tester.widget(find.widgetWithIcon(IconTheme, const IconData(1))); iconTheme = tester.widget(find.widgetWithIcon(IconTheme, const IconData(1)));
expect(textStyle.style.color, CupertinoColors.activeGreen); expect(textStyle.style.color, CupertinoColors.activeGreen.color);
expect(iconTheme.data.color, CupertinoColors.lightBackgroundGray); expect(iconTheme.data.color, CupertinoColors.lightBackgroundGray);
expect(getBackgroundColor(tester, 0), CupertinoColors.lightBackgroundGray); expect(getBackgroundColor(tester, 0), CupertinoColors.lightBackgroundGray);
expect(getBackgroundColor(tester, 1), CupertinoColors.activeGreen); expect(getBackgroundColor(tester, 1), CupertinoColors.activeGreen.color);
final Offset center = tester.getCenter(find.text('Child 1')); final Offset center = tester.getCenter(find.text('Child 1'));
await tester.startGesture(center); await tester.startGesture(center);
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(getBackgroundColor(tester, 0), const Color(0x638CFC7B)); expect(getBackgroundColor(tester, 0), const Color(0x638CFC7B));
expect(getBackgroundColor(tester, 1), CupertinoColors.activeGreen); expect(getBackgroundColor(tester, 1), CupertinoColors.activeGreen.color);
}); });
testWidgets('Widgets are centered within segments', (WidgetTester tester) async { testWidgets('Widgets are centered within segments', (WidgetTester tester) async {
......
...@@ -3391,7 +3391,7 @@ void main() { ...@@ -3391,7 +3391,7 @@ void main() {
children: <Widget>[ children: <Widget>[
Container( Container(
height: 100, height: 100,
color: CupertinoColors.activeOrange, color: CupertinoColors.black,
), ),
Expanded( Expanded(
child: Navigator( child: Navigator(
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
import 'dart:async'; import 'dart:async';
import 'package:collection/collection.dart' show SetEquality;
import 'package:flutter/foundation.dart';
import 'package:flutter/painting.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -56,10 +59,10 @@ void main() { ...@@ -56,10 +59,10 @@ void main() {
testWidgets('Theme attributes cascade', (WidgetTester tester) async { testWidgets('Theme attributes cascade', (WidgetTester tester) async {
final CupertinoThemeData theme = await testTheme(tester, const CupertinoThemeData( final CupertinoThemeData theme = await testTheme(tester, const CupertinoThemeData(
primaryColor: CupertinoColors.destructiveRed, primaryColor: CupertinoColors.systemRed,
)); ));
expect(theme.textTheme.actionTextStyle.color, isSameColorAs(CupertinoColors.destructiveRed)); expect(theme.textTheme.actionTextStyle.color, isSameColorAs(CupertinoColors.systemRed.color));
}); });
testWidgets('Dependent attribute can be overridden from cascaded value', (WidgetTester tester) async { testWidgets('Dependent attribute can be overridden from cascaded value', (WidgetTester tester) async {
...@@ -137,12 +140,12 @@ void main() { ...@@ -137,12 +140,12 @@ void main() {
); );
testWidgets("Theme has default IconThemeData, which is derived from the theme's primary color", (WidgetTester tester) async { testWidgets("Theme has default IconThemeData, which is derived from the theme's primary color", (WidgetTester tester) async {
const CupertinoDynamicColor primaryColor = CupertinoColors.destructiveRed; const CupertinoDynamicColor primaryColor = CupertinoColors.systemRed;
const CupertinoThemeData themeData = CupertinoThemeData(primaryColor: primaryColor); const CupertinoThemeData themeData = CupertinoThemeData(primaryColor: primaryColor);
final IconThemeData resultingIconTheme = await testIconTheme(tester, themeData); final IconThemeData resultingIconTheme = await testIconTheme(tester, themeData);
expect(resultingIconTheme.color, themeData.primaryColor); expect(resultingIconTheme.color, isSameColorAs(primaryColor));
// Works in dark mode if primaryColor is a CupertinoDynamicColor. // Works in dark mode if primaryColor is a CupertinoDynamicColor.
final Color darkColor = (await testIconTheme( final Color darkColor = (await testIconTheme(
...@@ -164,6 +167,36 @@ void main() { ...@@ -164,6 +167,36 @@ void main() {
expect(iconTheme.color, CupertinoColors.activeOrange); expect(iconTheme.color, CupertinoColors.activeOrange);
}); });
testWidgets('CupertinoTheme diagnostics', (WidgetTester tester) async {
final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder();
const CupertinoThemeData().debugFillProperties(builder);
final Set<String> description = builder.properties
.map((DiagnosticsNode node) => node.name.toString())
.toSet();
expect(
const SetEquality<String>().equals(
description,
<String>{ 'brightness',
'primaryColor',
'primaryContrastingColor',
'barBackgroundColor',
'scaffoldBackgroundColor',
'textStyle',
'actionTextStyle',
'tabLabelTextStyle',
'navTitleTextStyle',
'navLargeTitleTextStyle',
'navActionTextStyle',
'pickerTextStyle',
'dateTimePickerTextStyle'
}
),
isTrue,
);
});
Brightness currentBrightness; Brightness currentBrightness;
void colorMatches(Color componentColor, CupertinoDynamicColor expectedDynamicColor) { void colorMatches(Color componentColor, CupertinoDynamicColor expectedDynamicColor) {
switch (currentBrightness) { switch (currentBrightness) {
...@@ -181,7 +214,7 @@ void main() { ...@@ -181,7 +214,7 @@ void main() {
final CupertinoThemeData data = CupertinoThemeData(brightness: currentBrightness, primaryColor: CupertinoColors.systemRed); final CupertinoThemeData data = CupertinoThemeData(brightness: currentBrightness, primaryColor: CupertinoColors.systemRed);
final CupertinoThemeData theme = await testTheme(tester, data); final CupertinoThemeData theme = await testTheme(tester, data);
expect(data.primaryColor, isSameColorAs(CupertinoColors.systemRed.color)); expect(data.primaryColor, isSameColorAs(CupertinoColors.systemRed));
colorMatches(theme.primaryColor, CupertinoColors.systemRed); colorMatches(theme.primaryColor, CupertinoColors.systemRed);
}); });
......
...@@ -1625,7 +1625,7 @@ class _ColorMatcher extends Matcher { ...@@ -1625,7 +1625,7 @@ class _ColorMatcher extends Matcher {
@override @override
bool matches(dynamic item, Map<dynamic, dynamic> matchState) { bool matches(dynamic item, Map<dynamic, dynamic> matchState) {
if (item is Color) if (item is Color)
return item.value == targetColor.value; return item == targetColor || item.value == targetColor.value;
return false; return false;
} }
......
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