【发布时间】:2022-01-16 06:26:13
【问题描述】:
我对 Firebase 还是很陌生,我一直在试图弄清楚如何在每次点击时在 Firebase 中获取特定文档的特定数据。
我将不胜感激。
当我点击其中一个字段时,此窗口会显示我需要添加的每个员工的信息。
这是我的数据库类代码:
class DataBaseService {
final String uid;
DataBaseService({this.uid});
//collection reference
final CollectionReference MyEmployees =
FirebaseFirestore.instance.collection('employees');
Future<void> updateEmployeeInfo(
String firstName,
String lastName,
String profession,
String status,
String email,
String phone,
String birth,
String address,
String taxNumber,
String major,
double salary,
) async {
return await MyEmployees.doc(uid).set(({
"firstName": firstName,
"lastName": lastName,
"profession": profession,
"status": status,
"email": email,
"phone": phone,
"birth": birth,
"address": address,
"taxNumber": taxNumber,
"major": major,
"salary": salary,
}));
}
// Get employees
Future getEmployeesList() async {
List itemList = [];
try {
await MyEmployees.get().then((querySnapshot) {
querySnapshot.docs.forEach((element) {
itemList.add(element.data());
});
});
return itemList;
} catch (e) {
print(e.toString());
return null;
}
}
}
数据库:
【问题讨论】:
-
请添加您收到的任何错误消息。是查询还是更新的问题? Please try to improve your question.
标签: firebase flutter google-cloud-firestore