From 4f569fb326046079baaf5a16f68668fd7262cfd9 Mon Sep 17 00:00:00 2001 From: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com> Date: Mon, 15 Mar 2021 14:18:03 -0700 Subject: [PATCH] CupertinoTextField to show disabled background color when decoration is null (#78140) --- .../flutter/lib/src/cupertino/text_field.dart | 1 + .../test/cupertino/text_field_test.dart | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/packages/flutter/lib/src/cupertino/text_field.dart b/packages/flutter/lib/src/cupertino/text_field.dart index 473b3b18f0..c3af40acfd 100644 --- a/packages/flutter/lib/src/cupertino/text_field.dart +++ b/packages/flutter/lib/src/cupertino/text_field.dart @@ -1216,6 +1216,7 @@ class _CupertinoTextFieldState extends State with Restoratio ignoring: !enabled, child: Container( decoration: effectiveDecoration, + color: !enabled && effectiveDecoration == null ? disabledColor : null, child: _selectionGestureDetectorBuilder.buildGestureDetector( behavior: HitTestBehavior.translucent, child: Align( diff --git a/packages/flutter/test/cupertino/text_field_test.dart b/packages/flutter/test/cupertino/text_field_test.dart index 07f5920dc4..017841a83a 100644 --- a/packages/flutter/test/cupertino/text_field_test.dart +++ b/packages/flutter/test/cupertino/text_field_test.dart @@ -4695,4 +4695,28 @@ void main() { 0xFF050505, ); }); + + // Regression test for https://github.com/flutter/flutter/issues/78097. + testWidgets( + 'still gets disabled background color when decoration is null', + (WidgetTester tester) async { + await tester.pumpWidget( + const CupertinoApp( + home: Center( + child: CupertinoTextField( + decoration: null, + enabled: false, + ), + ), + ), + ); + + final Color disabledColor = tester.widget( + find.descendant( + of: find.byType(CupertinoTextField), + matching: find.byType(ColoredBox), + ), + ).color; + expect(disabledColor, isSameColorAs(const Color(0xFFFAFAFA))); + }); }