From 9f4e132fb8a390e76fb6ad9162b230f18e904072 Mon Sep 17 00:00:00 2001 From: Haruka Ma Date: Sun, 14 Mar 2021 07:33:07 +0900 Subject: [PATCH] Fix CupertinoTextField incorrect background color when disabled (#78058) --- .../flutter/lib/src/cupertino/text_field.dart | 2 +- .../test/cupertino/text_field_test.dart | 78 +++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/cupertino/text_field.dart b/packages/flutter/lib/src/cupertino/text_field.dart index 5488eec3ace..473b3b18f09 100644 --- a/packages/flutter/lib/src/cupertino/text_field.dart +++ b/packages/flutter/lib/src/cupertino/text_field.dart @@ -1137,7 +1137,7 @@ class _CupertinoTextFieldState extends State with Restoratio final BoxDecoration? effectiveDecoration = widget.decoration?.copyWith( border: resolvedBorder, - color: enabled ? decorationColor : (decorationColor ?? disabledColor), + color: enabled ? decorationColor : disabledColor, ); final Color selectionColor = CupertinoTheme.of(context).primaryColor.withOpacity(0.2); diff --git a/packages/flutter/test/cupertino/text_field_test.dart b/packages/flutter/test/cupertino/text_field_test.dart index 085ba46d62e..07f5920dc41 100644 --- a/packages/flutter/test/cupertino/text_field_test.dart +++ b/packages/flutter/test/cupertino/text_field_test.dart @@ -4617,4 +4617,82 @@ void main() { expect(state.currentTextEditingValue.composing, TextRange.empty); }); }); + + testWidgets('disabled widget changes background color', + (WidgetTester tester) async { + await tester.pumpWidget( + const CupertinoApp( + home: Center( + child: CupertinoTextField( + enabled: false, + ), + ), + ), + ); + + BoxDecoration decoration = tester + .widget( + find.descendant( + of: find.byType(CupertinoTextField), + matching: find.byType(DecoratedBox), + ), + ) + .decoration as BoxDecoration; + + expect( + decoration.color!.value, + 0xFFFAFAFA, + ); + + await tester.pumpWidget( + const CupertinoApp( + home: Center( + child: CupertinoTextField( + enabled: true, + ), + ), + ), + ); + + decoration = tester + .widget( + find.descendant( + of: find.byType(CupertinoTextField), + matching: find.byType(DecoratedBox), + ), + ) + .decoration as BoxDecoration; + + expect( + decoration.color!.value, + CupertinoColors.white.value, + ); + + await tester.pumpWidget( + const CupertinoApp( + theme: CupertinoThemeData( + brightness: Brightness.dark, + ), + home: Center( + child: CupertinoTextField( + enabled: false, + ), + ), + ), + ); + + decoration = tester + .widget( + find.descendant( + of: find.byType(CupertinoTextField), + matching: find.byType(DecoratedBox), + ), + ) + .decoration as BoxDecoration; + + expect( + decoration.color!.value, + 0xFF050505, + ); + }); }