Unverified Commit a5d0d0e5 authored by Darren Austin's avatar Darren Austin Committed by GitHub

Updated InputDecorator to no longer reference ThemeData.accentColor. (#77999)

parent 2820d21c
...@@ -2019,24 +2019,14 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat ...@@ -2019,24 +2019,14 @@ class _InputDecoratorState extends State<InputDecorator> with TickerProviderStat
Color _getActiveColor(ThemeData themeData) { Color _getActiveColor(ThemeData themeData) {
if (isFocused) { if (isFocused) {
switch (themeData.brightness) { return themeData.colorScheme.primary;
case Brightness.dark:
return themeData.accentColor;
case Brightness.light:
return themeData.primaryColor;
}
} }
return themeData.hintColor; return themeData.hintColor;
} }
Color _getDefaultBorderColor(ThemeData themeData) { Color _getDefaultBorderColor(ThemeData themeData) {
if (isFocused) { if (isFocused) {
switch (themeData.brightness) { return themeData.colorScheme.primary;
case Brightness.dark:
return themeData.accentColor;
case Brightness.light:
return themeData.primaryColor;
}
} }
if (decoration!.filled!) { if (decoration!.filled!) {
return themeData.hintColor; return themeData.hintColor;
......
...@@ -13,6 +13,7 @@ import '../rendering/mock_canvas.dart'; ...@@ -13,6 +13,7 @@ import '../rendering/mock_canvas.dart';
Widget buildInputDecorator({ Widget buildInputDecorator({
InputDecoration decoration = const InputDecoration(), InputDecoration decoration = const InputDecoration(),
ThemeData? theme,
InputDecorationTheme? inputDecorationTheme, InputDecorationTheme? inputDecorationTheme,
TextDirection textDirection = TextDirection.ltr, TextDirection textDirection = TextDirection.ltr,
bool expands = false, bool expands = false,
...@@ -33,7 +34,7 @@ Widget buildInputDecorator({ ...@@ -33,7 +34,7 @@ Widget buildInputDecorator({
child: Builder( child: Builder(
builder: (BuildContext context) { builder: (BuildContext context) {
return Theme( return Theme(
data: Theme.of(context).copyWith( data: (theme ?? Theme.of(context)).copyWith(
inputDecorationTheme: inputDecorationTheme, inputDecorationTheme: inputDecorationTheme,
visualDensity: visualDensity, visualDensity: visualDensity,
fixTextFieldOutlineLabel: fixTextFieldOutlineLabel, fixTextFieldOutlineLabel: fixTextFieldOutlineLabel,
...@@ -3595,6 +3596,94 @@ void main() { ...@@ -3595,6 +3596,94 @@ void main() {
expect(debugString, contains('focusedBorder: OutlineInputBorder()')); expect(debugString, contains('focusedBorder: OutlineInputBorder()'));
}); });
testWidgets('InputDecoration default border uses colorScheme', (WidgetTester tester) async {
final ThemeData theme = ThemeData.from(colorScheme: const ColorScheme.light());
final Color enabledColor = theme.colorScheme.onSurface.withOpacity(0.38);
final Color hoverColor = Color.alphaBlend(theme.hoverColor.withOpacity(0.12), enabledColor);
// Enabled
await tester.pumpWidget(
buildInputDecorator(
theme: theme,
decoration: const InputDecoration(),
),
);
await tester.pumpAndSettle();
expect(getBorderColor(tester), enabledColor);
// Filled
await tester.pumpWidget(
buildInputDecorator(
theme: theme,
decoration: const InputDecoration(
filled: true,
),
),
);
await tester.pumpAndSettle();
expect(getBorderColor(tester), theme.hintColor);
// Hovering
await tester.pumpWidget(
buildInputDecorator(
theme: theme,
isHovering: true,
decoration: const InputDecoration(),
),
);
await tester.pumpAndSettle();
expect(getBorderColor(tester), hoverColor);
// Focused
await tester.pumpWidget(
buildInputDecorator(
theme: theme,
isFocused: true,
decoration: const InputDecoration(),
),
);
await tester.pumpAndSettle();
expect(getBorderColor(tester), theme.colorScheme.primary);
// Error
await tester.pumpWidget(
buildInputDecorator(
theme: theme,
decoration: const InputDecoration(
errorText: 'Nope',
),
),
);
await tester.pumpAndSettle();
expect(getBorderColor(tester), theme.errorColor);
// Disabled
await tester.pumpWidget(
buildInputDecorator(
theme: theme,
decoration: const InputDecoration(
enabled: false,
),
),
);
await tester.pumpAndSettle();
expect(getBorderColor(tester), theme.disabledColor);
// Disabled, filled
await tester.pumpWidget(
buildInputDecorator(
theme: theme,
decoration: const InputDecoration(
enabled: false,
filled: true,
),
),
);
await tester.pumpAndSettle();
expect(getBorderColor(tester), Colors.transparent);
});
testWidgets('InputDecoration borders', (WidgetTester tester) async { testWidgets('InputDecoration borders', (WidgetTester tester) async {
const InputBorder errorBorder = OutlineInputBorder( const InputBorder errorBorder = OutlineInputBorder(
borderSide: BorderSide(color: Colors.red, width: 1.5), borderSide: BorderSide(color: Colors.red, width: 1.5),
......
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