From 21712a49a76af0fab63246a9acbe61f3e1928070 Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Mon, 8 May 2017 17:38:22 -0700 Subject: [PATCH] Add obscureText field to TextInputConfiguration (#9908) Provides a cue to the engine to disable auto-correct/suggest. --- .../flutter/lib/src/services/text_input.dart | 12 ++++++-- .../lib/src/widgets/editable_text.dart | 2 +- .../test/services/text_input_test.dart | 29 +++++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 packages/flutter/test/services/text_input_test.dart diff --git a/packages/flutter/lib/src/services/text_input.dart b/packages/flutter/lib/src/services/text_input.dart index 6189235968..828c9a1623 100644 --- a/packages/flutter/lib/src/services/text_input.dart +++ b/packages/flutter/lib/src/services/text_input.dart @@ -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 toJSON() { return { 'inputType': inputType.toString(), + 'obscureText': obscureText.toString(), 'actionLabel': actionLabel, }; } diff --git a/packages/flutter/lib/src/widgets/editable_text.dart b/packages/flutter/lib/src/widgets/editable_text.dart index 16ad31bf11..4f69154204 100644 --- a/packages/flutter/lib/src/widgets/editable_text.dart +++ b/packages/flutter/lib/src/widgets/editable_text.dart @@ -348,7 +348,7 @@ class EditableTextState extends State 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(); diff --git a/packages/flutter/test/services/text_input_test.dart b/packages/flutter/test/services/text_input_test.dart new file mode 100644 index 0000000000..0de06492f8 --- /dev/null +++ b/packages/flutter/test/services/text_input_test.dart @@ -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 json = configuration.toJSON(); + expect(json['inputType'], 'TextInputType.number'); + expect(json['obscureText'], 'true'); + expect(json['actionLabel'], 'xyzzy'); + }); + }); +}