gpt4 book ai didi

android - 验证程序未将数据保存到Firebase数据库

转载 作者:行者123 更新时间:2023-12-03 04:26:36 26 4
gpt4 key购买 nike

我目前作为一个初学者正在做一个 flutter 的项目,我喜欢它。现在我开始接触后端(只是一个简单的CREATE WRITE btw),问题是当我输入数据时,它是Firebase中的null
我认为问题出在我的TextFormFields验证器中

                    TextFormField(
decoration: InputDecoration(hintText: 'Enter Offer Name'),
validator: (value) {
if (value.isEmpty) {
}
return 'Please Enter Offer Name';
},
onSaved: (value) => offerName = value,
),

我似乎无法找到一种方法来解决此问题,它只能返回 ''内的文本,而不保存 实际的输入,从而在Firebase数据库中显示 null

Additional details: I want the forms to save its data to firebase after clicking this FlatButton


                      child: FlatButton(
color: Colors.blue,
child: Text("Confirm", style: TextStyle(color: Colors.white)),
onPressed: () async {
await db.collection("createdoffers").add(
{
'name': offerName,
'type': offerType,
'start': start,
'end': end,
}
);
}
),

最佳答案

您代码中的return语句应位于if子句内,当前,由于return不在Please enter some text之外,因此它将始终返回if。因此,将validator函数更改为以下内容:

TextFormField(
// The validator receives the text that the user has entered.
validator: (value) {
if (value.isEmpty) {
return 'Please enter some text';
}
return null;
},
);

Validate the input by providing a validator() function to the TextFormField. If the user’s input isn’t valid, the validator function returns a String containing an error message. If there are no errors, the validator must return null.

关于android - 验证程序未将数据保存到Firebase数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59412486/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com