Skip to content

Commit 1c77696

Browse files
authored
Make CupertinoTextField respect decoration color when disabled (#149774)
#83531 contains complaints that this default disabled color can no longer be overridden by setting a color of the `decoration` property. This regression was introduced by #78058, which was itself made to fix an issue where the color of the decoration was always used even when disabled. Currently, when the text field is disabled, its color is set to a default disabled color. This PR makes it so that if a decoration is set when the text field is disabled, its color is used instead of the default disabled color. Fixes flutter/flutter#83531
1 parent 0aadb89 commit 1c77696

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

packages/flutter/lib/src/cupertino/text_field.dart

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,10 +1338,16 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with Restoratio
13381338
);
13391339
}
13401340

1341-
final BoxDecoration? effectiveDecoration = widget.decoration?.copyWith(
1342-
border: resolvedBorder,
1343-
color: enabled ? decorationColor : disabledColor,
1344-
);
1341+
// Use the default disabled color only if the box decoration was not set.
1342+
final BoxDecoration? effectiveDecoration =
1343+
widget.decoration?.copyWith(
1344+
border: resolvedBorder,
1345+
color: enabled ? decorationColor
1346+
: (widget.decoration == _kDefaultRoundedBorderDecoration
1347+
? disabledColor
1348+
: widget.decoration?.color
1349+
),
1350+
);
13451351

13461352
final Color selectionColor = CupertinoDynamicColor.maybeResolve(
13471353
DefaultSelectionStyle.of(context).selectionColor,

packages/flutter/test/cupertino/text_field_test.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8397,6 +8397,34 @@ void main() {
83978397
);
83988398
});
83998399

8400+
testWidgets('Disabled widget does not override background color', (WidgetTester tester) async {
8401+
const Color backgroundColor = Color(0x0000000A);
8402+
await tester.pumpWidget(
8403+
const CupertinoApp(
8404+
home: Center(
8405+
child: CupertinoTextField(
8406+
enabled: false,
8407+
decoration: BoxDecoration(color: backgroundColor),
8408+
),
8409+
),
8410+
),
8411+
);
8412+
8413+
final BoxDecoration decoration = tester
8414+
.widget<DecoratedBox>(
8415+
find.descendant(
8416+
of: find.byType(CupertinoTextField),
8417+
matching: find.byType(DecoratedBox),
8418+
),
8419+
)
8420+
.decoration as BoxDecoration;
8421+
8422+
expect(
8423+
decoration.color!.value,
8424+
backgroundColor.value,
8425+
);
8426+
});
8427+
84008428
// Regression test for https://github.com/flutter/flutter/issues/78097.
84018429
testWidgets(
84028430
'still gets disabled background color when decoration is null',

0 commit comments

Comments
 (0)