diff --git a/packages/flutter/lib/src/cupertino/text_field.dart b/packages/flutter/lib/src/cupertino/text_field.dart index 65661e158b..ec4d1694ce 100644 --- a/packages/flutter/lib/src/cupertino/text_field.dart +++ b/packages/flutter/lib/src/cupertino/text_field.dart @@ -1338,10 +1338,16 @@ class _CupertinoTextFieldState extends State with Restoratio ); } - final BoxDecoration? effectiveDecoration = widget.decoration?.copyWith( - border: resolvedBorder, - color: enabled ? decorationColor : disabledColor, - ); + // Use the default disabled color only if the box decoration was not set. + final BoxDecoration? effectiveDecoration = + widget.decoration?.copyWith( + border: resolvedBorder, + color: enabled ? decorationColor + : (widget.decoration == _kDefaultRoundedBorderDecoration + ? disabledColor + : widget.decoration?.color + ), + ); final Color selectionColor = CupertinoDynamicColor.maybeResolve( DefaultSelectionStyle.of(context).selectionColor, diff --git a/packages/flutter/test/cupertino/text_field_test.dart b/packages/flutter/test/cupertino/text_field_test.dart index 7407eccea1..9a1f1e9089 100644 --- a/packages/flutter/test/cupertino/text_field_test.dart +++ b/packages/flutter/test/cupertino/text_field_test.dart @@ -8397,6 +8397,34 @@ void main() { ); }); + testWidgets('Disabled widget does not override background color', (WidgetTester tester) async { + const Color backgroundColor = Color(0x0000000A); + await tester.pumpWidget( + const CupertinoApp( + home: Center( + child: CupertinoTextField( + enabled: false, + decoration: BoxDecoration(color: backgroundColor), + ), + ), + ), + ); + + final BoxDecoration decoration = tester + .widget( + find.descendant( + of: find.byType(CupertinoTextField), + matching: find.byType(DecoratedBox), + ), + ) + .decoration as BoxDecoration; + + expect( + decoration.color!.value, + backgroundColor.value, + ); + }); + // Regression test for https://github.com/flutter/flutter/issues/78097. testWidgets( 'still gets disabled background color when decoration is null',