import 'package:cloud_firestore/cloud_firestore.dart'; class ApiService{ final Firestore _db = Firestore.instance; final String _path; CollectionReference _ref; ApiService(this._path) { _ref = _db.collection(_path); } Future getDataCollection() { return _ref.getDocuments(); } Stream streamDataCollectionContains( String field, dynamic value) { return _ref .orderBy(field, descending: false).startAt([value]).endAt([value+ '\uf8ff']) .snapshots(); } Stream streamDataCollectionWhere( String field, dynamic value) { return _ref .where(field, isEqualTo: value) .snapshots(); } Stream streamDataCollection() { return _ref.snapshots(); } Stream streamDataCollectionById(String id) { return _ref.document(id).snapshots(); } Future getDocumentById(String id) { return _ref.document(id).get(); } Future create(Map data) { return _ref.add(data); } Future delete(String id) { return _ref.document(id).delete(); } Future update(Map data, String id) { return _ref.document(id).updateData(data); } }