-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscratch_firebase.dart
115 lines (56 loc) · 1.97 KB
/
scratch_firebase.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'lib/data/inventory.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(home: Home());
}
}
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
List disposables =[];
FirebaseFirestore firestore = FirebaseFirestore.instance;
///questa variabile è un riferimento alla collection 'inventory' in firebase
CollectionReference inventoryFirebaseCollection =
FirebaseFirestore.instance.collection('Inventory');
Future<void> fetchDataFromFirebase(String documentName , List listInventory) async {
List fetchedList = [];
await inventoryFirebaseCollection
.where(FieldPath.documentId, isEqualTo: documentName)
.get()
.then((snapshot) {
if (snapshot.docs.isNotEmpty) {
snapshot.docs.asMap().forEach((key, value) {
fetchedList.add(value);
print(value.id);
listInventory = fetchedList;
});
}
}).catchError((e) => print("error fetching data: $e"));
// StreamBuilder(
// stream: FirebaseFirestore.instance
// .collection('YOUR COLLECTION NAME')
// .doc(id) //ID OF DOCUMENT
// .snapshots(),
// builder: (context, snapshot) {
// if (!snapshot.hasData) {
// return new CircularProgressIndicator();
// }
// var document = snapshot.data;
// return new Text(document["name"]);
// }
// );
// }
}
fetchDataFromFirebase('Disposables', disposables);
return Scaffold(
appBar: AppBar(
title: Text('AppBar'),
),
body: Container(child: Center(child: Text(disposables[0].id),),)
);
}
}