diff --git a/packages/flutter/lib/src/material/text_field.dart b/packages/flutter/lib/src/material/text_field.dart index a566a749ae..4ca47e4378 100644 --- a/packages/flutter/lib/src/material/text_field.dart +++ b/packages/flutter/lib/src/material/text_field.dart @@ -83,7 +83,7 @@ class TextField extends StatefulWidget { /// [TextField.noMaxLength] then only the current length is displayed. /// /// After [maxLength] characters have been input, additional input - /// is ignored, unless [maxLengthEnforced] is set to false. The TextField + /// is ignored, unless [maxLengthEnforced] is set to false. The text field /// enforces the length with a [LengthLimitingTextInputFormatter], which is /// evaluated after the supplied [inputFormatters], if any. The [maxLength] /// value must be either null or greater than zero. @@ -173,7 +173,7 @@ class TextField extends StatefulWidget { /// Requesting the focus will typically cause the keyboard to be shown /// if it's not showing already. /// - /// On Android, the user can hide the keyboard - withouth changing the focus - + /// On Android, the user can hide the keyboard - without changing the focus - /// with the system back button. They can restore the keyboard's visibility /// by tapping on a text field. The user might hide the keyboard and /// switch to a physical keyboard, or they might just need to get it @@ -244,7 +244,7 @@ class TextField extends StatefulWidget { /// to [TextField.noMaxLength] then only the current character count is displayed. /// /// After [maxLength] characters have been input, additional input - /// is ignored, unless [maxLengthEnforced] is set to false. The TextField + /// is ignored, unless [maxLengthEnforced] is set to false. The text field /// enforces the length with a [LengthLimitingTextInputFormatter], which is /// evaluated after the supplied [inputFormatters], if any. /// @@ -262,7 +262,7 @@ class TextField extends StatefulWidget { /// /// ## Limitations /// - /// The TextField does not currently count Unicode grapheme clusters (i.e. + /// The text field does not currently count Unicode grapheme clusters (i.e. /// characters visible to the user), it counts Unicode scalar values, which /// leaves out a number of useful possible characters (like many emoji and /// composed characters), so this will be inaccurate in the presence of those @@ -315,7 +315,7 @@ class TextField extends StatefulWidget { /// {@macro flutter.widgets.editableText.inputFormatters} final List inputFormatters; - /// If false the textfield is "disabled": it ignores taps and its + /// If false the text field is "disabled": it ignores taps and its /// [decoration] is rendered in grey. /// /// If non-null this property overrides the [decoration]'s @@ -351,24 +351,24 @@ class TextField extends StatefulWidget { return enableInteractiveSelection ?? !obscureText; } - /// Called when the user taps on this textfield. + /// Called when the user taps on this text field. /// - /// The textfield builds a [GestureDetector] to handle input events like tap, + /// The text field builds a [GestureDetector] to handle input events like tap, /// to trigger focus requests, to move the caret, adjust the selection, etc. - /// Handling some of those events by wrapping the textfield with a competing + /// Handling some of those events by wrapping the text field with a competing /// GestureDetector is problematic. /// - /// To unconditionally handle taps, without interfering with the textfield's + /// To unconditionally handle taps, without interfering with the text field's /// internal gesture detector, provide this callback. /// - /// If the textfield is created with [enabled] false, taps will not be + /// If the text field is created with [enabled] false, taps will not be /// recognized. /// - /// To be notified when the textfield gains or loses the focus, provide a + /// To be notified when the text field gains or loses the focus, provide a /// [focusNode] and add a listener to that. /// /// To listen to arbitrary pointer events without competing with the - /// textfield's internal gesture detector, use a [Listener]. + /// text field's internal gesture detector, use a [Listener]. final GestureTapCallback onTap; @override @@ -380,16 +380,25 @@ class TextField extends StatefulWidget { properties.add(DiagnosticsProperty('controller', controller, defaultValue: null)); properties.add(DiagnosticsProperty('focusNode', focusNode, defaultValue: null)); properties.add(DiagnosticsProperty('enabled', enabled, defaultValue: null)); - properties.add(DiagnosticsProperty('decoration', decoration)); + properties.add(DiagnosticsProperty('decoration', decoration, defaultValue: const InputDecoration())); properties.add(DiagnosticsProperty('keyboardType', keyboardType, defaultValue: TextInputType.text)); properties.add(DiagnosticsProperty('style', style, defaultValue: null)); properties.add(DiagnosticsProperty('autofocus', autofocus, defaultValue: false)); properties.add(DiagnosticsProperty('obscureText', obscureText, defaultValue: false)); - properties.add(DiagnosticsProperty('autocorrect', autocorrect, defaultValue: false)); + properties.add(DiagnosticsProperty('autocorrect', autocorrect, defaultValue: true)); properties.add(IntProperty('maxLines', maxLines, defaultValue: 1)); properties.add(IntProperty('maxLength', maxLength, defaultValue: null)); - properties.add(FlagProperty('maxLengthEnforced', value: maxLengthEnforced, ifTrue: 'max length enforced')); - properties.add(DiagnosticsProperty('onTap', onTap, defaultValue: false)); + properties.add(FlagProperty('maxLengthEnforced', value: maxLengthEnforced, defaultValue: true, ifFalse: 'maxLength not enforced')); + properties.add(EnumProperty('textInputAction', textInputAction, defaultValue: null)); + properties.add(EnumProperty('textCapitalization', textCapitalization, defaultValue: TextCapitalization.none)); + properties.add(EnumProperty('textAlign', textAlign, defaultValue: TextAlign.start)); + properties.add(EnumProperty('textDirection', textDirection, defaultValue: null)); + properties.add(DoubleProperty('cursorWidth', cursorWidth, defaultValue: 2.0)); + properties.add(DiagnosticsProperty('cursorRadius', cursorRadius, defaultValue: null)); + properties.add(DiagnosticsProperty('cursorColor', cursorColor, defaultValue: null)); + properties.add(DiagnosticsProperty('keyboardAppearance', keyboardAppearance, defaultValue: null)); + properties.add(DiagnosticsProperty('scrollPadding', scrollPadding, defaultValue: const EdgeInsets.all(20.0))); + properties.add(FlagProperty('selectionEnabled', value: selectionEnabled, defaultValue: true, ifFalse: 'selection disabled')); } } diff --git a/packages/flutter/test/material/text_field_test.dart b/packages/flutter/test/material/text_field_test.dart index 111b0ce96f..3e1327b326 100644 --- a/packages/flutter/test/material/text_field_test.dart +++ b/packages/flutter/test/material/text_field_test.dart @@ -4197,4 +4197,69 @@ void main() { expect(find.byType(CupertinoButton), findsNWidgets(3)); }, ); + + testWidgets('default TextField debugFillProperties', (WidgetTester tester) async { + final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); + + const TextField().debugFillProperties(builder); + + final List description = builder.properties + .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info)) + .map((DiagnosticsNode node) => node.toString()).toList(); + + expect(description, []); + }); + + testWidgets('TextField implements debugFillProperties', (WidgetTester tester) async { + final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); + + // Not checking controller, inputFormatters, focusNode + const TextField( + decoration: InputDecoration(labelText: 'foo'), + keyboardType: TextInputType.text, + textInputAction: TextInputAction.done, + textCapitalization: TextCapitalization.none, + style: TextStyle(color: Color(0xff00ff00)), + textAlign: TextAlign.end, + textDirection: TextDirection.ltr, + autofocus: true, + obscureText: true, + autocorrect: false, + maxLines: 10, + maxLength: 100, + maxLengthEnforced: false, + enabled: false, + cursorWidth: 1.0, + cursorRadius: Radius.zero, + cursorColor: Color(0xff00ff00), + keyboardAppearance: Brightness.dark, + scrollPadding: EdgeInsets.zero, + enableInteractiveSelection: false, + ).debugFillProperties(builder); + + final List description = builder.properties + .where((DiagnosticsNode node) => !node.isFiltered(DiagnosticLevel.info)) + .map((DiagnosticsNode node) => node.toString()).toList(); + + expect(description, [ + 'enabled: false', + 'decoration: InputDecoration(labelText: "foo")', + 'style: TextStyle(inherit: true, color: Color(0xff00ff00))', + 'autofocus: true', + 'obscureText: true', + 'autocorrect: false', + 'maxLines: 10', + 'maxLength: 100', + 'maxLength not enforced', + 'textInputAction: done', + 'textAlign: end', + 'textDirection: ltr', + 'cursorWidth: 1.0', + 'cursorRadius: Radius.circular(0.0)', + 'cursorColor: Color(0xff00ff00)', + 'keyboardAppearance: Brightness.dark', + 'scrollPadding: EdgeInsets.zero', + 'selection disabled' + ]); + }); }