diff --git a/bin/internal/goldens.version b/bin/internal/goldens.version index ad05202bae..d4db4c0575 100644 --- a/bin/internal/goldens.version +++ b/bin/internal/goldens.version @@ -1 +1 @@ -d79941e3d9c6e761189ac8aefa3a40c7fb98413e +2eea0c710c4fca4c6655b4efc15b68d4b44cd404 diff --git a/packages/flutter/lib/src/cupertino/text_field.dart b/packages/flutter/lib/src/cupertino/text_field.dart index 09ae55d9fa..f5dd5c0480 100644 --- a/packages/flutter/lib/src/cupertino/text_field.dart +++ b/packages/flutter/lib/src/cupertino/text_field.dart @@ -785,6 +785,13 @@ class _CupertinoTextFieldState extends State with AutomaticK final TextStyle placeholderStyle = textStyle.merge(widget.placeholderStyle); final Brightness keyboardAppearance = widget.keyboardAppearance ?? themeData.brightness; final Color cursorColor = widget.cursorColor ?? themeData.primaryColor; + final Color disabledColor = CupertinoTheme.of(context).brightness == Brightness.light + ? _kDisabledBackground + : CupertinoColors.darkBackgroundGray; + + final BoxDecoration effectiveDecoration = enabled + ? widget.decoration + : widget.decoration?.copyWith(color: widget.decoration?.color ?? disabledColor); final Widget paddedEditable = TextSelectionGestureDetector( onTapDown: _handleTapDown, @@ -855,16 +862,8 @@ class _CupertinoTextFieldState extends State with AutomaticK child: IgnorePointer( ignoring: !enabled, child: Container( - decoration: widget.decoration, - // The main decoration and the disabled scrim exists separately. - child: Container( - color: enabled - ? null - : CupertinoTheme.of(context).brightness == Brightness.light - ? _kDisabledBackground - : CupertinoColors.darkBackgroundGray, - child: _addTextDependentAttachments(paddedEditable, textStyle, placeholderStyle), - ), + decoration: effectiveDecoration, + child: _addTextDependentAttachments(paddedEditable, textStyle, placeholderStyle), ), ), ); diff --git a/packages/flutter/lib/src/painting/box_decoration.dart b/packages/flutter/lib/src/painting/box_decoration.dart index 9777628537..f1e80668dd 100644 --- a/packages/flutter/lib/src/painting/box_decoration.dart +++ b/packages/flutter/lib/src/painting/box_decoration.dart @@ -97,6 +97,30 @@ class BoxDecoration extends Decoration { 'gradient, but no color or gradient was provided.' ); + /// Creates a copy of this object but with the given fields replaced with the + /// new values. + BoxDecoration copyWith({ + Color color, + DecorationImage image, + BoxBorder border, + BorderRadiusGeometry borderRadius, + List boxShadow, + Gradient gradient, + BlendMode backgroundBlendMode, + BoxShape shape, + }) { + return BoxDecoration( + color: color ?? this.color, + image: image ?? this.image, + border: border ?? this.border, + borderRadius: borderRadius ?? this.borderRadius, + boxShadow: boxShadow ?? this.boxShadow, + gradient: gradient ?? this.gradient, + backgroundBlendMode: backgroundBlendMode ?? this.backgroundBlendMode, + shape: shape ?? this.shape, + ); + } + @override bool debugAssertIsValid() { assert(shape != BoxShape.circle || diff --git a/packages/flutter/test/cupertino/text_field_test.dart b/packages/flutter/test/cupertino/text_field_test.dart index c33bb64ae5..007b41c848 100644 --- a/packages/flutter/test/cupertino/text_field_test.dart +++ b/packages/flutter/test/cupertino/text_field_test.dart @@ -2590,4 +2590,30 @@ void main() { debugDefaultTargetPlatformOverride = null; }); + + testWidgets('disabled state golden', (WidgetTester tester) async { + await tester.pumpWidget( + CupertinoApp( + home: DecoratedBox( + decoration: const BoxDecoration(color: Color(0xFFFFFFFF)), + child: Center( + child: SizedBox( + width: 200, + height: 200, + child: CupertinoTextField( + controller: TextEditingController(text: 'lorem'), + enabled: false, + ), + ) + ) + ) + ) + ); + + await expectLater( + find.byType(CupertinoTextField), + matchesGoldenFile('text_field_test.disabled.0.png'), + skip: !Platform.isLinux, + ); + }); }