Commit 683238e8 authored by SimonIT's avatar SimonIT Committed by LongCatIsLooong

Fix disabled CupertinoTextField style (#32974)

parent 2767d37c
d79941e3d9c6e761189ac8aefa3a40c7fb98413e 2eea0c710c4fca4c6655b4efc15b68d4b44cd404
...@@ -785,6 +785,13 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with AutomaticK ...@@ -785,6 +785,13 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with AutomaticK
final TextStyle placeholderStyle = textStyle.merge(widget.placeholderStyle); final TextStyle placeholderStyle = textStyle.merge(widget.placeholderStyle);
final Brightness keyboardAppearance = widget.keyboardAppearance ?? themeData.brightness; final Brightness keyboardAppearance = widget.keyboardAppearance ?? themeData.brightness;
final Color cursorColor = widget.cursorColor ?? themeData.primaryColor; 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( final Widget paddedEditable = TextSelectionGestureDetector(
onTapDown: _handleTapDown, onTapDown: _handleTapDown,
...@@ -855,16 +862,8 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with AutomaticK ...@@ -855,16 +862,8 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with AutomaticK
child: IgnorePointer( child: IgnorePointer(
ignoring: !enabled, ignoring: !enabled,
child: Container( child: Container(
decoration: widget.decoration, decoration: effectiveDecoration,
// The main decoration and the disabled scrim exists separately. child: _addTextDependentAttachments(paddedEditable, textStyle, placeholderStyle),
child: Container(
color: enabled
? null
: CupertinoTheme.of(context).brightness == Brightness.light
? _kDisabledBackground
: CupertinoColors.darkBackgroundGray,
child: _addTextDependentAttachments(paddedEditable, textStyle, placeholderStyle),
),
), ),
), ),
); );
......
...@@ -97,6 +97,30 @@ class BoxDecoration extends Decoration { ...@@ -97,6 +97,30 @@ class BoxDecoration extends Decoration {
'gradient, but no color or gradient was provided.' '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> 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 @override
bool debugAssertIsValid() { bool debugAssertIsValid() {
assert(shape != BoxShape.circle || assert(shape != BoxShape.circle ||
......
...@@ -2590,4 +2590,30 @@ void main() { ...@@ -2590,4 +2590,30 @@ void main() {
debugDefaultTargetPlatformOverride = null; 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,
);
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment