颤振Firestore更新数据方法

时间:2020-09-29 12:18:59

标签: android firebase flutter dart google-cloud-firestore

我正在尝试更新从Firestore带来的卡数据

当我在Inkwell中使用onTap时,我想更改此卡中的数据。

这是我的搜索服务。我正在使用它来从Firestore带来数据

如何在这种情况下进行更新功能。谢谢你的帮助

class SearchService {
List<Future<QuerySnapshot>> searchByName() {
return [
  Firestore.instance
      .collection('dis')
      .where('no')
      .orderBy('date', descending: true )
      .getDocuments(),
   ];
  }
}

这是我的卡号

Widget buildResultCard(BuildContext context , data) {
return Card(
  shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5.0)),
  elevation: 5,
  child: ExpansionCard(


    title: Column(
              children: [

                Row(
                  children: [
                    Padding(
                      padding: EdgeInsets.fromLTRB(5, 0, 5, 1),
                      child: Text(data['isim'],
                        style:  GoogleFonts.montserrat(color: Colors.blueGrey[700], fontSize: 20 , textStyle: TextStyle(fontWeight: FontWeight.w400)),
                        textAlign: TextAlign.center,
                      ),
                    ),
                     InkWell(
                          child: Icon(
                            Icons.update,
                            color: Colors.white54,
                          ),
                          onTap: (){//I want to set update function here// 
                             },
                    )

                  ],
                ),
             );
           }

这是我的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');
}

}

有点长,但这是我的添加方法

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);
              });
            },
          )
        ],
      );
    });

}

0 个答案:

没有答案