adding packages
This commit is contained in:
@@ -0,0 +1 @@
|
||||
export 'snapshot.dart';
|
||||
@@ -0,0 +1,9 @@
|
||||
class FbDocumentSnapshot {
|
||||
final String documentId;
|
||||
final Map<String, dynamic> data;
|
||||
|
||||
FbDocumentSnapshot(
|
||||
this.documentId, {
|
||||
this.data,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export 'unsupported.dart'
|
||||
if (dart.library.html) 'web.dart'
|
||||
if (dart.library.io) 'mobile.dart';
|
||||
@@ -0,0 +1,47 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
|
||||
import 'classes/index.dart';
|
||||
|
||||
class FbFirestore {
|
||||
FbFirestore._();
|
||||
static FirebaseFirestore _firestore = FirebaseFirestore.instance;
|
||||
static Future<List<FbDocumentSnapshot>> getDocs(String path) async {
|
||||
final _data = await _firestore.collection(path).get();
|
||||
if (_data == null) return null;
|
||||
if (_data?.docs == null || _data.docs.isEmpty) return [];
|
||||
List<FbDocumentSnapshot> _items = [];
|
||||
_data.docs.forEach((d) {
|
||||
_items.add(FbDocumentSnapshot(d.id, data: _getData(d)));
|
||||
});
|
||||
return _items;
|
||||
}
|
||||
|
||||
static Future editDoc(String path, Map<String, dynamic> data,
|
||||
{bool update = false}) async {
|
||||
if (update) {
|
||||
await _firestore.doc('$path').update(data);
|
||||
} else {
|
||||
await _firestore.doc('$path').set(data);
|
||||
}
|
||||
}
|
||||
|
||||
static Future addDoc(String path, Map<String, dynamic> data) async {
|
||||
await _firestore.collection(path).add(data);
|
||||
}
|
||||
|
||||
static Future<FbDocumentSnapshot> getDoc(String path) async {
|
||||
final _data = await _firestore.doc(path).get();
|
||||
return FbDocumentSnapshot(_data.id, data: _getData(_data));
|
||||
}
|
||||
|
||||
static Future deleteDoc(String path) async {
|
||||
await _firestore.doc(path).delete();
|
||||
}
|
||||
|
||||
static Map<String, dynamic> _getData(DocumentSnapshot d) {
|
||||
if (d?.data == null) return null;
|
||||
return json.decode(json.encode(d.data));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import 'classes/index.dart';
|
||||
|
||||
class FbFirestore {
|
||||
FbFirestore._();
|
||||
|
||||
static Future<List<FbDocumentSnapshot>> getDocs(String path) {
|
||||
throw 'Platform Not Supported';
|
||||
}
|
||||
|
||||
static Future editDoc(String path, Map<String, dynamic> data,
|
||||
{bool update = false}) {
|
||||
throw 'Platform Not Supported';
|
||||
}
|
||||
|
||||
static Future addDoc(String path, Map<String, dynamic> data) {
|
||||
throw 'Platform Not Supported';
|
||||
}
|
||||
|
||||
static Future deleteDoc(String path) {
|
||||
throw 'Platform Not Supported';
|
||||
}
|
||||
|
||||
static Future<FbDocumentSnapshot> getDoc(String path) {
|
||||
throw 'Platform Not Supported';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:firebase/firebase.dart';
|
||||
import 'package:firebase/firestore.dart';
|
||||
|
||||
import 'classes/index.dart';
|
||||
|
||||
class FbFirestore {
|
||||
FbFirestore._();
|
||||
static Firestore _firestore = firestore();
|
||||
|
||||
static Future<List<FbDocumentSnapshot>> getDocs(String path) async {
|
||||
final _data = await _firestore.collection(path).get();
|
||||
if (_data == null) return null;
|
||||
if (_data?.docs == null || _data.docs.isEmpty) return [];
|
||||
List<FbDocumentSnapshot> _items = [];
|
||||
_data.docs.forEach((d) {
|
||||
_items.add(FbDocumentSnapshot(d.id, data: _getData(d)));
|
||||
});
|
||||
return _items;
|
||||
}
|
||||
|
||||
static Future editDoc(String path, Map<String, dynamic> data,
|
||||
{bool update = false}) async {
|
||||
if (update) {
|
||||
await _firestore.doc(path).update(data: data);
|
||||
} else {
|
||||
await _firestore.doc(path).set(data);
|
||||
}
|
||||
}
|
||||
|
||||
static Future addDoc(String path, Map<String, dynamic> data) async {
|
||||
await _firestore.collection(path).add(data);
|
||||
}
|
||||
|
||||
static Future deleteDoc(String path) async {
|
||||
await _firestore.doc(path).delete();
|
||||
}
|
||||
|
||||
static Future<FbDocumentSnapshot> getDoc(String path) async {
|
||||
final _data = await _firestore.doc(path).get();
|
||||
return FbDocumentSnapshot(_data.id, data: _getData(_data));
|
||||
}
|
||||
|
||||
static Map<String, dynamic> _getData(DocumentSnapshot d) {
|
||||
if (d?.data() == null) return null;
|
||||
return json.decode(json.encode(d.data()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user