From 6cf9c7cc17adbf39d0c2ab25bd64e567a63ca7d1 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Tue, 28 Apr 2020 10:39:03 -0700 Subject: [PATCH] Prevent use of TextInputType.text when also using TextInputAction.newLine via assert (#55636) --- packages/flutter/lib/src/cupertino/text_field.dart | 5 +++++ packages/flutter/lib/src/material/text_field.dart | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/packages/flutter/lib/src/cupertino/text_field.dart b/packages/flutter/lib/src/cupertino/text_field.dart index b36c6cc8901..3e9a547b771 100644 --- a/packages/flutter/lib/src/cupertino/text_field.dart +++ b/packages/flutter/lib/src/cupertino/text_field.dart @@ -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( diff --git a/packages/flutter/lib/src/material/text_field.dart b/packages/flutter/lib/src/material/text_field.dart index 23d7893ab7a..24056025eab 100644 --- a/packages/flutter/lib/src/material/text_field.dart +++ b/packages/flutter/lib/src/material/text_field.dart @@ -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(