From a5d0d0e506979ecc2633fcbefdbe419a39f3dd1a Mon Sep 17 00:00:00 2001 From: Darren Austin Date: Fri, 12 Mar 2021 16:48:05 -0800 Subject: [PATCH] Updated InputDecorator to no longer reference ThemeData.accentColor. (#77999) --- .../lib/src/material/input_decorator.dart | 14 +-- .../test/material/input_decorator_test.dart | 91 ++++++++++++++++++- 2 files changed, 92 insertions(+), 13 deletions(-) diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index c972542ec9..9d1ef43006 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -2019,24 +2019,14 @@ class _InputDecoratorState extends State with TickerProviderStat Color _getActiveColor(ThemeData themeData) { if (isFocused) { - switch (themeData.brightness) { - case Brightness.dark: - return themeData.accentColor; - case Brightness.light: - return themeData.primaryColor; - } + return themeData.colorScheme.primary; } return themeData.hintColor; } Color _getDefaultBorderColor(ThemeData themeData) { if (isFocused) { - switch (themeData.brightness) { - case Brightness.dark: - return themeData.accentColor; - case Brightness.light: - return themeData.primaryColor; - } + return themeData.colorScheme.primary; } if (decoration!.filled!) { return themeData.hintColor; diff --git a/packages/flutter/test/material/input_decorator_test.dart b/packages/flutter/test/material/input_decorator_test.dart index fbc1d3ceea..a74c206f7e 100644 --- a/packages/flutter/test/material/input_decorator_test.dart +++ b/packages/flutter/test/material/input_decorator_test.dart @@ -13,6 +13,7 @@ import '../rendering/mock_canvas.dart'; Widget buildInputDecorator({ InputDecoration decoration = const InputDecoration(), + ThemeData? theme, InputDecorationTheme? inputDecorationTheme, TextDirection textDirection = TextDirection.ltr, bool expands = false, @@ -33,7 +34,7 @@ Widget buildInputDecorator({ child: Builder( builder: (BuildContext context) { return Theme( - data: Theme.of(context).copyWith( + data: (theme ?? Theme.of(context)).copyWith( inputDecorationTheme: inputDecorationTheme, visualDensity: visualDensity, fixTextFieldOutlineLabel: fixTextFieldOutlineLabel, @@ -3595,6 +3596,94 @@ void main() { 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 { const InputBorder errorBorder = OutlineInputBorder( borderSide: BorderSide(color: Colors.red, width: 1.5),