Skip to content

Commit dc4d64c

Browse files
authored
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'), ], ), ) ) ) ); ```
1 parent fb4b29d commit dc4d64c

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

packages/flutter/lib/src/cupertino/theme.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export 'package:flutter/foundation.dart' show Brightness;
2222
const _CupertinoThemeDefaults _kDefaultTheme = _CupertinoThemeDefaults(
2323
null,
2424
CupertinoColors.systemBlue,
25-
CupertinoColors.systemBackground,
25+
CupertinoColors.white,
2626
CupertinoDynamicColor.withBrightness(
2727
color: Color(0xF0F9F9F9),
2828
darkColor: Color(0xF01D1D1D),

packages/flutter/test/cupertino/button_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ void main() {
454454
),
455455
),
456456
);
457-
expect(textStyle.color, isSameColorAs(CupertinoColors.black));
457+
expect(textStyle.color, isSameColorAs(CupertinoColors.white));
458458
decoration = tester.widget<DecoratedBox>(
459459
find.descendant(
460460
of: find.byType(CupertinoButton),

packages/flutter/test/cupertino/segmented_control_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ void main() {
337337
DefaultTextStyle textStyle = tester.widget(find.widgetWithText(DefaultTextStyle, 'Child 1').first);
338338
IconThemeData iconTheme = IconTheme.of(tester.element(find.byIcon(const IconData(1))));
339339

340-
expect(textStyle.style.color, isSameColorAs(CupertinoColors.black));
340+
expect(textStyle.style.color, isSameColorAs(CupertinoColors.white));
341341
expect(iconTheme.color, isSameColorAs(CupertinoColors.systemBlue.darkColor));
342342

343343
await tester.tap(find.byIcon(const IconData(1)));
@@ -348,7 +348,7 @@ void main() {
348348
iconTheme = IconTheme.of(tester.element(find.byIcon(const IconData(1))));
349349

350350
expect(textStyle.style.color, isSameColorAs(CupertinoColors.systemBlue.darkColor));
351-
expect(iconTheme.color, isSameColorAs(CupertinoColors.black));
351+
expect(iconTheme.color, isSameColorAs(CupertinoColors.white));
352352
},
353353
);
354354

packages/flutter/test/cupertino/theme_test.dart

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,16 @@ void main() {
225225
});
226226

227227
late Brightness currentBrightness;
228-
void colorMatches(Color? componentColor, CupertinoDynamicColor expectedDynamicColor) {
229-
switch (currentBrightness) {
230-
case Brightness.light:
231-
expect(componentColor, isSameColorAs(expectedDynamicColor.color));
232-
case Brightness.dark:
233-
expect(componentColor, isSameColorAs(expectedDynamicColor.darkColor));
228+
void colorMatches(Color? componentColor, Color expectedDynamicColor) {
229+
if (expectedDynamicColor is CupertinoDynamicColor) {
230+
switch (currentBrightness) {
231+
case Brightness.light:
232+
expect(componentColor, isSameColorAs(expectedDynamicColor.color));
233+
case Brightness.dark:
234+
expect(componentColor, isSameColorAs(expectedDynamicColor.darkColor));
235+
}
236+
} else {
237+
expect(componentColor, isSameColorAs(expectedDynamicColor));
234238
}
235239
}
236240

@@ -254,7 +258,7 @@ void main() {
254258

255259
final CupertinoThemeData theme = await testTheme(tester, data);
256260

257-
colorMatches(theme.primaryContrastingColor, CupertinoColors.systemBackground);
261+
colorMatches(theme.primaryContrastingColor, CupertinoColors.white);
258262
colorMatches(theme.barBackgroundColor, barBackgroundColor);
259263
colorMatches(theme.scaffoldBackgroundColor, CupertinoColors.systemBackground);
260264
colorMatches(theme.textTheme.textStyle.color, CupertinoColors.label);

0 commit comments

Comments
 (0)