add textCapitalization property (#19367)
This commit is contained in:
parent
eb69f59461
commit
a66ea0a628
@ -180,6 +180,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
|
||||
children: <Widget>[
|
||||
const SizedBox(height: 24.0),
|
||||
new TextFormField(
|
||||
textCapitalization: TextCapitalization.words,
|
||||
decoration: const InputDecoration(
|
||||
border: const UnderlineInputBorder(),
|
||||
filled: true,
|
||||
|
@ -103,6 +103,7 @@ class TextField extends StatefulWidget {
|
||||
this.decoration = const InputDecoration(),
|
||||
TextInputType keyboardType = TextInputType.text,
|
||||
this.textInputAction = TextInputAction.done,
|
||||
this.textCapitalization = TextCapitalization.none,
|
||||
this.style,
|
||||
this.textAlign = TextAlign.start,
|
||||
this.autofocus = false,
|
||||
@ -160,6 +161,19 @@ class TextField extends StatefulWidget {
|
||||
/// Defaults to [TextInputAction.done]. Must not be null.
|
||||
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.
|
||||
///
|
||||
/// This text style is also used as the base style for the [decoration].
|
||||
@ -509,6 +523,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
|
||||
focusNode: focusNode,
|
||||
keyboardType: widget.keyboardType,
|
||||
textInputAction: widget.textInputAction,
|
||||
textCapitalization: widget.textCapitalization,
|
||||
style: style,
|
||||
textAlign: widget.textAlign,
|
||||
autofocus: widget.autofocus,
|
||||
|
@ -55,6 +55,7 @@ class TextFormField extends FormField<String> {
|
||||
FocusNode focusNode,
|
||||
InputDecoration decoration = const InputDecoration(),
|
||||
TextInputType keyboardType = TextInputType.text,
|
||||
TextCapitalization textCapitalization = TextCapitalization.none,
|
||||
TextInputAction textInputAction = TextInputAction.done,
|
||||
TextStyle style,
|
||||
TextAlign textAlign = TextAlign.start,
|
||||
@ -101,6 +102,7 @@ class TextFormField extends FormField<String> {
|
||||
textInputAction: textInputAction,
|
||||
style: style,
|
||||
textAlign: textAlign,
|
||||
textCapitalization: textCapitalization,
|
||||
autofocus: autofocus,
|
||||
obscureText: obscureText,
|
||||
autocorrect: autocorrect,
|
||||
|
@ -314,6 +314,34 @@ enum TextInputAction {
|
||||
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.
|
||||
///
|
||||
/// Many [TextInputAction]s are common between Android and iOS. However, if an
|
||||
@ -343,11 +371,13 @@ class TextInputConfiguration {
|
||||
this.actionLabel,
|
||||
this.inputAction = TextInputAction.done,
|
||||
this.keyboardAppearance = Brightness.light,
|
||||
this.textCapitalization = TextCapitalization.none,
|
||||
}) : assert(inputType != null),
|
||||
assert(obscureText != null),
|
||||
assert(autocorrect != 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.
|
||||
final TextInputType inputType;
|
||||
@ -368,6 +398,16 @@ class TextInputConfiguration {
|
||||
/// What kind of action to request for the action button on the IME.
|
||||
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.
|
||||
///
|
||||
/// This setting is only honored on iOS devices.
|
||||
@ -383,6 +423,7 @@ class TextInputConfiguration {
|
||||
'autocorrect': autocorrect,
|
||||
'actionLabel': actionLabel,
|
||||
'inputAction': inputAction.toString(),
|
||||
'textCapitalization': textCapitalization.toString(),
|
||||
'keyboardAppearance': keyboardAppearance.toString(),
|
||||
};
|
||||
}
|
||||
|
@ -202,6 +202,7 @@ class EditableText extends StatefulWidget {
|
||||
this.selectionControls,
|
||||
TextInputType keyboardType,
|
||||
this.textInputAction = TextInputAction.done,
|
||||
this.textCapitalization = TextCapitalization.none,
|
||||
this.onChanged,
|
||||
this.onEditingComplete,
|
||||
this.onSubmitted,
|
||||
@ -269,6 +270,19 @@ class EditableText extends StatefulWidget {
|
||||
/// Defaults to the ambient [Directionality], if any.
|
||||
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
|
||||
/// be rendered differently, depending on the locale.
|
||||
///
|
||||
@ -569,6 +583,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
|
||||
inputAction: widget.keyboardType == TextInputType.multiline
|
||||
? TextInputAction.newline
|
||||
: widget.textInputAction,
|
||||
textCapitalization: widget.textCapitalization,
|
||||
)
|
||||
)..setEditingState(localValue);
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ void main() {
|
||||
expect(configuration.obscureText, false);
|
||||
expect(configuration.autocorrect, true);
|
||||
expect(configuration.actionLabel, null);
|
||||
expect(configuration.textCapitalization, TextCapitalization.none);
|
||||
expect(configuration.keyboardAppearance, Brightness.light);
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user