mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Prevent use of TextInputType.text when also using TextInputAction.newLine via assert (#55636)
This commit is contained in:
parent
b7fd24a7dc
commit
6cf9c7cc17
@ -300,6 +300,11 @@ class CupertinoTextField extends StatefulWidget {
|
||||
assert(clearButtonMode != null),
|
||||
assert(prefixMode != null),
|
||||
assert(suffixMode != null),
|
||||
// Assert the following instead of setting it directly to avoid surprising the user by silently changing the value they set.
|
||||
assert(!identical(textInputAction, TextInputAction.newline) ||
|
||||
maxLines == 1 ||
|
||||
!identical(keyboardType, TextInputType.text),
|
||||
'Use keyboardType TextInputType.multiline when using TextInputAction.newline on a multiline TextField.'),
|
||||
keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline),
|
||||
toolbarOptions = toolbarOptions ?? (obscureText ?
|
||||
const ToolbarOptions(
|
||||
|
||||
@ -376,6 +376,11 @@ class TextField extends StatefulWidget {
|
||||
),
|
||||
assert(!obscureText || maxLines == 1, 'Obscured fields cannot be multiline.'),
|
||||
assert(maxLength == null || maxLength == TextField.noMaxLength || maxLength > 0),
|
||||
// Assert the following instead of setting it directly to avoid surprising the user by silently changing the value they set.
|
||||
assert(!identical(textInputAction, TextInputAction.newline) ||
|
||||
maxLines == 1 ||
|
||||
!identical(keyboardType, TextInputType.text),
|
||||
'Use keyboardType TextInputType.multiline when using TextInputAction.newline on a multiline TextField.'),
|
||||
keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline),
|
||||
toolbarOptions = toolbarOptions ?? (obscureText ?
|
||||
const ToolbarOptions(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user