Unverified Commit 43ce3fd9 authored by Justin McCandless's avatar Justin McCandless Committed by GitHub

TextField enabled fix (#55775)

parent f7ad30b7
...@@ -802,7 +802,7 @@ class _TextFieldState extends State<TextField> implements TextSelectionGestureDe ...@@ -802,7 +802,7 @@ class _TextFieldState extends State<TextField> implements TextSelectionGestureDe
final InputDecoration effectiveDecoration = (widget.decoration ?? const InputDecoration()) final InputDecoration effectiveDecoration = (widget.decoration ?? const InputDecoration())
.applyDefaults(themeData.inputDecorationTheme) .applyDefaults(themeData.inputDecorationTheme)
.copyWith( .copyWith(
enabled: widget.enabled, enabled: _isEnabled,
hintMaxLines: widget.decoration?.hintMaxLines ?? widget.maxLines, hintMaxLines: widget.decoration?.hintMaxLines ?? widget.maxLines,
); );
......
...@@ -165,7 +165,7 @@ class TextFormField extends FormField<String> { ...@@ -165,7 +165,7 @@ class TextFormField extends FormField<String> {
FormFieldSetter<String> onSaved, FormFieldSetter<String> onSaved,
FormFieldValidator<String> validator, FormFieldValidator<String> validator,
List<TextInputFormatter> inputFormatters, List<TextInputFormatter> inputFormatters,
bool enabled = true, bool enabled,
double cursorWidth = 2.0, double cursorWidth = 2.0,
Radius cursorRadius, Radius cursorRadius,
Color cursorColor, Color cursorColor,
...@@ -205,7 +205,7 @@ class TextFormField extends FormField<String> { ...@@ -205,7 +205,7 @@ class TextFormField extends FormField<String> {
onSaved: onSaved, onSaved: onSaved,
validator: validator, validator: validator,
autovalidate: autovalidate, autovalidate: autovalidate,
enabled: enabled, enabled: enabled ?? decoration?.enabled ?? true,
builder: (FormFieldState<String> field) { builder: (FormFieldState<String> field) {
final _TextFormFieldState state = field as _TextFormFieldState; final _TextFormFieldState state = field as _TextFormFieldState;
final InputDecoration effectiveDecoration = (decoration ?? const InputDecoration()) final InputDecoration effectiveDecoration = (decoration ?? const InputDecoration())
...@@ -248,7 +248,7 @@ class TextFormField extends FormField<String> { ...@@ -248,7 +248,7 @@ class TextFormField extends FormField<String> {
onEditingComplete: onEditingComplete, onEditingComplete: onEditingComplete,
onSubmitted: onFieldSubmitted, onSubmitted: onFieldSubmitted,
inputFormatters: inputFormatters, inputFormatters: inputFormatters,
enabled: enabled, enabled: enabled ?? decoration?.enabled ?? true,
cursorWidth: cursorWidth, cursorWidth: cursorWidth,
cursorRadius: cursorRadius, cursorRadius: cursorRadius,
cursorColor: cursorColor, cursorColor: cursorColor,
......
...@@ -3597,6 +3597,52 @@ void main() { ...@@ -3597,6 +3597,52 @@ void main() {
semantics.dispose(); semantics.dispose();
}); });
testWidgets('Disabled text field hides helper and counter', (WidgetTester tester) async {
const String helperText = 'helper text';
const String counterText = 'counter text';
const String errorText = 'error text';
Widget buildFrame(bool enabled, bool hasError) {
return MaterialApp(
home: Material(
child: Center(
child: TextField(
decoration: InputDecoration(
labelText: 'label text',
helperText: helperText,
counterText: counterText,
errorText: hasError ? errorText : null,
enabled: enabled,
),
),
),
),
);
}
await tester.pumpWidget(buildFrame(true, false));
Text helperWidget = tester.widget(find.text(helperText));
Text counterWidget = tester.widget(find.text(counterText));
expect(helperWidget.style.color, isNot(equals(Colors.transparent)));
expect(counterWidget.style.color, isNot(equals(Colors.transparent)));
await tester.pumpWidget(buildFrame(true, true));
counterWidget = tester.widget(find.text(counterText));
Text errorWidget = tester.widget(find.text(errorText));
expect(helperWidget.style.color, isNot(equals(Colors.transparent)));
expect(errorWidget.style.color, isNot(equals(Colors.transparent)));
// When enabled is false, the helper/error and counter are not visible.
await tester.pumpWidget(buildFrame(false, false));
helperWidget = tester.widget(find.text(helperText));
counterWidget = tester.widget(find.text(counterText));
expect(helperWidget.style.color, equals(Colors.transparent));
expect(counterWidget.style.color, equals(Colors.transparent));
await tester.pumpWidget(buildFrame(false, true));
errorWidget = tester.widget(find.text(errorText));
counterWidget = tester.widget(find.text(counterText));
expect(counterWidget.style.color, equals(Colors.transparent));
expect(errorWidget.style.color, equals(Colors.transparent));
});
testWidgets('currentValueLength/maxValueLength are in the tree', (WidgetTester tester) async { testWidgets('currentValueLength/maxValueLength are in the tree', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
final TextEditingController controller = TextEditingController(); final TextEditingController controller = TextEditingController();
......
...@@ -240,6 +240,54 @@ void main() { ...@@ -240,6 +240,54 @@ void main() {
expect(_validateCalled, 2); expect(_validateCalled, 2);
}); });
testWidgets('Disabled field hides helper and counter', (WidgetTester tester) async {
const String helperText = 'helper text';
const String counterText = 'counter text';
const String errorText = 'error text';
Widget buildFrame(bool enabled, bool hasError) {
return MaterialApp(
home: Material(
child: Center(
child: TextFormField(
decoration: InputDecoration(
labelText: 'label text',
helperText: helperText,
counterText: counterText,
errorText: hasError ? errorText : null,
enabled: enabled,
),
),
),
),
);
}
// When enabled is true, the helper/error and counter are visible.
await tester.pumpWidget(buildFrame(true, false));
Text helperWidget = tester.widget(find.text(helperText));
Text counterWidget = tester.widget(find.text(counterText));
expect(helperWidget.style.color, isNot(equals(Colors.transparent)));
expect(counterWidget.style.color, isNot(equals(Colors.transparent)));
await tester.pumpWidget(buildFrame(true, true));
counterWidget = tester.widget(find.text(counterText));
Text errorWidget = tester.widget(find.text(errorText));
expect(helperWidget.style.color, isNot(equals(Colors.transparent)));
expect(errorWidget.style.color, isNot(equals(Colors.transparent)));
// When enabled is false, the helper/error and counter are not visible.
await tester.pumpWidget(buildFrame(false, false));
helperWidget = tester.widget(find.text(helperText));
counterWidget = tester.widget(find.text(counterText));
expect(helperWidget.style.color, equals(Colors.transparent));
expect(counterWidget.style.color, equals(Colors.transparent));
await tester.pumpWidget(buildFrame(false, true));
errorWidget = tester.widget(find.text(errorText));
counterWidget = tester.widget(find.text(counterText));
expect(counterWidget.style.color, equals(Colors.transparent));
expect(errorWidget.style.color, equals(Colors.transparent));
});
testWidgets('passing a buildCounter shows returned widget', (WidgetTester tester) async { testWidgets('passing a buildCounter shows returned widget', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
home: Material( home: Material(
......
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