Skip to content

Commit 6cf9c7c

Browse files
authored
Prevent use of TextInputType.text when also using TextInputAction.newLine via assert (flutter#55636)
1 parent b7fd24a commit 6cf9c7c

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

packages/flutter/lib/src/cupertino/text_field.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ class CupertinoTextField extends StatefulWidget {
300300
assert(clearButtonMode != null),
301301
assert(prefixMode != null),
302302
assert(suffixMode != null),
303+
// Assert the following instead of setting it directly to avoid surprising the user by silently changing the value they set.
304+
assert(!identical(textInputAction, TextInputAction.newline) ||
305+
maxLines == 1 ||
306+
!identical(keyboardType, TextInputType.text),
307+
'Use keyboardType TextInputType.multiline when using TextInputAction.newline on a multiline TextField.'),
303308
keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline),
304309
toolbarOptions = toolbarOptions ?? (obscureText ?
305310
const ToolbarOptions(

packages/flutter/lib/src/material/text_field.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,11 @@ class TextField extends StatefulWidget {
376376
),
377377
assert(!obscureText || maxLines == 1, 'Obscured fields cannot be multiline.'),
378378
assert(maxLength == null || maxLength == TextField.noMaxLength || maxLength > 0),
379+
// Assert the following instead of setting it directly to avoid surprising the user by silently changing the value they set.
380+
assert(!identical(textInputAction, TextInputAction.newline) ||
381+
maxLines == 1 ||
382+
!identical(keyboardType, TextInputType.text),
383+
'Use keyboardType TextInputType.multiline when using TextInputAction.newline on a multiline TextField.'),
379384
keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline),
380385
toolbarOptions = toolbarOptions ?? (obscureText ?
381386
const ToolbarOptions(

0 commit comments

Comments
 (0)