From 1ed2312493ac35c17a01cf5ef8e5c9f2a0bcbf59 Mon Sep 17 00:00:00 2001 From: Eilidh Southren Date: Thu, 8 Sep 2022 12:36:07 +0100 Subject: [PATCH] Deprecate ThemeDate.bottomAppBarColor (#111080) * test commit * Deprecate BottomAppBarColor field * test commit * Deprecate BottomAppBarColor field * Update fix_data.yaml & tests * remove text.txt * Update PR ID values * Update fix_data.yaml * Make deprecation changes non-breaking * Whitespace formatting * Modify docstring, retain bottomAppBarColor default * Modify theme_data_test.dart * Update docstrings --- packages/flutter/lib/fix_data.yaml | 74 +++++++++++++++++++ .../flutter/lib/src/material/theme_data.dart | 46 ++++++++---- .../test/material/theme_data_test.dart | 10 +-- packages/flutter/test_fixes/material.dart | 6 ++ .../flutter/test_fixes/material.dart.expect | 6 ++ 5 files changed, 122 insertions(+), 20 deletions(-) diff --git a/packages/flutter/lib/fix_data.yaml b/packages/flutter/lib/fix_data.yaml index d77969bca8..d44f715815 100644 --- a/packages/flutter/lib/fix_data.yaml +++ b/packages/flutter/lib/fix_data.yaml @@ -17,6 +17,80 @@ version: 1 transforms: + # Changes made in https://github.com/flutter/flutter/pull/111080 + - title: "Migrate to 'BottomAppBarTheme.color'" + date: 2022-09-07 + element: + uris: [ 'material.dart' ] + constructor: '' + inClass: 'ThemeData' + oneOf: + - if: "bottomAppBarColor != ''" + changes: + - kind: 'removeParameter' + name: 'bottomAppBarColor' + - kind: 'addParameter' + index: 73 + name: 'bottomAppBarTheme' + style: optional_named + argumentValue: + expression: 'BottomAppBarTheme(color: {% bottomAppBarColor %})' + requiredIf: "bottomAppBarColor != ''" + variables: + bottomAppBarColor: + kind: 'fragment' + value: 'arguments[bottomAppBarColor]' + + # Changes made in https://github.com/flutter/flutter/pull/111080 + - title: "Migrate to 'BottomAppBarTheme.color'" + date: 2022-09-07 + element: + uris: [ 'material.dart' ] + constructor: 'raw' + inClass: 'ThemeData' + oneOf: + - if: "bottomAppBarColor != ''" + changes: + - kind: 'removeParameter' + name: 'bottomAppBarColor' + - kind: 'addParameter' + index: 73 + name: 'bottomAppBarTheme' + style: optional_named + argumentValue: + expression: 'BottomAppBarTheme(color: {% bottomAppBarColor %})' + requiredIf: "bottomAppBarColor != ''" + variables: + bottomAppBarColor: + kind: 'fragment' + value: 'arguments[bottomAppBarColor]' + + # Changes made in https://github.com/flutter/flutter/pull/111080 + - title: "Migrate to 'BottomAppBarTheme.color'" + date: 2022-09-06 + element: + uris: [ 'material.dart' ] + method: 'copyWith' + inClass: 'ThemeData' + oneOf: + - if: "bottomAppBarColor != ''" + changes: + - kind: 'removeParameter' + name: 'bottomAppBarColor' + - kind: 'addParameter' + index: 73 + name: 'bottomAppBarTheme' + style: optional_named + argumentValue: + expression: 'BottomAppBarTheme(color: {% bottomAppBarColor %})' + requiredIf: "bottomAppBarColor != ''" + variables: + bottomAppBarColor: + kind: 'fragment' + value: 'arguments[bottomAppBarColor]' + + + # Changes made in https://github.com/flutter/flutter/pull/110162 - title: "Migrate to 'ColorScheme.background'" date: 2022-08-24 diff --git a/packages/flutter/lib/src/material/theme_data.dart b/packages/flutter/lib/src/material/theme_data.dart index 305b8da54f..2f876bf158 100644 --- a/packages/flutter/lib/src/material/theme_data.dart +++ b/packages/flutter/lib/src/material/theme_data.dart @@ -295,7 +295,6 @@ class ThemeData with Diagnosticable { // [colorScheme] is the preferred way to configure colors. The other color // properties (as well as primaryColorBrightness, and primarySwatch) // will gradually be phased out, see https://github.com/flutter/flutter/issues/91772. - Color? bottomAppBarColor, Brightness? brightness, Color? canvasColor, Color? cardColor, @@ -432,6 +431,11 @@ class ThemeData with Diagnosticable { 'This feature was deprecated after v3.3.0-0.5.pre.', ) Color? backgroundColor, + @Deprecated( + 'Use BottomAppBarTheme.color instead. ' + 'This feature was deprecated after v3.3.0-0.6.pre.', + ) + Color? bottomAppBarColor, }) { // GENERAL CONFIGURATION cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault(); @@ -505,7 +509,6 @@ class ThemeData with Diagnosticable { shadowColor ??= Colors.black; canvasColor ??= isDark ? Colors.grey[850]! : Colors.grey[50]!; scaffoldBackgroundColor ??= canvasColor; - bottomAppBarColor ??= isDark ? Colors.grey[800]! : Colors.white; cardColor ??= isDark ? Colors.grey[800]! : Colors.white; dividerColor ??= isDark ? const Color(0x1FFFFFFF) : const Color(0x1F000000); // Create a ColorScheme that is backwards compatible as possible @@ -601,6 +604,7 @@ class ThemeData with Diagnosticable { primaryColorBrightness = estimatedPrimaryColorBrightness; errorColor ??= Colors.red[700]!; backgroundColor ??= isDark ? Colors.grey[700]! : primarySwatch[200]!; + bottomAppBarColor ??= colorSchemeSeed != null ? colorScheme.surface : isDark ? Colors.grey[800]! : Colors.white; return ThemeData.raw( // For the sanity of the reader, make sure these properties are in the same @@ -621,7 +625,6 @@ class ThemeData with Diagnosticable { useMaterial3: useMaterial3, visualDensity: visualDensity, // COLOR - bottomAppBarColor: bottomAppBarColor, canvasColor: canvasColor, cardColor: cardColor, colorScheme: colorScheme, @@ -696,6 +699,7 @@ class ThemeData with Diagnosticable { selectedRowColor: selectedRowColor, errorColor: errorColor, backgroundColor: backgroundColor, + bottomAppBarColor: bottomAppBarColor, ); } @@ -728,7 +732,6 @@ class ThemeData with Diagnosticable { // [colorScheme] is the preferred way to configure colors. The other color // properties will gradually be phased out, see // https://github.com/flutter/flutter/issues/91772. - required this.bottomAppBarColor, required this.canvasColor, required this.cardColor, required this.colorScheme, @@ -861,6 +864,12 @@ class ThemeData with Diagnosticable { 'This feature was deprecated after v3.3.0-0.5.pre.', ) Color? backgroundColor, + @Deprecated( + 'Use BottomAppBarTheme.color instead. ' + 'This feature was deprecated after v3.3.0-0.6.pre.', + ) + Color? bottomAppBarColor, + }) : // DEPRECATED (newest deprecations at the bottom) // should not be `required`, use getter pattern to avoid breakages. _accentColor = accentColor, @@ -874,6 +883,7 @@ class ThemeData with Diagnosticable { _selectedRowColor = selectedRowColor, _errorColor = errorColor, _backgroundColor = backgroundColor, + _bottomAppBarColor = bottomAppBarColor, // GENERAL CONFIGURATION assert(applyElevationOverlayColor != null), assert(extensions != null), @@ -886,7 +896,6 @@ class ThemeData with Diagnosticable { assert(useMaterial3 != null), assert(visualDensity != null), // COLOR - assert(bottomAppBarColor != null), assert(canvasColor != null), assert(cardColor != null), assert(colorScheme != null), @@ -1304,9 +1313,12 @@ class ThemeData with Diagnosticable { // COLOR /// The default color of the [BottomAppBar]. - /// - /// This can be overridden by specifying [BottomAppBar.color]. - final Color bottomAppBarColor; + @Deprecated( + 'Use BottomAppBarTheme.color instead. ' + 'This feature was deprecated after v3.3.0-0.6.pre.', + ) + Color get bottomAppBarColor => _bottomAppBarColor!; + final Color? _bottomAppBarColor; /// The default color of [MaterialType.canvas] [Material]. final Color canvasColor; @@ -1745,7 +1757,6 @@ class ThemeData with Diagnosticable { // [colorScheme] is the preferred way to configure colors. The other color // properties will gradually be phased out, see // https://github.com/flutter/flutter/issues/91772. - Color? bottomAppBarColor, Brightness? brightness, Color? canvasColor, Color? cardColor, @@ -1879,6 +1890,11 @@ class ThemeData with Diagnosticable { 'This feature was deprecated after v2.6.0-11.0.pre.', ) Color? backgroundColor, + @Deprecated( + 'Use BottomAppBarTheme.color instead. ' + 'This feature was deprecated after v3.3.0-0.6.pre.', + ) + Color? bottomAppBarColor, }) { cupertinoOverrideTheme = cupertinoOverrideTheme?.noDefault(); return ThemeData.raw( @@ -1900,7 +1916,6 @@ class ThemeData with Diagnosticable { useMaterial3: useMaterial3 ?? this.useMaterial3, visualDensity: visualDensity ?? this.visualDensity, // COLOR - bottomAppBarColor: bottomAppBarColor ?? this.bottomAppBarColor, canvasColor: canvasColor ?? this.canvasColor, cardColor: cardColor ?? this.cardColor, colorScheme: (colorScheme ?? this.colorScheme).copyWith(brightness: brightness), @@ -1975,6 +1990,7 @@ class ThemeData with Diagnosticable { selectedRowColor: selectedRowColor ?? _selectedRowColor, errorColor: errorColor ?? _errorColor, backgroundColor: backgroundColor ?? _backgroundColor, + bottomAppBarColor: bottomAppBarColor ?? _bottomAppBarColor, ); } @@ -2100,7 +2116,6 @@ class ThemeData with Diagnosticable { useMaterial3: t < 0.5 ? a.useMaterial3 : b.useMaterial3, visualDensity: VisualDensity.lerp(a.visualDensity, b.visualDensity, t), // COLOR - bottomAppBarColor: Color.lerp(a.bottomAppBarColor, b.bottomAppBarColor, t)!, canvasColor: Color.lerp(a.canvasColor, b.canvasColor, t)!, cardColor: Color.lerp(a.cardColor, b.cardColor, t)!, colorScheme: ColorScheme.lerp(a.colorScheme, b.colorScheme, t), @@ -2175,6 +2190,7 @@ class ThemeData with Diagnosticable { selectedRowColor: Color.lerp(a.selectedRowColor, b.selectedRowColor, t), errorColor: Color.lerp(a.errorColor, b.errorColor, t), backgroundColor: Color.lerp(a.backgroundColor, b.backgroundColor, t), + bottomAppBarColor: Color.lerp(a.bottomAppBarColor, b.bottomAppBarColor, t), ); } @@ -2202,7 +2218,6 @@ class ThemeData with Diagnosticable { other.useMaterial3 == useMaterial3 && other.visualDensity == visualDensity && // COLOR - other.bottomAppBarColor == bottomAppBarColor && other.canvasColor == canvasColor && other.cardColor == cardColor && other.colorScheme == colorScheme && @@ -2276,7 +2291,8 @@ class ThemeData with Diagnosticable { other.toggleableActiveColor == toggleableActiveColor && other.selectedRowColor == selectedRowColor && other.errorColor == errorColor && - other.backgroundColor == backgroundColor; + other.backgroundColor == backgroundColor && + other.bottomAppBarColor == bottomAppBarColor; } @override @@ -2301,7 +2317,6 @@ class ThemeData with Diagnosticable { useMaterial3, visualDensity, // COLOR - bottomAppBarColor, canvasColor, cardColor, colorScheme, @@ -2376,6 +2391,7 @@ class ThemeData with Diagnosticable { selectedRowColor, errorColor, backgroundColor, + bottomAppBarColor, ]; return Object.hashAll(values); } @@ -2402,7 +2418,6 @@ class ThemeData with Diagnosticable { properties.add(DiagnosticsProperty('useMaterial3', useMaterial3, defaultValue: defaultData.useMaterial3, level: DiagnosticLevel.debug)); properties.add(DiagnosticsProperty('visualDensity', visualDensity, defaultValue: defaultData.visualDensity, level: DiagnosticLevel.debug)); // COLORS - properties.add(ColorProperty('bottomAppBarColor', bottomAppBarColor, defaultValue: defaultData.bottomAppBarColor, level: DiagnosticLevel.debug)); properties.add(ColorProperty('canvasColor', canvasColor, defaultValue: defaultData.canvasColor, level: DiagnosticLevel.debug)); properties.add(ColorProperty('cardColor', cardColor, defaultValue: defaultData.cardColor, level: DiagnosticLevel.debug)); properties.add(DiagnosticsProperty('colorScheme', colorScheme, defaultValue: defaultData.colorScheme, level: DiagnosticLevel.debug)); @@ -2477,6 +2492,7 @@ class ThemeData with Diagnosticable { properties.add(ColorProperty('selectedRowColor', selectedRowColor, defaultValue: defaultData.selectedRowColor, level: DiagnosticLevel.debug)); properties.add(ColorProperty('errorColor', errorColor, defaultValue: defaultData.errorColor, level: DiagnosticLevel.debug)); properties.add(ColorProperty('backgroundColor', backgroundColor, defaultValue: defaultData.backgroundColor, level: DiagnosticLevel.debug)); + properties.add(ColorProperty('bottomAppBarColor', bottomAppBarColor, defaultValue: defaultData.bottomAppBarColor, level: DiagnosticLevel.debug)); } } diff --git a/packages/flutter/test/material/theme_data_test.dart b/packages/flutter/test/material/theme_data_test.dart index 71cbb321dc..5e2e0fba31 100644 --- a/packages/flutter/test/material/theme_data_test.dart +++ b/packages/flutter/test/material/theme_data_test.dart @@ -650,7 +650,6 @@ void main() { useMaterial3: false, visualDensity: VisualDensity.standard, // COLOR - bottomAppBarColor: Colors.black, canvasColor: Colors.black, cardColor: Colors.black, colorScheme: const ColorScheme.light(), @@ -725,6 +724,7 @@ void main() { selectedRowColor: Colors.black, errorColor: Colors.black, backgroundColor: Colors.black, + bottomAppBarColor: Colors.black, ); final SliderThemeData otherSliderTheme = SliderThemeData.fromPrimaryColors( @@ -762,7 +762,6 @@ void main() { visualDensity: VisualDensity.standard, // COLOR - bottomAppBarColor: Colors.white, canvasColor: Colors.white, cardColor: Colors.white, colorScheme: const ColorScheme.light(), @@ -840,6 +839,7 @@ void main() { selectedRowColor: Colors.white, errorColor: Colors.white, backgroundColor: Colors.white, + bottomAppBarColor: Colors.white, ); final ThemeData themeDataCopy = theme.copyWith( @@ -862,7 +862,6 @@ void main() { visualDensity: otherTheme.visualDensity, // COLOR - bottomAppBarColor: otherTheme.bottomAppBarColor, canvasColor: otherTheme.canvasColor, cardColor: otherTheme.cardColor, colorScheme: otherTheme.colorScheme, @@ -940,6 +939,7 @@ void main() { selectedRowColor: otherTheme.selectedRowColor, errorColor: otherTheme.errorColor, backgroundColor: otherTheme.backgroundColor, + bottomAppBarColor: otherTheme.bottomAppBarColor, ); // For the sanity of the reader, make sure these properties are in the same @@ -961,7 +961,6 @@ void main() { expect(themeDataCopy.visualDensity, equals(otherTheme.visualDensity)); // COLOR - expect(themeDataCopy.bottomAppBarColor, equals(otherTheme.bottomAppBarColor)); expect(themeDataCopy.canvasColor, equals(otherTheme.canvasColor)); expect(themeDataCopy.cardColor, equals(otherTheme.cardColor)); expect(themeDataCopy.colorScheme, equals(otherTheme.colorScheme)); @@ -1044,6 +1043,7 @@ void main() { expect(themeDataCopy.selectedRowColor, equals(otherTheme.selectedRowColor)); expect(themeDataCopy.errorColor, equals(otherTheme.errorColor)); expect(themeDataCopy.backgroundColor, equals(otherTheme.backgroundColor)); + expect(themeDataCopy.bottomAppBarColor, equals(otherTheme.bottomAppBarColor)); }); testWidgets('ThemeData.toString has less than 200 characters output', (WidgetTester tester) async { @@ -1109,7 +1109,6 @@ void main() { 'shadowColor', 'canvasColor', 'scaffoldBackgroundColor', - 'bottomAppBarColor', 'cardColor', 'dividerColor', 'highlightColor', @@ -1175,6 +1174,7 @@ void main() { 'selectedRowColor', 'errorColor', 'backgroundColor', + 'bottomAppBarColor', }; final DiagnosticPropertiesBuilder properties = DiagnosticPropertiesBuilder(); diff --git a/packages/flutter/test_fixes/material.dart b/packages/flutter/test_fixes/material.dart index cdd40e0cb5..40f9545c43 100644 --- a/packages/flutter/test_fixes/material.dart +++ b/packages/flutter/test_fixes/material.dart @@ -688,4 +688,10 @@ void main() { themeData = ThemeData(backgroundColor: Colors.grey, errorColor: Colors.red); themeData = ThemeData.raw(backgroundColor: Colors.grey, errorColor: Colors.red); themeData = themeData.copyWith(backgroundColor: Colors.grey, errorColor: Colors.red); + + // Changes made in https://github.com/flutter/flutter/pull/111080 + ThemeData themeData = ThemeData(); + themeData = ThemeData(bottomAppBarColor: Colors.green); + themeData = ThemeData.raw(bottomAppBarColor: Colors.green); + themeData = ThemeData.copyWith(bottomAppBarColor: Colors.green); } diff --git a/packages/flutter/test_fixes/material.dart.expect b/packages/flutter/test_fixes/material.dart.expect index 4e06598edf..7f8763a324 100644 --- a/packages/flutter/test_fixes/material.dart.expect +++ b/packages/flutter/test_fixes/material.dart.expect @@ -892,4 +892,10 @@ void main() { themeData = ThemeData(colorScheme: ColorScheme(error: Colors.red).copyWith(background: Colors.grey)); themeData = ThemeData.raw(colorScheme: ColorScheme(error: Colors.red).copyWith(background: Colors.grey)); themeData = themeData.copyWith(colorScheme: ColorScheme(error: Colors.red).copyWith(background: Colors.grey)); + + // Changes made in https://github.com/flutter/flutter/pull/111080 + ThemeData themeData = ThemeData(); + themeData = ThemeData(bottomAppBarTheme: BottomAppBarTheme(color: Colors.green)); + themeData = ThemeData.raw(bottomAppBarTheme: BottomAppBarTheme(color: Colors.green)); + themeData = ThemeData.copyWith(bottomAppBarTheme: BottomAppBarTheme(color: Colors.green)); }