Unverified Commit 88539266 authored by Pierre-Louis's avatar Pierre-Louis Committed by GitHub

Deprecate `ThemeData` `errorColor` and `backgroundColor` (#110162)

parent 0c2f7bc2
......@@ -202,7 +202,7 @@ class KeyPad extends StatelessWidget {
),
Expanded(
child: Material(
color: themeData.backgroundColor,
color: themeData.colorScheme.background,
child: Column(
children: <Widget>[
CalcKey('\u232B', calcState!.handleDelTap),
......
......@@ -203,7 +203,7 @@ class _ChipDemoState extends State<ChipDemo> {
assert(name.length > 1);
final int hash = name.hashCode & 0xffff;
final double hue = (360.0 * hash / (1 << 15)) % 360.0;
final double themeValue = HSVColor.fromColor(theme.backgroundColor).value;
final double themeValue = HSVColor.fromColor(theme.colorScheme.background).value;
return HSVColor.fromAHSV(1.0, hue, 0.4, themeValue).toColor();
}
......
......@@ -87,7 +87,6 @@ ThemeData _buildShrineTheme() {
primaryColor: kShrinePink100,
scaffoldBackgroundColor: kShrineBackgroundWhite,
cardColor: kShrineBackgroundWhite,
errorColor: kShrineErrorRed,
primaryIconTheme: _customIconTheme(base.iconTheme),
inputDecorationTheme: const InputDecorationTheme(border: CutCornersBorder()),
textTheme: _buildShrineTextTheme(base.textTheme),
......
......@@ -22,6 +22,8 @@ ThemeData _buildDarkTheme() {
primary: primaryColor,
secondary: secondaryColor,
onPrimary: Colors.white,
error: const Color(0xFFB00020),
background: const Color(0xFF202124),
);
final ThemeData base = ThemeData(
brightness: Brightness.dark,
......@@ -32,8 +34,6 @@ ThemeData _buildDarkTheme() {
indicatorColor: Colors.white,
canvasColor: const Color(0xFF202124),
scaffoldBackgroundColor: const Color(0xFF202124),
backgroundColor: const Color(0xFF202124),
errorColor: const Color(0xFFB00020),
);
return base.copyWith(
textTheme: _buildTextTheme(base.textTheme),
......@@ -47,6 +47,7 @@ ThemeData _buildLightTheme() {
final ColorScheme colorScheme = const ColorScheme.light().copyWith(
primary: primaryColor,
secondary: secondaryColor,
error: const Color(0xFFB00020),
);
final ThemeData base = ThemeData(
brightness: Brightness.light,
......@@ -57,8 +58,6 @@ ThemeData _buildLightTheme() {
splashFactory: InkRipple.splashFactory,
canvasColor: Colors.white,
scaffoldBackgroundColor: Colors.white,
backgroundColor: Colors.white,
errorColor: const Color(0xFFB00020),
);
return base.copyWith(
textTheme: _buildTextTheme(base.textTheme),
......
......@@ -433,7 +433,7 @@ void sanityCheckDocs() {
// Check a "snippet" example, any one will do.
final File snippetExample = File('$kPublishRoot/api/widgets/ModalRoute/barrierColor.html');
final RegExp snippetRegExp = RegExp(r'\s*<pre class="language-dart" id="sample-code">.*Color get barrierColor =&gt; Theme\.of\(navigator\.context\)\.backgroundColor;.*</pre>');
final RegExp snippetRegExp = RegExp(r'\s*<pre class="language-dart" id="sample-code">.*Color get barrierColor =&gt; Theme\.of\(navigator\.context\)\.colorScheme.background;.*</pre>');
_sanityCheckExample(snippetExample, snippetRegExp);
// Check a "dartpad" example, any one will do.
......
......@@ -41,7 +41,7 @@ class InputDecoratorExample extends StatelessWidget {
// is in its error state.
floatingLabelStyle: MaterialStateTextStyle.resolveWith(
(Set<MaterialState> states) {
final Color color = states.contains(MaterialState.error) ? Theme.of(context).errorColor: Colors.orange;
final Color color = states.contains(MaterialState.error) ? Theme.of(context).colorScheme.error: Colors.orange;
return TextStyle(color: color, letterSpacing: 1.3);
}
),
......
......@@ -41,7 +41,7 @@ class InputDecoratorExample extends StatelessWidget {
// is in its error state.
labelStyle: MaterialStateTextStyle.resolveWith(
(Set<MaterialState> states) {
final Color color = states.contains(MaterialState.error) ? Theme.of(context).errorColor: Colors.orange;
final Color color = states.contains(MaterialState.error) ? Theme.of(context).colorScheme.error: Colors.orange;
return TextStyle(color: color, letterSpacing: 1.3);
}
),
......
......@@ -7,7 +7,7 @@ import 'package:flutter_api_samples/material/input_decorator/input_decoration.fl
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('InputDecorator label uses errorColor', (WidgetTester tester) async {
testWidgets('InputDecorator label uses error color', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MyApp(),
);
......@@ -17,6 +17,6 @@ void main() {
await tester.pumpAndSettle();
final AnimatedDefaultTextStyle label = tester.firstWidget(find.ancestor(of: find.text('Name'), matching: find.byType(AnimatedDefaultTextStyle)));
expect(label.style.color, theme.data.errorColor);
expect(label.style.color, theme.data.colorScheme.error);
});
}
......@@ -7,13 +7,13 @@ import 'package:flutter_api_samples/material/input_decorator/input_decoration.la
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('InputDecorator label uses errorColor', (WidgetTester tester) async {
testWidgets('InputDecorator label uses error color', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MyApp(),
);
final Theme theme = tester.firstWidget(find.byType(Theme));
final AnimatedDefaultTextStyle label = tester.firstWidget(find.ancestor(of: find.text('Name'), matching: find.byType(AnimatedDefaultTextStyle)));
expect(label.style.color, theme.data.errorColor);
expect(label.style.color, theme.data.colorScheme.error);
});
}
This diff is collapsed.
......@@ -1957,7 +1957,7 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
: themeData.disabledColor;
}
if (decoration.errorText != null) {
return themeData.errorColor;
return themeData.colorScheme.error;
}
if (isFocused) {
return themeData.colorScheme.primary;
......@@ -2641,7 +2641,7 @@ class InputDecoration {
///
/// Note that if you specify this style it will override the default behavior
/// of [InputDecoration] that changes the color of the label to the
/// [InputDecoration.errorStyle] color or [ThemeData.errorColor].
/// [InputDecoration.errorStyle] color or [ColorScheme.error].
///
/// {@tool dartpad}
/// It's possible to override the label style for just the error state, or
......@@ -2671,7 +2671,7 @@ class InputDecoration {
///
/// Note that if you specify this style it will override the default behavior
/// of [InputDecoration] that changes the color of the label to the
/// [InputDecoration.errorStyle] color or [ThemeData.errorColor].
/// [InputDecoration.errorStyle] color or [ColorScheme.error].
///
/// {@tool dartpad}
/// It's possible to override the label style for just the error state, or
......@@ -4345,7 +4345,7 @@ class _InputDecoratorDefaultsM2 extends InputDecorationTheme {
return TextStyle(color: Theme.of(context).disabledColor);
}
if (states.contains(MaterialState.error)) {
return TextStyle(color: Theme.of(context).errorColor);
return TextStyle(color: Theme.of(context).colorScheme.error);
}
if (states.contains(MaterialState.focused)) {
return TextStyle(color: Theme.of(context).colorScheme.primary);
......@@ -4369,7 +4369,7 @@ class _InputDecoratorDefaultsM2 extends InputDecorationTheme {
if (states.contains(MaterialState.disabled)) {
return themeData.textTheme.bodySmall!.copyWith(color: Colors.transparent);
}
return themeData.textTheme.bodySmall!.copyWith(color: themeData.errorColor);
return themeData.textTheme.bodySmall!.copyWith(color: themeData.colorScheme.error);
});
@override
......
......@@ -1440,7 +1440,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
}
TextStyle _m2CounterErrorStyle(BuildContext context) =>
Theme.of(context).textTheme.bodySmall!.copyWith(color: Theme.of(context).errorColor);
Theme.of(context).textTheme.bodySmall!.copyWith(color: Theme.of(context).colorScheme.error);
// BEGIN GENERATED TOKEN PROPERTIES - TextField
......
......@@ -1319,7 +1319,7 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T
/// background color, one could say:
///
/// ```dart
/// Color get barrierColor => Theme.of(navigator.context).backgroundColor;
/// Color get barrierColor => Theme.of(navigator.context).colorScheme.background;
/// ```
///
/// {@end-tool}
......
......@@ -4621,7 +4621,7 @@ void main() {
),
);
await tester.pumpAndSettle();
expect(getBorderColor(tester), theme.errorColor);
expect(getBorderColor(tester), theme.colorScheme.error);
// Disabled
await tester.pumpWidget(
......
......@@ -650,7 +650,6 @@ void main() {
useMaterial3: false,
visualDensity: VisualDensity.standard,
// COLOR
backgroundColor: Colors.black,
bottomAppBarColor: Colors.black,
canvasColor: Colors.black,
cardColor: Colors.black,
......@@ -658,7 +657,6 @@ void main() {
dialogBackgroundColor: Colors.black,
disabledColor: Colors.black,
dividerColor: Colors.black,
errorColor: Colors.black,
focusColor: Colors.black,
highlightColor: Colors.black,
hintColor: Colors.black,
......@@ -725,6 +723,8 @@ void main() {
androidOverscrollIndicator: AndroidOverscrollIndicator.glow,
toggleableActiveColor: Colors.black,
selectedRowColor: Colors.black,
errorColor: Colors.black,
backgroundColor: Colors.black,
);
final SliderThemeData otherSliderTheme = SliderThemeData.fromPrimaryColors(
......@@ -762,7 +762,6 @@ void main() {
visualDensity: VisualDensity.standard,
// COLOR
backgroundColor: Colors.white,
bottomAppBarColor: Colors.white,
canvasColor: Colors.white,
cardColor: Colors.white,
......@@ -770,7 +769,6 @@ void main() {
dialogBackgroundColor: Colors.white,
disabledColor: Colors.white,
dividerColor: Colors.white,
errorColor: Colors.white,
focusColor: Colors.white,
highlightColor: Colors.white,
hintColor: Colors.white,
......@@ -840,6 +838,8 @@ void main() {
androidOverscrollIndicator: AndroidOverscrollIndicator.stretch,
toggleableActiveColor: Colors.white,
selectedRowColor: Colors.white,
errorColor: Colors.white,
backgroundColor: Colors.white,
);
final ThemeData themeDataCopy = theme.copyWith(
......@@ -862,7 +862,6 @@ void main() {
visualDensity: otherTheme.visualDensity,
// COLOR
backgroundColor: otherTheme.backgroundColor,
bottomAppBarColor: otherTheme.bottomAppBarColor,
canvasColor: otherTheme.canvasColor,
cardColor: otherTheme.cardColor,
......@@ -870,7 +869,6 @@ void main() {
dialogBackgroundColor: otherTheme.dialogBackgroundColor,
disabledColor: otherTheme.disabledColor,
dividerColor: otherTheme.dividerColor,
errorColor: otherTheme.errorColor,
focusColor: otherTheme.focusColor,
highlightColor: otherTheme.highlightColor,
hintColor: otherTheme.hintColor,
......@@ -940,6 +938,8 @@ void main() {
androidOverscrollIndicator: otherTheme.androidOverscrollIndicator,
toggleableActiveColor: otherTheme.toggleableActiveColor,
selectedRowColor: otherTheme.selectedRowColor,
errorColor: otherTheme.errorColor,
backgroundColor: otherTheme.backgroundColor,
);
// 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.backgroundColor, equals(otherTheme.backgroundColor));
expect(themeDataCopy.bottomAppBarColor, equals(otherTheme.bottomAppBarColor));
expect(themeDataCopy.canvasColor, equals(otherTheme.canvasColor));
expect(themeDataCopy.cardColor, equals(otherTheme.cardColor));
......@@ -969,7 +968,6 @@ void main() {
expect(themeDataCopy.dialogBackgroundColor, equals(otherTheme.dialogBackgroundColor));
expect(themeDataCopy.disabledColor, equals(otherTheme.disabledColor));
expect(themeDataCopy.dividerColor, equals(otherTheme.dividerColor));
expect(themeDataCopy.errorColor, equals(otherTheme.errorColor));
expect(themeDataCopy.focusColor, equals(otherTheme.focusColor));
expect(themeDataCopy.highlightColor, equals(otherTheme.highlightColor));
expect(themeDataCopy.hintColor, equals(otherTheme.hintColor));
......@@ -1044,6 +1042,8 @@ void main() {
expect(themeDataCopy.androidOverscrollIndicator, equals(otherTheme.androidOverscrollIndicator));
expect(themeDataCopy.toggleableActiveColor, equals(otherTheme.toggleableActiveColor));
expect(themeDataCopy.selectedRowColor, equals(otherTheme.selectedRowColor));
expect(themeDataCopy.errorColor, equals(otherTheme.errorColor));
expect(themeDataCopy.backgroundColor, equals(otherTheme.backgroundColor));
});
testWidgets('ThemeData.toString has less than 200 characters output', (WidgetTester tester) async {
......@@ -1117,11 +1117,9 @@ void main() {
'unselectedWidgetColor',
'disabledColor',
'secondaryHeaderColor',
'backgroundColor',
'dialogBackgroundColor',
'indicatorColor',
'hintColor',
'errorColor',
// TYPOGRAPHY & ICONOGRAPHY
'typography',
'textTheme',
......@@ -1175,6 +1173,8 @@ void main() {
'androidOverscrollIndicator',
'toggleableActiveColor',
'selectedRowColor',
'errorColor',
'backgroundColor',
};
final DiagnosticPropertiesBuilder properties = DiagnosticPropertiesBuilder();
......
......@@ -516,7 +516,7 @@ void main() {
colorScheme = ColorScheme.highContrastLight(primaryVariant: Colors.black, secondaryVariant: Colors.white);
colorScheme = ColorScheme.highContrastDark(primaryVariant: Colors.black, secondaryVariant: Colors.white);
colorScheme = colorScheme.copyWith(primaryVariant: Colors.black, secondaryVariant: Colors.white);
colorScheme.primaryVariant;
colorScheme.primaryVariant; // Removing field reference not supported.
colorScheme.secondaryVariant;
// Changes made in https://github.com/flutter/flutter/pull/96115
......@@ -644,4 +644,48 @@ void main() {
style = textTheme.caption;
style = textTheme.button;
style = textTheme.overline;
// Changes made in https://github.com/flutter/flutter/pull/110162
ThemeData themeData = ThemeData();
themeData = ThemeData(errorColor: Colors.red);
themeData = ThemeData(errorColor: Colors.red, primarySwatch: Colors.blue);
themeData = ThemeData(errorColor: Colors.red, colorScheme: ColorScheme.light());
themeData = ThemeData(errorColor: Colors.red, colorScheme: ColorScheme.light(), primarySwatch: Colors.blue);
themeData = ThemeData(otherParam: '');
themeData = ThemeData.raw(errorColor: Colors.red);
themeData = ThemeData.raw(errorColor: Colors.red, primarySwatch: Colors.blue);
themeData = ThemeData.raw(errorColor: Colors.red, colorScheme: ColorScheme.light());
themeData = ThemeData.raw(errorColor: Colors.red, colorScheme: ColorScheme.light(), primarySwatch: Colors.blue);
themeData = ThemeData.raw(otherParam: '');
themeData = themeData.copyWith(errorColor: Colors.red);
themeData = themeData.copyWith(otherParam: '');
themeData = themeData.copyWith(errorColor: Colors.red, primarySwatch: Colors.blue);
themeData = themeData.copyWith(errorColor: Colors.red, colorScheme: ColorScheme.light());
themeData = themeData.copyWith(errorColor: Colors.red, colorScheme: ColorScheme.light(), primarySwatch: Colors.blue);
themeData.errorColor;
// Changes made in https://github.com/flutter/flutter/pull/110162
ThemeData themeData = ThemeData();
themeData = ThemeData(backgroundColor: Colors.grey);
themeData = ThemeData(backgroundColor: Colors.grey, primarySwatch: Colors.blue);
themeData = ThemeData(backgroundColor: Colors.grey, colorScheme: ColorScheme.light());
themeData = ThemeData(backgroundColor: Colors.grey, colorScheme: ColorScheme.light(), primarySwatch: Colors.blue);
themeData = ThemeData(otherParam: '');
themeData = ThemeData.raw(backgroundColor: Colors.grey);
themeData = ThemeData.raw(backgroundColor: Colors.grey, primarySwatch: Colors.blue);
themeData = ThemeData.raw(backgroundColor: Colors.grey, colorScheme: ColorScheme.light());
themeData = ThemeData.raw(backgroundColor: Colors.grey, colorScheme: ColorScheme.light(), primarySwatch: Colors.blue);
themeData = ThemeData.raw(otherParam: '');
themeData = themeData.copyWith(backgroundColor: Colors.grey);
themeData = themeData.copyWith(otherParam: '');
themeData = themeData.copyWith(backgroundColor: Colors.grey, primarySwatch: Colors.blue);
themeData = themeData.copyWith(backgroundColor: Colors.grey, colorScheme: ColorScheme.light());
themeData = themeData.copyWith(backgroundColor: Colors.grey, colorScheme: ColorScheme.light(), primarySwatch: Colors.blue);
themeData.backgroundColor;
// Changes made in https://github.com/flutter/flutter/pull/110162
ThemeData themeData = ThemeData();
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);
}
......@@ -490,7 +490,7 @@ void main() {
colorScheme = ColorScheme.highContrastLight();
colorScheme = ColorScheme.highContrastDark();
colorScheme = colorScheme.copyWith();
colorScheme.primaryContainer;
colorScheme.primaryContainer; // Removing field reference not supported.
colorScheme.secondaryContainer;
// Changes made in https://github.com/flutter/flutter/pull/96115
......@@ -848,4 +848,48 @@ void main() {
style = textTheme.bodySmall;
style = textTheme.labelLarge;
style = textTheme.labelSmall;
// Changes made in https://github.com/flutter/flutter/pull/110162
ThemeData themeData = ThemeData();
themeData = ThemeData(colorScheme: ColorScheme(error: Colors.red));
themeData = ThemeData(colorScheme: ColorScheme.fromSwatch(primarySwatch: Colors.blue).copyWith(error: Colors.red));
themeData = ThemeData(colorScheme: ColorScheme.light().copyWith(error: Colors.red));
themeData = ThemeData(colorScheme: ColorScheme.light().copyWith(primarySwatch: Colors.blue, error: Colors.red));
themeData = ThemeData(otherParam: '');
themeData = ThemeData.raw(colorScheme: ColorScheme(error: Colors.red));
themeData = ThemeData.raw(colorScheme: ColorScheme.fromSwatch(primarySwatch: Colors.blue).copyWith(error: Colors.red));
themeData = ThemeData.raw(colorScheme: ColorScheme.light().copyWith(error: Colors.red));
themeData = ThemeData.raw(colorScheme: ColorScheme.light().copyWith(primarySwatch: Colors.blue, error: Colors.red));
themeData = ThemeData.raw(otherParam: '');
themeData = themeData.copyWith(colorScheme: ColorScheme(error: Colors.red));
themeData = themeData.copyWith(otherParam: '');
themeData = themeData.copyWith(colorScheme: ColorScheme.fromSwatch(primarySwatch: Colors.blue).copyWith(error: Colors.red));
themeData = themeData.copyWith(colorScheme: ColorScheme.light().copyWith(error: Colors.red));
themeData = themeData.copyWith(colorScheme: ColorScheme.light().copyWith(primarySwatch: Colors.blue, error: Colors.red));
themeData.colorScheme.error;
// Changes made in https://github.com/flutter/flutter/pull/110162
ThemeData themeData = ThemeData();
themeData = ThemeData(colorScheme: ColorScheme(background: Colors.grey));
themeData = ThemeData(colorScheme: ColorScheme.fromSwatch(primarySwatch: Colors.blue).copyWith(background: Colors.grey));
themeData = ThemeData(colorScheme: ColorScheme.light().copyWith(background: Colors.grey));
themeData = ThemeData(colorScheme: ColorScheme.light().copyWith(primarySwatch: Colors.blue, background: Colors.grey));
themeData = ThemeData(otherParam: '');
themeData = ThemeData.raw(colorScheme: ColorScheme(background: Colors.grey));
themeData = ThemeData.raw(colorScheme: ColorScheme.fromSwatch(primarySwatch: Colors.blue).copyWith(background: Colors.grey));
themeData = ThemeData.raw(colorScheme: ColorScheme.light().copyWith(background: Colors.grey));
themeData = ThemeData.raw(colorScheme: ColorScheme.light().copyWith(primarySwatch: Colors.blue, background: Colors.grey));
themeData = ThemeData.raw(otherParam: '');
themeData = themeData.copyWith(colorScheme: ColorScheme(background: Colors.grey));
themeData = themeData.copyWith(otherParam: '');
themeData = themeData.copyWith(colorScheme: ColorScheme.fromSwatch(primarySwatch: Colors.blue).copyWith(background: Colors.grey));
themeData = themeData.copyWith(colorScheme: ColorScheme.light().copyWith(background: Colors.grey));
themeData = themeData.copyWith(colorScheme: ColorScheme.light().copyWith(primarySwatch: Colors.blue, background: Colors.grey));
themeData.colorScheme.background;
// Changes made in https://github.com/flutter/flutter/pull/110162
ThemeData themeData = ThemeData();
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));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment