From dc4d64c9c288d87eac80a7857fba60ef455d452c Mon Sep 17 00:00:00 2001 From: James Kerber Date: Thu, 8 Aug 2024 01:33:23 +0200 Subject: [PATCH] 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: > image 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: > image 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: [ Icon(CupertinoIcons.add), Text('Add'), ], ), ) ) ) ); ``` --- packages/flutter/lib/src/cupertino/theme.dart | 2 +- .../flutter/test/cupertino/button_test.dart | 2 +- .../test/cupertino/segmented_control_test.dart | 4 ++-- .../flutter/test/cupertino/theme_test.dart | 18 +++++++++++------- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/flutter/lib/src/cupertino/theme.dart b/packages/flutter/lib/src/cupertino/theme.dart index 75d68d8489e..36315e297ca 100644 --- a/packages/flutter/lib/src/cupertino/theme.dart +++ b/packages/flutter/lib/src/cupertino/theme.dart @@ -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), diff --git a/packages/flutter/test/cupertino/button_test.dart b/packages/flutter/test/cupertino/button_test.dart index 44ea39aba5b..6589055a12b 100644 --- a/packages/flutter/test/cupertino/button_test.dart +++ b/packages/flutter/test/cupertino/button_test.dart @@ -454,7 +454,7 @@ void main() { ), ), ); - expect(textStyle.color, isSameColorAs(CupertinoColors.black)); + expect(textStyle.color, isSameColorAs(CupertinoColors.white)); decoration = tester.widget( find.descendant( of: find.byType(CupertinoButton), diff --git a/packages/flutter/test/cupertino/segmented_control_test.dart b/packages/flutter/test/cupertino/segmented_control_test.dart index e669b63d9ff..bcf7d1a4db1 100644 --- a/packages/flutter/test/cupertino/segmented_control_test.dart +++ b/packages/flutter/test/cupertino/segmented_control_test.dart @@ -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)); }, ); diff --git a/packages/flutter/test/cupertino/theme_test.dart b/packages/flutter/test/cupertino/theme_test.dart index 148462a9788..bc68425cad0 100644 --- a/packages/flutter/test/cupertino/theme_test.dart +++ b/packages/flutter/test/cupertino/theme_test.dart @@ -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);