这里是我的代码,我想在用户输入按钮时将数据存储到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/TextEditingController (26078):错误:flutter/lib/ui/ui_dart_state.cc(157)未处理的异常:无效参数:'TextEditingController‘E/颤振(26078)的实例:#0 StandardMessageCodec.writeValue StandardMessageCodec.writeValue E/StandardMessageCodec.writeValue (26078):#1 StandardMessageCodec.writeValue。(package:flutter/src/services/message_codecs.dart:389:9) E/颤振(26078):#2 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:379:8) E/颤振(26078):#3 StandardMessageCodec.writeValue (package:flutter/src/services/message_codecs.dart:387:13) E/颤振(26078):#4 StandardMessageCodec.writeValue。(package:flutter/src/services/message_codecs.dart:389:9) E/颤振(26078):#5 _LinkedHashMapMixin.forEach (省道:收藏-
发布于 2021-06-01 07:39:59
如果您创建了"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",
});https://stackoverflow.com/questions/61190351
复制相似问题