Android 颤振firestore更新数据方法
我正在尝试更新我从firestore带来的卡数据 当我在Inkwell中使用onTap时,我想更改此卡中的数据 这是我的搜索服务。我用这个从firestore获取数据 我如何在这种情况下执行更新功能。谢谢你的帮助Android 颤振firestore更新数据方法,android,firebase,flutter,dart,google-cloud-firestore,Android,Firebase,Flutter,Dart,Google Cloud Firestore,我正在尝试更新我从firestore带来的卡数据 当我在Inkwell中使用onTap时,我想更改此卡中的数据 这是我的搜索服务。我用这个从firestore获取数据 我如何在这种情况下执行更新功能。谢谢你的帮助 class SearchService { List<Future<QuerySnapshot>> searchByName() { return [ Firestore.instance .collection('dis') .wh
class SearchService {
List<Future<QuerySnapshot>> searchByName() {
return [
Firestore.instance
.collection('dis')
.where('no')
.orderBy('date', descending: true )
.getDocuments(),
];
}
}
这是我的adddata函数
Future<void> addData(carData) async {
if (isLoggedIn()) {
Firestore.instance.collection('dis').add(carData).catchError((e) {
print(e);
});
} else {
print('You need to be logged in');
}
Future addData(carData)异步{
if(isLoggedIn()){
Firestore.instance.collection('dis').add(carData).catchError((e){
印刷品(e);
});
}否则{
打印(“您需要登录”);
}
}
有点长,但这是我的方法
crudMedthods crudObj = new crudMedthods();
Future<bool> addDialog(BuildContext context) async {
return showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
final _width = MediaQuery.of(context).size.width;
return AlertDialog(
title: Text('Temsilci Verisi Ekleyin.', style: GoogleFonts.montserrat(color: Colors.black54,
fontSize: 22 , textStyle: TextStyle(fontWeight: FontWeight.w300)),
textAlign: TextAlign.center,),
content: SingleChildScrollView(
child: Container(
width: _width,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Column(
children: [
TextField(
onTap: (){
showDatePicker(context: context,
initialDate: _dateTime == null ? DateTime.now() : _dateTime,
firstDate: DateTime(2000),
lastDate: DateTime(2030)).then((date) {
setState(() {
_dateTime = date;
});
});
},
decoration: InputDecoration(hintText: _dateTime == null ? 'Uygulama Sıralama
Takvimi Giriniz' : _dateTime.toString()),
onChanged: (value) {
this._dateTime = value as DateTime;
},
),
],
),
SizedBox(height: 5.0),
TextField(
decoration: InputDecoration(hintText: 'Temsilci'),
onChanged: (value) {
this.temsilci = value;
},
),
SizedBox(height: 5.0),
TextField(
decoration: InputDecoration(hintText: 'Sıra No'),
onChanged: (value) {
this.sirano = value;
},
),
SizedBox(height: 5.0),
TextField(
decoration: InputDecoration(hintText: 'Tarih'),
onChanged: (value) {
this.tarih = value;
},
),
SizedBox(height: 5.0),
TextField(
decoration: InputDecoration(hintText: 'Veri Kaynağı'),
onChanged: (value) {
this.verik = value;
},
),
],
),
),
),
actions: <Widget>[
FlatButton(
child: Text('Verileri Sisteme Ekleyin'),
textColor: Colors.blue,
onPressed: () {
Navigator.of(context).pop();
crudObj.addData({
'date': this._dateTime,
'no': this.no,
'temsilci': this.temsilci,
'sıra no': this.sirano,
'tarih': this.tarih,
'veri kaynağı': this.verik,
}).then((result) {
dialogTrigger(context);
}).catchError((e) {
print(e);
});
},
)
],
);
});
crudMedthods crudObj=新的crudMedthods();
Future addDialog(BuildContext上下文)异步{
返回显示对话框(
上下文:上下文,
禁止:错误,
生成器:(BuildContext上下文){
final _width=MediaQuery.of(context).size.width;
返回警报对话框(
标题:文本(“Temsilci Verisi Ekleyin.”,样式:GoogleFonts.montserrat(颜色:Colors.black54,
fontSize:22,textStyle:textStyle(fontWeight:fontWeight.w300)),
textAlign:textAlign.center,),
内容:SingleChildScrollView(
子:容器(
宽度:_宽度,
子:列(
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
纵队(
儿童:[
文本字段(
onTap:(){
showDatePicker(上下文:上下文,
initialDate:_dateTime==null?dateTime.now():_dateTime,
firstDate:DateTime(2000年),
lastDate:DateTime(2030))。然后((日期){
设置状态(){
_日期时间=日期;
});
});
},
装饰:输入装饰(hintText:_dateTime==null?“维库拉马Sıralama
Takvimi girizing':_dateTime.toString()),
一旦更改:(值){
此值为.\u dateTime=值为dateTime;
},
),
],
),
尺寸箱(高度:5.0),
文本字段(
装饰:输入装饰(hintText:“Temsilci”),
一旦更改:(值){
this.temsilci=值;
},
),
尺寸箱(高度:5.0),
文本字段(
装饰:输入装饰(hintText:‘Sıra No’),
一旦更改:(值){
this.sirano=值;
},
),
尺寸箱(高度:5.0),
文本字段(
装饰:输入装饰(hintText:“Tarih”),
一旦更改:(值){
this.tarih=值;
},
),
尺寸箱(高度:5.0),
文本字段(
装饰:输入装饰(hintText:“Veri Kaynağ305;”),
一旦更改:(值){
this.verik=值;
},
),
],
),
),
),
行动:[
扁平按钮(
子:文本(“Verileri Sisteme Ekleyin”),
textColor:Colors.blue,
已按下:(){
Navigator.of(context.pop();
crudObj.addData({
“日期”:此。\u dateTime,
“不”:这个。不,
“temsilci”:this.temsilci,
“sıra no”:这个,西拉诺,
“tarih”:这个。tarih,
“veri kaynağ305;”:这是verik,
}).然后((结果){
对话触发(上下文);
}).catchError((e){
印刷品(e);
});
},
)
],
);
});
}问题是什么?我没有更新功能,也不知道如何编写,您必须正确地从数据中传递documetID@PeterHaddad纠正我如果我从数据中获取documentID时出错,其余部分应该可以正常工作<代码>等待Firestore.instance.collection('dis').document(data.documentID).updateData({'date':“new data”、'no':“new data”、'temsilci':“new data”、'sıra no':“new data”、'tarih':“new data”、'veri kaynaı':“new data”、})代码>问题是什么?我没有更新功能,我不知道如何编写,你必须正确地从数据中传递documetID@PeterHaddad纠正我如果我从数据中获取documentID时出错,其余的应该可以正常工作<代码>等待Firestore.instance.collection('dis').document(data.documentID).updateData({'date':“new data”、'no':“new data”、'temsilci':“new data”、'sıra no':“new data”、'tarih':“new data”、'veri kaynaı':“new data”、})代码>
crudMedthods crudObj = new crudMedthods();
Future<bool> addDialog(BuildContext context) async {
return showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
final _width = MediaQuery.of(context).size.width;
return AlertDialog(
title: Text('Temsilci Verisi Ekleyin.', style: GoogleFonts.montserrat(color: Colors.black54,
fontSize: 22 , textStyle: TextStyle(fontWeight: FontWeight.w300)),
textAlign: TextAlign.center,),
content: SingleChildScrollView(
child: Container(
width: _width,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Column(
children: [
TextField(
onTap: (){
showDatePicker(context: context,
initialDate: _dateTime == null ? DateTime.now() : _dateTime,
firstDate: DateTime(2000),
lastDate: DateTime(2030)).then((date) {
setState(() {
_dateTime = date;
});
});
},
decoration: InputDecoration(hintText: _dateTime == null ? 'Uygulama Sıralama
Takvimi Giriniz' : _dateTime.toString()),
onChanged: (value) {
this._dateTime = value as DateTime;
},
),
],
),
SizedBox(height: 5.0),
TextField(
decoration: InputDecoration(hintText: 'Temsilci'),
onChanged: (value) {
this.temsilci = value;
},
),
SizedBox(height: 5.0),
TextField(
decoration: InputDecoration(hintText: 'Sıra No'),
onChanged: (value) {
this.sirano = value;
},
),
SizedBox(height: 5.0),
TextField(
decoration: InputDecoration(hintText: 'Tarih'),
onChanged: (value) {
this.tarih = value;
},
),
SizedBox(height: 5.0),
TextField(
decoration: InputDecoration(hintText: 'Veri Kaynağı'),
onChanged: (value) {
this.verik = value;
},
),
],
),
),
),
actions: <Widget>[
FlatButton(
child: Text('Verileri Sisteme Ekleyin'),
textColor: Colors.blue,
onPressed: () {
Navigator.of(context).pop();
crudObj.addData({
'date': this._dateTime,
'no': this.no,
'temsilci': this.temsilci,
'sıra no': this.sirano,
'tarih': this.tarih,
'veri kaynağı': this.verik,
}).then((result) {
dialogTrigger(context);
}).catchError((e) {
print(e);
});
},
)
],
);
});