Unverified Commit a66ea0a6 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

add textCapitalization property (#19367)

parent eb69f594
...@@ -180,6 +180,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> { ...@@ -180,6 +180,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
children: <Widget>[ children: <Widget>[
const SizedBox(height: 24.0), const SizedBox(height: 24.0),
new TextFormField( new TextFormField(
textCapitalization: TextCapitalization.words,
decoration: const InputDecoration( decoration: const InputDecoration(
border: const UnderlineInputBorder(), border: const UnderlineInputBorder(),
filled: true, filled: true,
......
...@@ -103,6 +103,7 @@ class TextField extends StatefulWidget { ...@@ -103,6 +103,7 @@ class TextField extends StatefulWidget {
this.decoration = const InputDecoration(), this.decoration = const InputDecoration(),
TextInputType keyboardType = TextInputType.text, TextInputType keyboardType = TextInputType.text,
this.textInputAction = TextInputAction.done, this.textInputAction = TextInputAction.done,
this.textCapitalization = TextCapitalization.none,
this.style, this.style,
this.textAlign = TextAlign.start, this.textAlign = TextAlign.start,
this.autofocus = false, this.autofocus = false,
...@@ -160,6 +161,19 @@ class TextField extends StatefulWidget { ...@@ -160,6 +161,19 @@ class TextField extends StatefulWidget {
/// Defaults to [TextInputAction.done]. Must not be null. /// Defaults to [TextInputAction.done]. Must not be null.
final TextInputAction textInputAction; final TextInputAction textInputAction;
/// Configures how the platform keyboard will select an uppercase or
/// lowercase keyboard.
///
/// Only supports text keyboards, other keyboard types will ignore this
/// configuration. Capitalization is locale-aware.
///
/// Defaults to [TextCapitalization.none]. Must not be null.
///
/// See also:
///
/// * [TextCapitalization], for a description of each capitalization behavior.
final TextCapitalization textCapitalization;
/// The style to use for the text being edited. /// The style to use for the text being edited.
/// ///
/// This text style is also used as the base style for the [decoration]. /// This text style is also used as the base style for the [decoration].
...@@ -509,6 +523,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi ...@@ -509,6 +523,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
focusNode: focusNode, focusNode: focusNode,
keyboardType: widget.keyboardType, keyboardType: widget.keyboardType,
textInputAction: widget.textInputAction, textInputAction: widget.textInputAction,
textCapitalization: widget.textCapitalization,
style: style, style: style,
textAlign: widget.textAlign, textAlign: widget.textAlign,
autofocus: widget.autofocus, autofocus: widget.autofocus,
......
...@@ -55,6 +55,7 @@ class TextFormField extends FormField<String> { ...@@ -55,6 +55,7 @@ class TextFormField extends FormField<String> {
FocusNode focusNode, FocusNode focusNode,
InputDecoration decoration = const InputDecoration(), InputDecoration decoration = const InputDecoration(),
TextInputType keyboardType = TextInputType.text, TextInputType keyboardType = TextInputType.text,
TextCapitalization textCapitalization = TextCapitalization.none,
TextInputAction textInputAction = TextInputAction.done, TextInputAction textInputAction = TextInputAction.done,
TextStyle style, TextStyle style,
TextAlign textAlign = TextAlign.start, TextAlign textAlign = TextAlign.start,
...@@ -101,6 +102,7 @@ class TextFormField extends FormField<String> { ...@@ -101,6 +102,7 @@ class TextFormField extends FormField<String> {
textInputAction: textInputAction, textInputAction: textInputAction,
style: style, style: style,
textAlign: textAlign, textAlign: textAlign,
textCapitalization: textCapitalization,
autofocus: autofocus, autofocus: autofocus,
obscureText: obscureText, obscureText: obscureText,
autocorrect: autocorrect, autocorrect: autocorrect,
......
...@@ -314,6 +314,34 @@ enum TextInputAction { ...@@ -314,6 +314,34 @@ enum TextInputAction {
newline, newline,
} }
/// Configures how the platform keyboard will select an uppercase or
/// lowercase keyboard.
///
/// Only supports text keyboards, other keyboard types will ignore this
/// configuration. Capitalization is locale-aware.
enum TextCapitalization {
/// Defaults to an uppercase keyboard for the first letter of each word.
///
/// Corresponds to `InputType.TYPE_TEXT_FLAG_CAP_WORDS` on Android, and
/// `UITextAutocapitalizationTypeWords` on iOS.
words,
/// Defaults to an uppercase keyboard for the first letter of each sentence.
///
/// Corresponds to `InputType.TYPE_TEXT_FLAG_CAP_SENTENCES` on Android, and
/// `UITextAutocapitalizationTypeSentences` on iOS.
sentences,
/// Defaults to an uppercase keyboard for each character.
///
/// Corresponds to `InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS` on Android, and
/// `UITextAutocapitalizationTypeAllCharacters` on iOS.
characters,
/// Defaults to a lowercase keyboard.
none,
}
/// Controls the visual appearance of the text input control. /// Controls the visual appearance of the text input control.
/// ///
/// Many [TextInputAction]s are common between Android and iOS. However, if an /// Many [TextInputAction]s are common between Android and iOS. However, if an
...@@ -343,11 +371,13 @@ class TextInputConfiguration { ...@@ -343,11 +371,13 @@ class TextInputConfiguration {
this.actionLabel, this.actionLabel,
this.inputAction = TextInputAction.done, this.inputAction = TextInputAction.done,
this.keyboardAppearance = Brightness.light, this.keyboardAppearance = Brightness.light,
this.textCapitalization = TextCapitalization.none,
}) : assert(inputType != null), }) : assert(inputType != null),
assert(obscureText != null), assert(obscureText != null),
assert(autocorrect != null), assert(autocorrect != null),
assert(keyboardAppearance != null), assert(keyboardAppearance != null),
assert(inputAction != null); assert(inputAction != null),
assert(textCapitalization != null);
/// The type of information for which to optimize the text input control. /// The type of information for which to optimize the text input control.
final TextInputType inputType; final TextInputType inputType;
...@@ -368,6 +398,16 @@ class TextInputConfiguration { ...@@ -368,6 +398,16 @@ class TextInputConfiguration {
/// What kind of action to request for the action button on the IME. /// What kind of action to request for the action button on the IME.
final TextInputAction inputAction; final TextInputAction inputAction;
/// Specifies how platforms may automatically capitialize text entered by the
/// user.
///
/// Defaults to [TextCapitalization.none].
///
/// See also:
///
/// * [TextCapitalization], for a description of each capitalization behavior.
final TextCapitalization textCapitalization;
/// The appearance of the keyboard. /// The appearance of the keyboard.
/// ///
/// This setting is only honored on iOS devices. /// This setting is only honored on iOS devices.
...@@ -383,6 +423,7 @@ class TextInputConfiguration { ...@@ -383,6 +423,7 @@ class TextInputConfiguration {
'autocorrect': autocorrect, 'autocorrect': autocorrect,
'actionLabel': actionLabel, 'actionLabel': actionLabel,
'inputAction': inputAction.toString(), 'inputAction': inputAction.toString(),
'textCapitalization': textCapitalization.toString(),
'keyboardAppearance': keyboardAppearance.toString(), 'keyboardAppearance': keyboardAppearance.toString(),
}; };
} }
......
...@@ -202,6 +202,7 @@ class EditableText extends StatefulWidget { ...@@ -202,6 +202,7 @@ class EditableText extends StatefulWidget {
this.selectionControls, this.selectionControls,
TextInputType keyboardType, TextInputType keyboardType,
this.textInputAction = TextInputAction.done, this.textInputAction = TextInputAction.done,
this.textCapitalization = TextCapitalization.none,
this.onChanged, this.onChanged,
this.onEditingComplete, this.onEditingComplete,
this.onSubmitted, this.onSubmitted,
...@@ -269,6 +270,19 @@ class EditableText extends StatefulWidget { ...@@ -269,6 +270,19 @@ class EditableText extends StatefulWidget {
/// Defaults to the ambient [Directionality], if any. /// Defaults to the ambient [Directionality], if any.
final TextDirection textDirection; final TextDirection textDirection;
/// Configures how the platform keyboard will select an uppercase or
/// lowercase keyboard.
///
/// Only supports text keyboards, other keyboard types will ignore this
/// configuration. Capitalization is locale-aware.
///
/// Defaults to [TextCapitalization.none]. Must not be null.
///
/// See also:
///
/// * [TextCapitalization], for a description of each capitalization behavior.
final TextCapitalization textCapitalization;
/// Used to select a font when the same Unicode character can /// Used to select a font when the same Unicode character can
/// be rendered differently, depending on the locale. /// be rendered differently, depending on the locale.
/// ///
...@@ -569,6 +583,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien ...@@ -569,6 +583,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
inputAction: widget.keyboardType == TextInputType.multiline inputAction: widget.keyboardType == TextInputType.multiline
? TextInputAction.newline ? TextInputAction.newline
: widget.textInputAction, : widget.textInputAction,
textCapitalization: widget.textCapitalization,
) )
)..setEditingState(localValue); )..setEditingState(localValue);
} }
......
...@@ -13,6 +13,7 @@ void main() { ...@@ -13,6 +13,7 @@ void main() {
expect(configuration.obscureText, false); expect(configuration.obscureText, false);
expect(configuration.autocorrect, true); expect(configuration.autocorrect, true);
expect(configuration.actionLabel, null); expect(configuration.actionLabel, null);
expect(configuration.textCapitalization, TextCapitalization.none);
expect(configuration.keyboardAppearance, Brightness.light); expect(configuration.keyboardAppearance, Brightness.light);
}); });
......
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