我遇到了一些问题。我如何可以添加验证到明文字段或任何字段,这是用于OTP输入。如果有人有另一个领域的OTP输入请让我知道。希望你能理解。请帮帮我。
_onAlertotp(context) {
Alert(
context: context,
title: "OTP expires in: MM:SS (Counter",
desc:
"We have Texted and/or Emailed OTP (One Time Pin) to your registered cell phone and/ or email account. Please check and enter OTP below to activate your TUDO account",
content: Column(
children: <Widget>[
Form(
autovalidate: true,
child: PinField(
padding: EdgeInsets.all(16.0),
length: 6,
gap: 6.0,
onSubmitted: Validators().otpValidate,
keyboardType: TextInputType.numberWithOptions(signed: true),
inputFormatters: [WhitelistingTextInputFormatter.digitsOnly]),
)
],
),
buttons: [
DialogButton(
onPressed: () => Navigator.pop(context),
child: Text(
"Resend OTP",
style: TextStyle(color: Colors.white, fontSize: 20),
),
),
DialogButton(
onPressed: () {
_onAlertrunningbusiness(context);
},
child: Text(
"Enter Otp",
style: TextStyle(color: Colors.white, fontSize: 20),
),
)
]).show();
}
2条答案
按热度按时间xa9qqrwz1#
为了验证一个空字符串,你只需要检查它的值是否等于“”。
你可以使用getter函数
isEmpty()
来检查String是否为空。方案编码:
cbjzeqam2#
我正在使用不同的库:https://pub.dev/packages/otp_text_field。但是你的库也有'onChanged'参数。