0 points

Firestore CRUD


dashboard

Sun Jun 14 2020 03:21:06 GMT+0000 (UTC)

Posted by @pratik.gtm #dart

   final databaseReference = Firestore.instance;

 
 void createRecord() async {
    Map data = {'length': '1:30:20', 'position': '1', 'title': 'Introduction 3.'};
    await databaseReference
        .collection("class_10")
        .document('chapter_4')
        .collection('videos')
        .document()
        .setData(
           data
);

//    await databaseReference.collection("classes")
//        .document('10')
//        .collection('chapter')
//        .document('1')
//    .collection('videos')
//    .document('1')
//        .setData({
//      'title': 'Introduction 1 Sets',
//      'length': '10:20'
//    });
  }

  void getData() {
    databaseReference
        .collection("class_10")
        .document('chapter_1')
        .collection('videos')
        .getDocuments()
        .then((QuerySnapshot snapshot) {
      snapshot.documents.forEach((f) => print('${f.data}}'));
    });
  }

  void updateData() {
    try {
      databaseReference
          .collection('books')
          .document('1')
          .updateData({'description': 'Head First Flutter'});
    } catch (e) {
      print(e.toString());
    }
    databaseReference
        .collection("classes")
        .document('10')
        .collection('chapter')
        .document('1')
        .collection('videos');
  }

  void deleteData() {
    try {
      databaseReference.collection('books').document('1').delete();
    } catch (e) {
      print(e.toString());
    }
  }
content_copy Copy