Support keyboardAppearance field for iOS (#19244)
This commit is contained in:
parent
2f0b4158ab
commit
1b35cc2cc2
@ -115,6 +115,7 @@ class TextField extends StatefulWidget {
|
|||||||
this.onSubmitted,
|
this.onSubmitted,
|
||||||
this.inputFormatters,
|
this.inputFormatters,
|
||||||
this.enabled,
|
this.enabled,
|
||||||
|
this.keyboardAppearance,
|
||||||
}) : assert(keyboardType != null),
|
}) : assert(keyboardType != null),
|
||||||
assert(textInputAction != null),
|
assert(textInputAction != null),
|
||||||
assert(textAlign != null),
|
assert(textAlign != null),
|
||||||
@ -278,6 +279,13 @@ class TextField extends StatefulWidget {
|
|||||||
/// [Decoration.enabled] property.
|
/// [Decoration.enabled] property.
|
||||||
final bool enabled;
|
final bool enabled;
|
||||||
|
|
||||||
|
/// The appearance of the keyboard.
|
||||||
|
///
|
||||||
|
/// This setting is only honored on iOS devices.
|
||||||
|
///
|
||||||
|
/// If unset, defaults to the brightness of [ThemeData.primaryColorBrightness].
|
||||||
|
final Brightness keyboardAppearance;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_TextFieldState createState() => new _TextFieldState();
|
_TextFieldState createState() => new _TextFieldState();
|
||||||
|
|
||||||
@ -468,6 +476,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
|
|||||||
assert(debugCheckHasMaterial(context));
|
assert(debugCheckHasMaterial(context));
|
||||||
final ThemeData themeData = Theme.of(context);
|
final ThemeData themeData = Theme.of(context);
|
||||||
final TextStyle style = widget.style ?? themeData.textTheme.subhead;
|
final TextStyle style = widget.style ?? themeData.textTheme.subhead;
|
||||||
|
final Brightness keyboardAppearance = widget.keyboardAppearance ?? themeData.primaryColorBrightness;
|
||||||
final TextEditingController controller = _effectiveController;
|
final TextEditingController controller = _effectiveController;
|
||||||
final FocusNode focusNode = _effectiveFocusNode;
|
final FocusNode focusNode = _effectiveFocusNode;
|
||||||
final List<TextInputFormatter> formatters = widget.inputFormatters ?? <TextInputFormatter>[];
|
final List<TextInputFormatter> formatters = widget.inputFormatters ?? <TextInputFormatter>[];
|
||||||
@ -497,6 +506,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
|
|||||||
onSelectionChanged: _handleSelectionChanged,
|
onSelectionChanged: _handleSelectionChanged,
|
||||||
inputFormatters: formatters,
|
inputFormatters: formatters,
|
||||||
rendererIgnoresPointer: true,
|
rendererIgnoresPointer: true,
|
||||||
|
keyboardAppearance: keyboardAppearance,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -69,6 +69,7 @@ class TextFormField extends FormField<String> {
|
|||||||
FormFieldValidator<String> validator,
|
FormFieldValidator<String> validator,
|
||||||
List<TextInputFormatter> inputFormatters,
|
List<TextInputFormatter> inputFormatters,
|
||||||
bool enabled,
|
bool enabled,
|
||||||
|
Brightness keyboardAppearance,
|
||||||
}) : assert(initialValue == null || controller == null),
|
}) : assert(initialValue == null || controller == null),
|
||||||
assert(keyboardType != null),
|
assert(keyboardType != null),
|
||||||
assert(textAlign != null),
|
assert(textAlign != null),
|
||||||
@ -106,6 +107,7 @@ class TextFormField extends FormField<String> {
|
|||||||
onSubmitted: onFieldSubmitted,
|
onSubmitted: onFieldSubmitted,
|
||||||
inputFormatters: inputFormatters,
|
inputFormatters: inputFormatters,
|
||||||
enabled: enabled,
|
enabled: enabled,
|
||||||
|
keyboardAppearance: keyboardAppearance,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -10,6 +10,7 @@ import 'package:flutter/foundation.dart';
|
|||||||
|
|
||||||
import 'message_codec.dart';
|
import 'message_codec.dart';
|
||||||
import 'system_channels.dart';
|
import 'system_channels.dart';
|
||||||
|
import 'system_chrome.dart';
|
||||||
import 'text_editing.dart';
|
import 'text_editing.dart';
|
||||||
|
|
||||||
export 'dart:ui' show TextAffinity;
|
export 'dart:ui' show TextAffinity;
|
||||||
@ -104,7 +105,7 @@ class TextInputType {
|
|||||||
String get _name => 'TextInputType.${_names[index]}';
|
String get _name => 'TextInputType.${_names[index]}';
|
||||||
|
|
||||||
/// Returns a representation of this object as a JSON object.
|
/// Returns a representation of this object as a JSON object.
|
||||||
Map<String, dynamic> toJSON() {
|
Map<String, dynamic> toJson() {
|
||||||
return <String, dynamic>{
|
return <String, dynamic>{
|
||||||
'name': _name,
|
'name': _name,
|
||||||
'signed': signed,
|
'signed': signed,
|
||||||
@ -341,9 +342,11 @@ class TextInputConfiguration {
|
|||||||
this.autocorrect = true,
|
this.autocorrect = true,
|
||||||
this.actionLabel,
|
this.actionLabel,
|
||||||
this.inputAction = TextInputAction.done,
|
this.inputAction = TextInputAction.done,
|
||||||
|
this.keyboardAppearance = Brightness.light,
|
||||||
}) : assert(inputType != null),
|
}) : assert(inputType != null),
|
||||||
assert(obscureText != null),
|
assert(obscureText != null),
|
||||||
assert(autocorrect != null),
|
assert(autocorrect != null),
|
||||||
|
assert(keyboardAppearance != null),
|
||||||
assert(inputAction != null);
|
assert(inputAction != 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.
|
||||||
@ -365,14 +368,22 @@ 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;
|
||||||
|
|
||||||
|
/// The appearance of the keyboard.
|
||||||
|
///
|
||||||
|
/// This setting is only honored on iOS devices.
|
||||||
|
///
|
||||||
|
/// Defaults to [Brightness.light].
|
||||||
|
final Brightness keyboardAppearance;
|
||||||
|
|
||||||
/// Returns a representation of this object as a JSON object.
|
/// Returns a representation of this object as a JSON object.
|
||||||
Map<String, dynamic> toJSON() {
|
Map<String, dynamic> toJson() {
|
||||||
return <String, dynamic>{
|
return <String, dynamic>{
|
||||||
'inputType': inputType.toJSON(),
|
'inputType': inputType.toJson(),
|
||||||
'obscureText': obscureText,
|
'obscureText': obscureText,
|
||||||
'autocorrect': autocorrect,
|
'autocorrect': autocorrect,
|
||||||
'actionLabel': actionLabel,
|
'actionLabel': actionLabel,
|
||||||
'inputAction': inputAction.toString(),
|
'inputAction': inputAction.toString(),
|
||||||
|
'keyboardAppearance': keyboardAppearance.toString(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -675,7 +686,7 @@ class TextInput {
|
|||||||
_clientHandler._currentConnection = connection;
|
_clientHandler._currentConnection = connection;
|
||||||
SystemChannels.textInput.invokeMethod(
|
SystemChannels.textInput.invokeMethod(
|
||||||
'TextInput.setClient',
|
'TextInput.setClient',
|
||||||
<dynamic>[ connection._id, configuration.toJSON() ],
|
<dynamic>[ connection._id, configuration.toJson() ],
|
||||||
);
|
);
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
@ -210,6 +210,7 @@ class EditableText extends StatefulWidget {
|
|||||||
this.rendererIgnoresPointer = false,
|
this.rendererIgnoresPointer = false,
|
||||||
this.cursorWidth = 1.0,
|
this.cursorWidth = 1.0,
|
||||||
this.cursorRadius,
|
this.cursorRadius,
|
||||||
|
this.keyboardAppearance = Brightness.light,
|
||||||
}) : assert(controller != null),
|
}) : assert(controller != null),
|
||||||
assert(focusNode != null),
|
assert(focusNode != null),
|
||||||
assert(obscureText != null),
|
assert(obscureText != null),
|
||||||
@ -365,6 +366,13 @@ class EditableText extends StatefulWidget {
|
|||||||
/// By default, the cursor has a Radius of zero.
|
/// By default, the cursor has a Radius of zero.
|
||||||
final Radius cursorRadius;
|
final Radius cursorRadius;
|
||||||
|
|
||||||
|
/// The appearance of the keyboard.
|
||||||
|
///
|
||||||
|
/// This setting is only honored on iOS devices.
|
||||||
|
///
|
||||||
|
/// Defaults to [Brightness.light].
|
||||||
|
final Brightness keyboardAppearance;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
EditableTextState createState() => new EditableTextState();
|
EditableTextState createState() => new EditableTextState();
|
||||||
|
|
||||||
@ -557,6 +565,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
|
|||||||
inputType: widget.keyboardType,
|
inputType: widget.keyboardType,
|
||||||
obscureText: widget.obscureText,
|
obscureText: widget.obscureText,
|
||||||
autocorrect: widget.autocorrect,
|
autocorrect: widget.autocorrect,
|
||||||
|
keyboardAppearance: widget.keyboardAppearance,
|
||||||
inputAction: widget.keyboardType == TextInputType.multiline
|
inputAction: widget.keyboardType == TextInputType.multiline
|
||||||
? TextInputAction.newline
|
? TextInputAction.newline
|
||||||
: widget.textInputAction,
|
: widget.textInputAction,
|
||||||
|
@ -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.keyboardAppearance, Brightness.light);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('text serializes to JSON', () async {
|
test('text serializes to JSON', () async {
|
||||||
@ -22,7 +23,7 @@ void main() {
|
|||||||
autocorrect: false,
|
autocorrect: false,
|
||||||
actionLabel: 'xyzzy',
|
actionLabel: 'xyzzy',
|
||||||
);
|
);
|
||||||
final Map<String, dynamic> json = configuration.toJSON();
|
final Map<String, dynamic> json = configuration.toJson();
|
||||||
expect(json['inputType'], <String, dynamic>{
|
expect(json['inputType'], <String, dynamic>{
|
||||||
'name': 'TextInputType.text', 'signed': null, 'decimal': null
|
'name': 'TextInputType.text', 'signed': null, 'decimal': null
|
||||||
});
|
});
|
||||||
@ -38,7 +39,7 @@ void main() {
|
|||||||
autocorrect: false,
|
autocorrect: false,
|
||||||
actionLabel: 'xyzzy',
|
actionLabel: 'xyzzy',
|
||||||
);
|
);
|
||||||
final Map<String, dynamic> json = configuration.toJSON();
|
final Map<String, dynamic> json = configuration.toJson();
|
||||||
expect(json['inputType'], <String, dynamic>{
|
expect(json['inputType'], <String, dynamic>{
|
||||||
'name': 'TextInputType.number', 'signed': false, 'decimal': true
|
'name': 'TextInputType.number', 'signed': false, 'decimal': true
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user