From e1a96b812ecb4057bd7cc171ff31f66974a2f625 Mon Sep 17 00:00:00 2001 From: Pierre-Louis <6655696+guidezpl@users.noreply.github.com> Date: Wed, 17 Nov 2021 00:03:03 +0100 Subject: [PATCH] Deprecate `primaryColorBrightness` (#93396) --- packages/flutter/lib/fix_data.yaml | 32 ++++++++++ .../flutter/lib/src/material/app_bar.dart | 2 +- .../flutter/lib/src/material/text_field.dart | 4 +- .../flutter/lib/src/material/theme_data.dart | 60 +++++++++++++------ .../test/material/circle_avatar_test.dart | 1 - .../test/material/theme_data_test.dart | 10 ++-- packages/flutter/test_fixes/material.dart | 7 +++ .../flutter/test_fixes/material.dart.expect | 7 +++ 8 files changed, 96 insertions(+), 27 deletions(-) diff --git a/packages/flutter/lib/fix_data.yaml b/packages/flutter/lib/fix_data.yaml index 9a89ba51e6..d4b9e031f6 100644 --- a/packages/flutter/lib/fix_data.yaml +++ b/packages/flutter/lib/fix_data.yaml @@ -14,6 +14,38 @@ version: 1 transforms: + # Changes made in https://github.com/flutter/flutter/pull/93396 + - title: "Remove 'primaryColorBrightness'" + date: 2021-11-11 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'primaryColorBrightness' + + # Changes made in https://github.com/flutter/flutter/pull/93396 + - title: "Remove 'primaryColorBrightness'" + date: 2021-11-11 + element: + uris: [ 'material.dart' ] + constructor: 'raw' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'primaryColorBrightness' + + # Changes made in https://github.com/flutter/flutter/pull/93396 + - title: "Remove 'primaryColorBrightness'" + date: 2021-11-11 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'ThemeData' + changes: + - kind: 'removeParameter' + name: 'primaryColorBrightness' # Changes made in https://github.com/flutter/flutter/pull/86198 - title: "Migrate to 'backgroundColor'" diff --git a/packages/flutter/lib/src/material/app_bar.dart b/packages/flutter/lib/src/material/app_bar.dart index 2248976880..086095c70b 100644 --- a/packages/flutter/lib/src/material/app_bar.dart +++ b/packages/flutter/lib/src/material/app_bar.dart @@ -1047,7 +1047,7 @@ class _AppBarState extends State { ? _systemOverlayStyleForBrightness( widget.brightness ?? appBarTheme.brightness - ?? theme.primaryColorBrightness, + ?? ThemeData.estimateBrightnessForColor(backgroundColor), ) : widget.systemOverlayStyle ?? appBarTheme.systemOverlayStyle diff --git a/packages/flutter/lib/src/material/text_field.dart b/packages/flutter/lib/src/material/text_field.dart index 333b374368..fc167cfd11 100644 --- a/packages/flutter/lib/src/material/text_field.dart +++ b/packages/flutter/lib/src/material/text_field.dart @@ -662,7 +662,7 @@ class TextField extends StatefulWidget { /// /// This setting is only honored on iOS devices. /// - /// If unset, defaults to the brightness of [ThemeData.primaryColorBrightness]. + /// If unset, defaults to [ThemeData.brightness]. final Brightness? keyboardAppearance; /// {@macro flutter.widgets.editableText.scrollPadding} @@ -1143,7 +1143,7 @@ class _TextFieldState extends State with RestorationMixin implements final ThemeData theme = Theme.of(context); final TextSelectionThemeData selectionTheme = TextSelectionTheme.of(context); final TextStyle style = theme.textTheme.subtitle1!.merge(widget.style); - final Brightness keyboardAppearance = widget.keyboardAppearance ?? theme.primaryColorBrightness; + final Brightness keyboardAppearance = widget.keyboardAppearance ?? theme.brightness; final TextEditingController controller = _effectiveController; final FocusNode focusNode = _effectiveFocusNode; final List formatters = [ diff --git a/packages/flutter/lib/src/material/theme_data.dart b/packages/flutter/lib/src/material/theme_data.dart index 873f271fed..a9a76260ad 100644 --- a/packages/flutter/lib/src/material/theme_data.dart +++ b/packages/flutter/lib/src/material/theme_data.dart @@ -239,7 +239,6 @@ class ThemeData with Diagnosticable { Brightness? brightness, MaterialColor? primarySwatch, Color? primaryColor, - Brightness? primaryColorBrightness, Color? primaryColorLight, Color? primaryColorDark, Color? focusColor, @@ -361,6 +360,11 @@ class ThemeData with Diagnosticable { 'This feature was deprecated after v2.5.0-1.0.pre.', ) bool? fixTextFieldOutlineLabel, + @Deprecated( + 'No longer used by the framework, please remove any reference to it. ' + 'This feature was deprecated after v2.6.0-11.0.pre.', + ) + Brightness? primaryColorBrightness, }) { // GENERAL CONFIGURATION applyElevationOverlayColor ??= false; @@ -390,10 +394,10 @@ class ThemeData with Diagnosticable { final bool isDark = _brightness == Brightness.dark; primarySwatch ??= Colors.blue; primaryColor ??= isDark ? Colors.grey[900]! : primarySwatch; - primaryColorBrightness ??= estimateBrightnessForColor(primaryColor); + final Brightness _primaryColorBrightness = estimateBrightnessForColor(primaryColor); primaryColorLight ??= isDark ? Colors.grey[500]! : primarySwatch[100]!; primaryColorDark ??= isDark ? Colors.black : primarySwatch[700]!; - final bool primaryIsDark = primaryColorBrightness == Brightness.dark; + final bool primaryIsDark = _primaryColorBrightness == Brightness.dark; toggleableActiveColor ??= isDark ? Colors.tealAccent[200]! : (accentColor ?? primarySwatch[600]!); accentColor ??= isDark ? Colors.tealAccent[200]! : primarySwatch[500]!; accentColorBrightness ??= estimateBrightnessForColor(accentColor); @@ -500,6 +504,7 @@ class ThemeData with Diagnosticable { accentIconTheme ??= accentIsDark ? const IconThemeData(color: Colors.white) : const IconThemeData(color: Colors.black); buttonColor ??= isDark ? primarySwatch[600]! : Colors.grey[300]!; fixTextFieldOutlineLabel ??= true; + primaryColorBrightness = _primaryColorBrightness; return ThemeData.raw( // GENERAL CONFIGURATION @@ -516,7 +521,6 @@ class ThemeData with Diagnosticable { // COLOR colorScheme: colorScheme, primaryColor: primaryColor, - primaryColorBrightness: primaryColorBrightness, primaryColorLight: primaryColorLight, primaryColorDark: primaryColorDark, focusColor: focusColor, @@ -589,6 +593,7 @@ class ThemeData with Diagnosticable { accentIconTheme: accentIconTheme, buttonColor: buttonColor, fixTextFieldOutlineLabel: fixTextFieldOutlineLabel, + primaryColorBrightness: primaryColorBrightness, ); } @@ -620,7 +625,6 @@ class ThemeData with Diagnosticable { // https://github.com/flutter/flutter/issues/91772. required this.colorScheme, required this.primaryColor, - required this.primaryColorBrightness, required this.primaryColorLight, required this.primaryColorDark, required this.focusColor, @@ -741,6 +745,11 @@ class ThemeData with Diagnosticable { 'This feature was deprecated after v2.5.0-1.0.pre.', ) required this.fixTextFieldOutlineLabel, + @Deprecated( + 'No longer used by the framework, please remove any reference to it. ' + 'This feature was deprecated after v2.6.0-11.0.pre.', + ) + required this.primaryColorBrightness, }) : // GENERAL CONFIGURATION assert(applyElevationOverlayColor != null), assert(inputDecorationTheme != null), @@ -753,7 +762,6 @@ class ThemeData with Diagnosticable { // COLOR assert(colorScheme != null), assert(primaryColor != null), - assert(primaryColorBrightness != null), assert(primaryColorLight != null), assert(primaryColorDark != null), assert(focusColor != null), @@ -825,7 +833,8 @@ class ThemeData with Diagnosticable { assert(accentTextTheme != null), assert(accentIconTheme != null), assert(buttonColor != null), - assert(fixTextFieldOutlineLabel != null); + assert(fixTextFieldOutlineLabel != null), + assert(primaryColorBrightness != null); /// Create a [ThemeData] based on the colors in the given [colorScheme] and /// text styles of the optional [textTheme]. @@ -1089,10 +1098,6 @@ class ThemeData with Diagnosticable { /// visuals in terms of the theme's [colorScheme]. final Color primaryColor; - /// The brightness of the [primaryColor]. Used to determine the color of text and - /// icons placed on top of the primary color (e.g. toolbar text). - final Brightness primaryColorBrightness; - /// A lighter version of the [primaryColor]. final Color primaryColorLight; @@ -1451,6 +1456,21 @@ class ThemeData with Diagnosticable { ) final bool fixTextFieldOutlineLabel; + /// Obsolete property that was originally used to determine the color + /// of text and icons placed on top of the primary color (e.g. toolbar text). + /// + /// The material library no longer uses this property. The [appBarTheme] can + /// be used to configure the appearance of [AppBar]s. The appearance of + /// Keyboards for [TextField]s now uses the overall theme's + /// [ThemeData.brightness] and can also be customized with + /// [TextField.keyboardAppearance]. The brightness of any color can be found + /// with [ThemeData.estimateBrightnessForColor]. + @Deprecated( + 'No longer used by the framework, please remove any reference to it. ' + 'This feature was deprecated after v2.6.0-11.0.pre.', + ) + final Brightness primaryColorBrightness; + /// Creates a copy of this theme but with the given fields replaced with the new values. /// /// The [brightness] value is applied to the [colorScheme]. @@ -1473,7 +1493,6 @@ class ThemeData with Diagnosticable { ColorScheme? colorScheme, Brightness? brightness, Color? primaryColor, - Brightness? primaryColorBrightness, Color? primaryColorLight, Color? primaryColorDark, Color? focusColor, @@ -1594,6 +1613,11 @@ class ThemeData with Diagnosticable { 'This feature was deprecated after v2.5.0-1.0.pre.', ) bool? fixTextFieldOutlineLabel, + @Deprecated( + 'No longer used by the framework, please remove any reference to it. ' + 'This feature was deprecated after v2.6.0-11.0.pre.', + ) + Brightness? primaryColorBrightness, }) { cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault(); return ThemeData.raw( @@ -1611,7 +1635,6 @@ class ThemeData with Diagnosticable { // COLOR colorScheme: (colorScheme ?? this.colorScheme).copyWith(brightness: brightness), primaryColor: primaryColor ?? this.primaryColor, - primaryColorBrightness: primaryColorBrightness ?? this.primaryColorBrightness, primaryColorLight: primaryColorLight ?? this.primaryColorLight, primaryColorDark: primaryColorDark ?? this.primaryColorDark, focusColor: focusColor ?? this.focusColor, @@ -1684,6 +1707,7 @@ class ThemeData with Diagnosticable { accentIconTheme: accentIconTheme ?? this.accentIconTheme, buttonColor: buttonColor ?? this.buttonColor, fixTextFieldOutlineLabel: fixTextFieldOutlineLabel ?? this.fixTextFieldOutlineLabel, + primaryColorBrightness: primaryColorBrightness ?? this.primaryColorBrightness, ); } @@ -1779,7 +1803,6 @@ class ThemeData with Diagnosticable { // COLOR colorScheme: ColorScheme.lerp(a.colorScheme, b.colorScheme, t), primaryColor: Color.lerp(a.primaryColor, b.primaryColor, t)!, - primaryColorBrightness: t < 0.5 ? a.primaryColorBrightness : b.primaryColorBrightness, primaryColorLight: Color.lerp(a.primaryColorLight, b.primaryColorLight, t)!, primaryColorDark: Color.lerp(a.primaryColorDark, b.primaryColorDark, t)!, focusColor: Color.lerp(a.focusColor, b.focusColor, t)!, @@ -1852,6 +1875,7 @@ class ThemeData with Diagnosticable { accentIconTheme: IconThemeData.lerp(a.accentIconTheme, b.accentIconTheme, t), buttonColor: Color.lerp(a.buttonColor, b.buttonColor, t)!, fixTextFieldOutlineLabel: t < 0.5 ? a.fixTextFieldOutlineLabel : b.fixTextFieldOutlineLabel, + primaryColorBrightness: t < 0.5 ? a.primaryColorBrightness : b.primaryColorBrightness, ); } @@ -1877,7 +1901,6 @@ class ThemeData with Diagnosticable { // COLOR other.colorScheme == colorScheme && other.primaryColor == primaryColor && - other.primaryColorBrightness == primaryColorBrightness && other.primaryColorLight == primaryColorLight && other.primaryColorDark == primaryColorDark && other.focusColor == focusColor && @@ -1949,7 +1972,8 @@ class ThemeData with Diagnosticable { other.accentTextTheme == accentTextTheme && other.accentIconTheme == accentIconTheme && other.buttonColor == buttonColor && - other.fixTextFieldOutlineLabel == fixTextFieldOutlineLabel; + other.fixTextFieldOutlineLabel == fixTextFieldOutlineLabel && + other.primaryColorBrightness == primaryColorBrightness; } @override @@ -1972,7 +1996,6 @@ class ThemeData with Diagnosticable { // COLOR colorScheme, primaryColor, - primaryColorBrightness, primaryColorLight, primaryColorDark, focusColor, @@ -2045,6 +2068,7 @@ class ThemeData with Diagnosticable { accentIconTheme, buttonColor, fixTextFieldOutlineLabel, + primaryColorBrightness, ]; return hashList(values); } @@ -2067,7 +2091,6 @@ class ThemeData with Diagnosticable { // COLORS properties.add(DiagnosticsProperty('colorScheme', colorScheme, defaultValue: defaultData.colorScheme, level: DiagnosticLevel.debug)); properties.add(ColorProperty('primaryColor', primaryColor, defaultValue: defaultData.primaryColor, level: DiagnosticLevel.debug)); - properties.add(EnumProperty('primaryColorBrightness', primaryColorBrightness, defaultValue: defaultData.primaryColorBrightness, level: DiagnosticLevel.debug)); properties.add(ColorProperty('primaryColorLight', primaryColorLight, defaultValue: defaultData.primaryColorLight, level: DiagnosticLevel.debug)); properties.add(ColorProperty('primaryColorDark', primaryColorDark, defaultValue: defaultData.primaryColorDark, level: DiagnosticLevel.debug)); properties.add(ColorProperty('focusColor', focusColor, defaultValue: defaultData.focusColor, level: DiagnosticLevel.debug)); @@ -2140,6 +2163,7 @@ class ThemeData with Diagnosticable { properties.add(DiagnosticsProperty('accentIconTheme', accentIconTheme, level: DiagnosticLevel.debug)); properties.add(ColorProperty('buttonColor', buttonColor, defaultValue: defaultData.buttonColor, level: DiagnosticLevel.debug)); properties.add(DiagnosticsProperty('fixTextFieldOutlineLabel', fixTextFieldOutlineLabel, level: DiagnosticLevel.debug)); + properties.add(EnumProperty('primaryColorBrightness', primaryColorBrightness, defaultValue: defaultData.primaryColorBrightness, level: DiagnosticLevel.debug)); } } diff --git a/packages/flutter/test/material/circle_avatar_test.dart b/packages/flutter/test/material/circle_avatar_test.dart index 19015f9f3d..cfeb97742a 100644 --- a/packages/flutter/test/material/circle_avatar_test.dart +++ b/packages/flutter/test/material/circle_avatar_test.dart @@ -5,7 +5,6 @@ // This file is run as part of a reduced test set in CI on Mac and Windows // machines. @Tags(['reduced-test-set']) - import 'dart:typed_data'; import 'package:flutter/material.dart'; diff --git a/packages/flutter/test/material/theme_data_test.dart b/packages/flutter/test/material/theme_data_test.dart index 24dcb9056c..8abfaf2a19 100644 --- a/packages/flutter/test/material/theme_data_test.dart +++ b/packages/flutter/test/material/theme_data_test.dart @@ -43,8 +43,8 @@ void main() { }); test('Default primary text theme contrasts with primary brightness', () { - final ThemeData lightTheme = ThemeData(primaryColorBrightness: Brightness.light); - final ThemeData darkTheme = ThemeData(primaryColorBrightness: Brightness.dark); + final ThemeData lightTheme = ThemeData(primaryColor: Colors.white); + final ThemeData darkTheme = ThemeData(primaryColor: Colors.black); final Typography typography = Typography.material2018(platform: lightTheme.platform); expect(lightTheme.primaryTextTheme.headline6!.color, typography.black.headline6!.color); @@ -61,8 +61,8 @@ void main() { }); test('Default primary icon theme contrasts with primary brightness', () { - final ThemeData lightTheme = ThemeData(primaryColorBrightness: Brightness.light); - final ThemeData darkTheme = ThemeData(primaryColorBrightness: Brightness.dark); + final ThemeData lightTheme = ThemeData(primaryColor: Colors.white); + final ThemeData darkTheme = ThemeData(primaryColor: Colors.black); final Typography typography = Typography.material2018(platform: lightTheme.platform); expect(lightTheme.primaryTextTheme.headline6!.color, typography.black.headline6!.color); @@ -670,7 +670,6 @@ void main() { // COLOR 'colorScheme', 'primaryColor', - 'primaryColorBrightness', 'primaryColorLight', 'primaryColorDark', 'focusColor', @@ -743,6 +742,7 @@ void main() { 'accentIconTheme', 'buttonColor', 'fixTextFieldOutlineLabel', + 'primaryColorBrightness', }; final DiagnosticPropertiesBuilder properties = DiagnosticPropertiesBuilder(); diff --git a/packages/flutter/test_fixes/material.dart b/packages/flutter/test_fixes/material.dart index 4aa084c9fa..99c875a48c 100644 --- a/packages/flutter/test_fixes/material.dart +++ b/packages/flutter/test_fixes/material.dart @@ -500,4 +500,11 @@ void main() { AppBarTheme appBarTheme = AppBarTheme(); appBarTheme.color; + + // Changes made in https://github.com/flutter/flutter/pull/93396 + ThemeData themeData = ThemeData(); + themeData = ThemeData(primaryColorBrightness: Brightness.dark); + themeData = ThemeData.raw(primaryColorBrightness: Brightness.dark); + themeData = themeData.copyWith(primaryColorBrightness: Brightness.dark); + themeData.primaryColorBrightness; // Removing field reference not supported. } diff --git a/packages/flutter/test_fixes/material.dart.expect b/packages/flutter/test_fixes/material.dart.expect index 1c1f84d4e2..07b27f135d 100644 --- a/packages/flutter/test_fixes/material.dart.expect +++ b/packages/flutter/test_fixes/material.dart.expect @@ -473,4 +473,11 @@ void main() { AppBarTheme appBarTheme = AppBarTheme(); appBarTheme.backgroundColor; + + // Changes made in https://github.com/flutter/flutter/pull/93396 + ThemeData themeData = ThemeData(); + themeData = ThemeData(); + themeData = ThemeData.raw(); + themeData = themeData.copyWith(); + themeData.primaryColorBrightness; // Removing field reference not supported. }