flutter 如何设置文本表单字段中errorTextStyle的overflow属性?[duplicate]

mu0hgdu0  于 2023-03-04  发布在  Flutter
关注(0)|答案(4)|浏览(139)

此问题在此处已有答案

Prevent flutter text form field validation message ellipsis(1个答案)
2天前关闭。
我正在尝试设置TextFormField小部件中errorText的溢出。如下图所示,剩余的错误文本将进入省略号。

我希望我的错误信息完全可见。我已经尝试设置errorTextStyle的溢出,但它不起作用。

errorStyle: TextStyle(
                color: AppColors.secondaryRed,
                overflow: TextOverflow.visible,
              ),

我错过了什么吗?或者有什么解决办法吗?

uplii1fm

uplii1fm1#

如果这不是由错误样式处理,你可以添加另一个文本代表你的错误,即在你的验证器函数,你必须更新errorString.
此处代码:

//Variable
String errorString = "";

//widget
   Column(
     children: [
        Form(
        key: formKey,
        child: TextFormField(
         controller: emailController,
           validator: (value) {
               if (value!.isEmpty) {
                  errorString = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled";
                } else {
                   errorString = "";
                }
                return null;
            },
          ),
        ),
        const SizedBox(height: 10),
        Align(
           alignment: Alignment.centerLeft,
             child: Text(errorString))
     ],
  ),
hgb9j2n6

hgb9j2n62#

只需在InputDecoration中添加errorMaxLines: 3

    • 输出**:

    • 完整代码:**
TextFormField(
        autovalidateMode: AutovalidateMode.always,
        decoration: InputDecoration(
          errorMaxLines: 3,    //👈 Add this
          errorStyle: TextStyle(
            color: Colors.red,
            overflow: TextOverflow.visible,
          ),
        ),
        validator: (value) {
          if (value?.isEmpty == true) {
            return 'Please enter a value Please enter a value Please enter a value Please enter a value';
          }
          return null;
        },
      ),
blpfk2vs

blpfk2vs3#

在InputDecoration中放入以下代码行errorMaxLines:二:

InputDecoration(
  errorMaxLines: 2,
  errorStyle: TextStyle(
      color: AppColors.secondaryRed,
      overflow: TextOverflow.visible,
   ),
)
kognpnkq

kognpnkq4#

尝试在溢出下添加errorMaxLines: 2

相关问题