Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
看来问题是以下代码中的控制流的一个简单错误(请参阅 // 注释):
如您所见,即使用户输入无效,您仍然会继续将结果上传到 Firebase。
尝试像这样纠正:
It appears that the problem is a simple mistake with your control flow in the following code (see // comment):
As you can see, even if the user input is not valid, you still continue to upload the results to Firebase anyway.
Try correcting like this:
唯一可能的原因是
_addressType
的初始值为null
因为它是一个
String?
变量,所以如果用户没有选择“Delivery Slot”保存后的结果将是
null
,您需要做的是检查
_addressType
的值是否为null
然后继续保存表单,因为您的表单不会检查它是否为空。The only possible reason is because of
_addressType
it's initial value isnull
since it's a
String?
variable so if the user didn't select a "Delivery Slot"the result of it after saving would be
null
,what you need to do, it to check the value of
_addressType
if it'snull
or not then proceed to saving the form because your form doesn't check it if it's null or not.您可以将表单验证器添加到提交按钮本身。当您单击“提交”按钮时,以下代码将起作用。
You can add the form validator to the submit button itself. The below code works when you click on the submit button.