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