Commit 21712a49 authored by Chris Bracken's avatar Chris Bracken Committed by GitHub

Add obscureText field to TextInputConfiguration (#9908)

Provides a cue to the engine to disable auto-correct/suggest.
parent ca4d7211
...@@ -43,15 +43,22 @@ enum TextInputAction { ...@@ -43,15 +43,22 @@ enum TextInputAction {
class TextInputConfiguration { class TextInputConfiguration {
/// Creates configuration information for a text input control. /// 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({ const TextInputConfiguration({
this.inputType: TextInputType.text, this.inputType: TextInputType.text,
this.obscureText: false,
this.actionLabel, this.actionLabel,
}) : assert(inputType != null); }) : assert(inputType != null),
assert(obscureText != 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;
/// 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. /// What text to display in the text input control's action button.
final String actionLabel; final String actionLabel;
...@@ -59,6 +66,7 @@ class TextInputConfiguration { ...@@ -59,6 +66,7 @@ class TextInputConfiguration {
Map<String, dynamic> toJSON() { Map<String, dynamic> toJSON() {
return <String, dynamic>{ return <String, dynamic>{
'inputType': inputType.toString(), 'inputType': inputType.toString(),
'obscureText': obscureText.toString(),
'actionLabel': actionLabel, 'actionLabel': actionLabel,
}; };
} }
......
...@@ -348,7 +348,7 @@ class EditableTextState extends State<EditableText> implements TextInputClient { ...@@ -348,7 +348,7 @@ class EditableTextState extends State<EditableText> implements TextInputClient {
if (!_hasInputConnection) { if (!_hasInputConnection) {
final TextEditingValue localValue = _value; final TextEditingValue localValue = _value;
_lastKnownRemoteTextEditingValue = localValue; _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); ..setEditingState(localValue);
} }
_textInputConnection.show(); _textInputConnection.show();
......
// 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');
});
});
}
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