mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Set default Cupertino primaryContrastingColor to white (#153039)
**Fixes #152846 in accordance with iOS HIG** Previously the `_CupertinoThemeDefaults _kDefaultTheme` would set the `primaryContrastingColor` to `CupertinoColors.systemBackground`, which was white-ish in light mode, and black-ish in dark mode. That was in accordance with Apple Design Resources from 5 years ago. > Before: > <img width="594" alt="image" src="https://github.com/user-attachments/assets/63e88abb-6933-446f-a7ba-55109d0f353c"> As of now, iOS HIG suggests that the `primaryContrastingColor` (in combination with the currently default `primaryColor: CupertinoColors.systemBlue`) be white (regardless of light/dark modes, contrast, elevation, etc.) > After: > <img width="594" alt="image" src="https://github.com/user-attachments/assets/2a48f22b-a886-46dd-aada-6d157cb4ac06"> Example code: ```dart import 'package:flutter/cupertino.dart'; import 'package:flutter/widgets.dart'; void main() => runApp( CupertinoApp( theme: CupertinoThemeData( brightness: Brightness.dark, ), home: Center(child: CupertinoButton.filled( onPressed: () {}, child: Row( mainAxisSize: MainAxisSize.min, children: <Widget>[ Icon(CupertinoIcons.add), Text('Add'), ], ), ) ) ) ); ```
This commit is contained in:
parent
fb4b29d9a7
commit
dc4d64c9c2
@ -22,7 +22,7 @@ export 'package:flutter/foundation.dart' show Brightness;
|
||||
const _CupertinoThemeDefaults _kDefaultTheme = _CupertinoThemeDefaults(
|
||||
null,
|
||||
CupertinoColors.systemBlue,
|
||||
CupertinoColors.systemBackground,
|
||||
CupertinoColors.white,
|
||||
CupertinoDynamicColor.withBrightness(
|
||||
color: Color(0xF0F9F9F9),
|
||||
darkColor: Color(0xF01D1D1D),
|
||||
|
||||
@ -454,7 +454,7 @@ void main() {
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(textStyle.color, isSameColorAs(CupertinoColors.black));
|
||||
expect(textStyle.color, isSameColorAs(CupertinoColors.white));
|
||||
decoration = tester.widget<DecoratedBox>(
|
||||
find.descendant(
|
||||
of: find.byType(CupertinoButton),
|
||||
|
||||
@ -337,7 +337,7 @@ void main() {
|
||||
DefaultTextStyle textStyle = tester.widget(find.widgetWithText(DefaultTextStyle, 'Child 1').first);
|
||||
IconThemeData iconTheme = IconTheme.of(tester.element(find.byIcon(const IconData(1))));
|
||||
|
||||
expect(textStyle.style.color, isSameColorAs(CupertinoColors.black));
|
||||
expect(textStyle.style.color, isSameColorAs(CupertinoColors.white));
|
||||
expect(iconTheme.color, isSameColorAs(CupertinoColors.systemBlue.darkColor));
|
||||
|
||||
await tester.tap(find.byIcon(const IconData(1)));
|
||||
@ -348,7 +348,7 @@ void main() {
|
||||
iconTheme = IconTheme.of(tester.element(find.byIcon(const IconData(1))));
|
||||
|
||||
expect(textStyle.style.color, isSameColorAs(CupertinoColors.systemBlue.darkColor));
|
||||
expect(iconTheme.color, isSameColorAs(CupertinoColors.black));
|
||||
expect(iconTheme.color, isSameColorAs(CupertinoColors.white));
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@ -225,12 +225,16 @@ void main() {
|
||||
});
|
||||
|
||||
late Brightness currentBrightness;
|
||||
void colorMatches(Color? componentColor, CupertinoDynamicColor expectedDynamicColor) {
|
||||
switch (currentBrightness) {
|
||||
case Brightness.light:
|
||||
expect(componentColor, isSameColorAs(expectedDynamicColor.color));
|
||||
case Brightness.dark:
|
||||
expect(componentColor, isSameColorAs(expectedDynamicColor.darkColor));
|
||||
void colorMatches(Color? componentColor, Color expectedDynamicColor) {
|
||||
if (expectedDynamicColor is CupertinoDynamicColor) {
|
||||
switch (currentBrightness) {
|
||||
case Brightness.light:
|
||||
expect(componentColor, isSameColorAs(expectedDynamicColor.color));
|
||||
case Brightness.dark:
|
||||
expect(componentColor, isSameColorAs(expectedDynamicColor.darkColor));
|
||||
}
|
||||
} else {
|
||||
expect(componentColor, isSameColorAs(expectedDynamicColor));
|
||||
}
|
||||
}
|
||||
|
||||
@ -254,7 +258,7 @@ void main() {
|
||||
|
||||
final CupertinoThemeData theme = await testTheme(tester, data);
|
||||
|
||||
colorMatches(theme.primaryContrastingColor, CupertinoColors.systemBackground);
|
||||
colorMatches(theme.primaryContrastingColor, CupertinoColors.white);
|
||||
colorMatches(theme.barBackgroundColor, barBackgroundColor);
|
||||
colorMatches(theme.scaffoldBackgroundColor, CupertinoColors.systemBackground);
|
||||
colorMatches(theme.textTheme.textStyle.color, CupertinoColors.label);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user