Commit 6fbe39e2 authored by Adam Barth's avatar Adam Barth

Merge pull request #645 from abarth/hide_text

Add input#hideText
parents 3b278c56 179d191e
...@@ -21,6 +21,7 @@ class Input extends Scrollable { ...@@ -21,6 +21,7 @@ class Input extends Scrollable {
GlobalKey key, GlobalKey key,
this.initialValue: '', this.initialValue: '',
this.placeholder, this.placeholder,
this.hideText: false,
this.onChanged, this.onChanged,
this.keyboardType: KeyboardType.TEXT, this.keyboardType: KeyboardType.TEXT,
this.onSubmitted this.onSubmitted
...@@ -33,6 +34,7 @@ class Input extends Scrollable { ...@@ -33,6 +34,7 @@ class Input extends Scrollable {
final String initialValue; final String initialValue;
final KeyboardType keyboardType; final KeyboardType keyboardType;
final String placeholder; final String placeholder;
final bool hideText;
final ValueChanged<String> onChanged; final ValueChanged<String> onChanged;
final ValueChanged<String> onSubmitted; final ValueChanged<String> onSubmitted;
...@@ -110,6 +112,7 @@ class InputState extends ScrollableState<Input> { ...@@ -110,6 +112,7 @@ class InputState extends ScrollableState<Input> {
value: _editableValue, value: _editableValue,
focused: focused, focused: focused,
style: textStyle, style: textStyle,
hideText: config.hideText,
cursorColor: cursorColor, cursorColor: cursorColor,
onContentSizeChanged: _handleContentSizeChanged, onContentSizeChanged: _handleContentSizeChanged,
scrollOffset: scrollOffsetVector scrollOffset: scrollOffsetVector
......
...@@ -144,6 +144,7 @@ class EditableText extends StatefulComponent { ...@@ -144,6 +144,7 @@ class EditableText extends StatefulComponent {
Key key, Key key,
this.value, this.value,
this.focused: false, this.focused: false,
this.hideText: false,
this.style, this.style,
this.cursorColor, this.cursorColor,
this.onContentSizeChanged, this.onContentSizeChanged,
...@@ -152,6 +153,7 @@ class EditableText extends StatefulComponent { ...@@ -152,6 +153,7 @@ class EditableText extends StatefulComponent {
final EditableString value; final EditableString value;
final bool focused; final bool focused;
final bool hideText;
final TextStyle style; final TextStyle style;
final Color cursorColor; final Color cursorColor;
final SizeChangedCallback onContentSizeChanged; final SizeChangedCallback onContentSizeChanged;
...@@ -216,6 +218,7 @@ class EditableTextState extends State<EditableText> { ...@@ -216,6 +218,7 @@ class EditableTextState extends State<EditableText> {
style: config.style, style: config.style,
cursorColor: config.cursorColor, cursorColor: config.cursorColor,
showCursor: _showCursor, showCursor: _showCursor,
hideText: config.hideText,
onContentSizeChanged: config.onContentSizeChanged, onContentSizeChanged: config.onContentSizeChanged,
scrollOffset: config.scrollOffset scrollOffset: config.scrollOffset
) )
...@@ -232,6 +235,7 @@ class _EditableTextWidget extends LeafRenderObjectWidget { ...@@ -232,6 +235,7 @@ class _EditableTextWidget extends LeafRenderObjectWidget {
this.style, this.style,
this.cursorColor, this.cursorColor,
this.showCursor, this.showCursor,
this.hideText,
this.onContentSizeChanged, this.onContentSizeChanged,
this.scrollOffset this.scrollOffset
}) : super(key: key); }) : super(key: key);
...@@ -240,6 +244,7 @@ class _EditableTextWidget extends LeafRenderObjectWidget { ...@@ -240,6 +244,7 @@ class _EditableTextWidget extends LeafRenderObjectWidget {
final TextStyle style; final TextStyle style;
final Color cursorColor; final Color cursorColor;
final bool showCursor; final bool showCursor;
final bool hideText;
final SizeChangedCallback onContentSizeChanged; final SizeChangedCallback onContentSizeChanged;
final Offset scrollOffset; final Offset scrollOffset;
...@@ -264,7 +269,7 @@ class _EditableTextWidget extends LeafRenderObjectWidget { ...@@ -264,7 +269,7 @@ class _EditableTextWidget extends LeafRenderObjectWidget {
// Construct a TextSpan that renders the EditableString using the chosen style. // Construct a TextSpan that renders the EditableString using the chosen style.
TextSpan _buildTextSpan() { TextSpan _buildTextSpan() {
if (value.composing.isValid) { if (!hideText && value.composing.isValid) {
TextStyle composingStyle = style.merge( TextStyle composingStyle = style.merge(
const TextStyle(decoration: underline) const TextStyle(decoration: underline)
); );
...@@ -279,6 +284,8 @@ class _EditableTextWidget extends LeafRenderObjectWidget { ...@@ -279,6 +284,8 @@ class _EditableTextWidget extends LeafRenderObjectWidget {
} }
String text = value.text; String text = value.text;
if (hideText)
text = new String.fromCharCodes(new List<int>.filled(text.length, 0x2022));
return new StyledTextSpan(style, <TextSpan>[ return new StyledTextSpan(style, <TextSpan>[
new PlainTextSpan(text.isEmpty ? _kZeroWidthSpace : text) new PlainTextSpan(text.isEmpty ? _kZeroWidthSpace : text)
]); ]);
......
...@@ -138,4 +138,27 @@ void main() { ...@@ -138,4 +138,27 @@ void main() {
expect(input.editableValue.selection.start, equals(0)); expect(input.editableValue.selection.start, equals(0));
}); });
}); });
test('hideText control test', () {
testWidgets((WidgetTester tester) {
GlobalKey inputKey = new GlobalKey();
Widget builder() {
return new Center(
child: new Input(
key: inputKey,
hideText: true,
placeholder: 'Placeholder'
)
);
}
tester.pumpWidget(builder());
const String testValue = 'ABC';
mockKeyboard.client.commitText(testValue, testValue.length);
tester.pump();
});
});
} }
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