【问题标题】:How to display error label in Cupertino TextField如何在 Cupertino TextField 中显示错误标签
【发布时间】:2021-03-28 08:53:09
【问题描述】:

如果用户按下我的登录按钮后该字段为空,我将尝试在 Cupertino TextField 下方显示错误文本。似乎没有明确的方法可以在任何 CupertinoTextfield 参数中像在 android 上那样在文本字段下方显示错误标签。

我如何做到这一点?

这是我的代码

CupertinoTextField(
        key: widget.key,
        keyboardType: widget.textInputType,
        placeholder: widget.errorText ?? widget.hint,
        style: widget.style,
        onChanged: widget.onChanged,
        enabled: widget.enabled,
        controller: widget.textEditingController,
        focusNode: _focusNode,
        obscureText: widget.obscureText,
        enableSuggestions: widget.enableSuggestions,
        autocorrect: widget.autocorrect,
        clearButtonMode: OverlayVisibilityMode.editing,
        padding: widget.iosPaddings != null
            ? widget.iosPaddings!
            : const EdgeInsets.all(4),
      );

【问题讨论】:

  • 这个错误会是 iOS UI 和设计系统的典型部分吗?我不熟悉 iOS 应用程序上的表单,但有可能它不存在,因为 iOS 上的设计系统期望错误以不同的方式显示。

标签: flutter


【解决方案1】:

你可以试试CupertinoTextFormFieldRow:

CupertinoTextFormFieldRow(
    prefix: Text('Email'),
    placeholder: 'mail@example.com',
    validator: (value) {
      if (value == null || value.isEmpty) {
        return 'Please, enter your email';
      }

      return null;
    },
);

查看完整形式的示例:https://api.flutter.dev/flutter/cupertino/CupertinoTextFormFieldRow-class.html

【讨论】:

    猜你喜欢
    • 2022-01-17
    • 1970-01-01
    • 2020-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多