Unverified Commit 109f2558 authored by Justin McCandless's avatar Justin McCandless Committed by GitHub

No multiline password fields (#42470)

Use assertions to prevent multiline password fields from being created
parent 8017f63b
...@@ -274,6 +274,7 @@ class CupertinoTextField extends StatefulWidget { ...@@ -274,6 +274,7 @@ class CupertinoTextField extends StatefulWidget {
!expands || (maxLines == null && minLines == null), !expands || (maxLines == null && minLines == null),
'minLines and maxLines must be null when expands is true.', 'minLines and maxLines must be null when expands is true.',
), ),
assert(!obscureText || maxLines == 1, 'Obscured fields cannot be multiline.'),
assert(maxLength == null || maxLength > 0), assert(maxLength == null || maxLength > 0),
assert(clearButtonMode != null), assert(clearButtonMode != null),
assert(prefixMode != null), assert(prefixMode != null),
......
...@@ -344,6 +344,7 @@ class TextField extends StatefulWidget { ...@@ -344,6 +344,7 @@ class TextField extends StatefulWidget {
!expands || (maxLines == null && minLines == null), !expands || (maxLines == null && minLines == null),
'minLines and maxLines must be null when expands is true.', 'minLines and maxLines must be null when expands is true.',
), ),
assert(!obscureText || maxLines == 1, 'Obscured fields cannot be multiline.'),
assert(maxLength == null || maxLength == TextField.noMaxLength || maxLength > 0), assert(maxLength == null || maxLength == TextField.noMaxLength || maxLength > 0),
keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline), keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline),
toolbarOptions = toolbarOptions ?? (obscureText ? toolbarOptions = toolbarOptions ?? (obscureText ?
......
...@@ -139,6 +139,7 @@ class TextFormField extends FormField<String> { ...@@ -139,6 +139,7 @@ class TextFormField extends FormField<String> {
!expands || (maxLines == null && minLines == null), !expands || (maxLines == null && minLines == null),
'minLines and maxLines must be null when expands is true.', 'minLines and maxLines must be null when expands is true.',
), ),
assert(!obscureText || maxLines == 1, 'Obscured fields cannot be multiline.'),
assert(maxLength == null || maxLength > 0), assert(maxLength == null || maxLength > 0),
assert(enableInteractiveSelection != null), assert(enableInteractiveSelection != null),
super( super(
......
...@@ -422,6 +422,7 @@ class EditableText extends StatefulWidget { ...@@ -422,6 +422,7 @@ class EditableText extends StatefulWidget {
!expands || (maxLines == null && minLines == null), !expands || (maxLines == null && minLines == null),
'minLines and maxLines must be null when expands is true.', 'minLines and maxLines must be null when expands is true.',
), ),
assert(!obscureText || maxLines == 1, 'Obscured fields cannot be multiline.'),
assert(autofocus != null), assert(autofocus != null),
assert(rendererIgnoresPointer != null), assert(rendererIgnoresPointer != null),
assert(scrollPadding != null), assert(scrollPadding != null),
......
...@@ -6530,7 +6530,7 @@ void main() { ...@@ -6530,7 +6530,7 @@ void main() {
textAlign: TextAlign.end, textAlign: TextAlign.end,
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
autofocus: true, autofocus: true,
obscureText: true, obscureText: false,
autocorrect: false, autocorrect: false,
maxLines: 10, maxLines: 10,
maxLength: 100, maxLength: 100,
...@@ -6554,7 +6554,6 @@ void main() { ...@@ -6554,7 +6554,6 @@ void main() {
'decoration: InputDecoration(labelText: "foo")', 'decoration: InputDecoration(labelText: "foo")',
'style: TextStyle(inherit: true, color: Color(0xff00ff00))', 'style: TextStyle(inherit: true, color: Color(0xff00ff00))',
'autofocus: true', 'autofocus: true',
'obscureText: true',
'autocorrect: false', 'autocorrect: false',
'maxLines: 10', 'maxLines: 10',
'maxLength: 100', 'maxLength: 100',
......
...@@ -3350,6 +3350,38 @@ void main() { ...@@ -3350,6 +3350,38 @@ void main() {
expect(scrollable.controller.position.pixels, equals(14)); expect(scrollable.controller.position.pixels, equals(14));
expect(scrollable.controller.position.pixels, equals(renderEditable.maxScrollExtent)); expect(scrollable.controller.position.pixels, equals(renderEditable.maxScrollExtent));
}, skip: isBrowser); }, skip: isBrowser);
testWidgets('obscured multiline fields throw an exception', (WidgetTester tester) async {
final TextEditingController controller = TextEditingController();
expect(
() {
EditableText(
backgroundCursorColor: cursorColor,
controller: controller,
cursorColor: cursorColor,
focusNode: focusNode,
maxLines: 1,
obscureText: true,
style: textStyle,
);
},
returnsNormally,
);
expect(
() {
EditableText(
backgroundCursorColor: cursorColor,
controller: controller,
cursorColor: cursorColor,
focusNode: focusNode,
maxLines: 2,
obscureText: true,
style: textStyle,
);
},
throwsAssertionError,
);
});
} }
class MockTextSelectionControls extends Mock implements TextSelectionControls { class MockTextSelectionControls extends Mock implements TextSelectionControls {
......
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