Add obscureText field to TextInputConfiguration (#9908)
Provides a cue to the engine to disable auto-correct/suggest.
This commit is contained in:
@@ -43,15 +43,22 @@ enum TextInputAction {
|
||||
class TextInputConfiguration {
|
||||
/// Creates configuration information for a text input control.
|
||||
///
|
||||
/// The [inputType] argument must not be null.
|
||||
/// The [inputType] and [obscureText] arguments must not be null.
|
||||
const TextInputConfiguration({
|
||||
this.inputType: TextInputType.text,
|
||||
this.obscureText: false,
|
||||
this.actionLabel,
|
||||
}) : assert(inputType != null);
|
||||
}) : assert(inputType != null),
|
||||
assert(obscureText != null);
|
||||
|
||||
/// The type of information for which to optimize the text input control.
|
||||
final TextInputType inputType;
|
||||
|
||||
/// Whether to hide the text being edited (e.g., for passwords).
|
||||
///
|
||||
/// Defaults to false.
|
||||
final bool obscureText;
|
||||
|
||||
/// What text to display in the text input control's action button.
|
||||
final String actionLabel;
|
||||
|
||||
@@ -59,6 +66,7 @@ class TextInputConfiguration {
|
||||
Map<String, dynamic> toJSON() {
|
||||
return <String, dynamic>{
|
||||
'inputType': inputType.toString(),
|
||||
'obscureText': obscureText.toString(),
|
||||
'actionLabel': actionLabel,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -348,7 +348,7 @@ class EditableTextState extends State<EditableText> implements TextInputClient {
|
||||
if (!_hasInputConnection) {
|
||||
final TextEditingValue localValue = _value;
|
||||
_lastKnownRemoteTextEditingValue = localValue;
|
||||
_textInputConnection = TextInput.attach(this, new TextInputConfiguration(inputType: widget.keyboardType))
|
||||
_textInputConnection = TextInput.attach(this, new TextInputConfiguration(inputType: widget.keyboardType, obscureText: widget.obscureText))
|
||||
..setEditingState(localValue);
|
||||
}
|
||||
_textInputConnection.show();
|
||||
|
||||
29
packages/flutter/test/services/text_input_test.dart
Normal file
29
packages/flutter/test/services/text_input_test.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
// Copyright 2017 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group('TextInputConfiguration', () {
|
||||
test('sets expected defaults', () {
|
||||
final TextInputConfiguration configuration = const TextInputConfiguration();
|
||||
expect(configuration.inputType, TextInputType.text);
|
||||
expect(configuration.obscureText, false);
|
||||
expect(configuration.actionLabel, null);
|
||||
});
|
||||
|
||||
test('serializes to JSON', () async {
|
||||
final TextInputConfiguration configuration = const TextInputConfiguration(
|
||||
inputType: TextInputType.number,
|
||||
obscureText: true,
|
||||
actionLabel: 'xyzzy'
|
||||
);
|
||||
final Map<String, dynamic> json = configuration.toJSON();
|
||||
expect(json['inputType'], 'TextInputType.number');
|
||||
expect(json['obscureText'], 'true');
|
||||
expect(json['actionLabel'], 'xyzzy');
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user