这是我的代码,我想在用户输入按钮但遇到以下错误时将数据存储到Firebase数据库中
onTap: () {
if(_controllershopname.text==''||_controllerstreet.text==''||_controllershopnumber.text==''||_controllercity.text==''||_controllerstate.text=='')
{
Fluttertoast.showToast(msg: "Please Fill all the fields");
}else{
DatabaseReference databseRefrence = FirebaseDatabase.instance.reference().child("ShopKeeper");
databseRefrence.child(widget.number).push().set(
{
'Name':widget.userName,
'ShopName': _controllershopname.text,
'ShopNumber':_controllershopnumber.text,
'ShopStreet':_controllerstreet.text,
'ShopCity':_controllercity.text,
'ShopState':_controllerstate.text,
'OnlineDelivery':"Yes",
});
这是错误
E / flutter(26078):[错误:flutter / lib / ui / ui_dart_state.cc(157)]未处理的异常:无效的参数:“ TextEditingController”的实例 E / flutter(26078):#0 StandardMessageCodec.writeValue(package:flutter / src / services / message_codecs.dart:392:7) E / Flutter(26078):#1 StandardMessageCodec.writeValue。 (软件包:flutter / src / services / message_codecs.dart:389:9) E / Flutter(26078):#2 _LinkedHashMapMixin.forEach(dart:collection-patch / compact_hash.dart:379:8) E / flutter(26078):#3 StandardMessageCodec.writeValue(package:flutter / src / services / message_codecs.dart:387:13) E / Flutter(26078):#4 StandardMessageCodec.writeValue。 (软件包:flutter / src / services / message_codecs.dart:389:9) E / flutter(26078):#5 _LinkedHashMapMixin.forEach(dart:collection-
答案 0 :(得分:1)
您是否创建了“TextEdittingControllers”的实例?如果创建了,那么您应该在保存到数据库之前尝试修剪文本:
onTap: () {
if(_controllershopname.text==''||_controllerstreet.text==''||_controllershopnumber.text==''||_controllercity.text==''||_controllerstate.text=='')
{
{
Fluttertoast.showToast(msg: "Please Fill all the fields");
}else{
DatabaseReference databseRefrence = FirebaseDatabase.instance.reference().child("ShopKeeper");
databseRefrence.child(widget.number).push().set(
{
'Name':widget.userName,
'ShopName': _controllershopname.text.trim(),
'ShopNumber':_controllershopnumber.text.trim(),
'ShopStreet':_controllerstreet.text.trim(),
'ShopCity':_controllercity.text.trim(),
'ShopState':_controllerstate.text.trim(),
'OnlineDelivery':"Yes",
});