如何解决如何在 Cupertino TextField 中显示错误标签
如果用户按下我的登录按钮后该字段为空,我将尝试在 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),);
解决方法
你可以试试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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。