[英]How to save specific field value from Firestore to Flutter
So my problem is that I know how to write in Firebase, update it, and read data... but now I need to get a specific field from a document and save it in some variable or string, and I am stuck there.所以我的问题是我知道如何在 Firebase 中写入,更新它并读取数据......但是现在我需要从文档中获取特定字段并将其保存在某个变量或字符串中,而我被困在那里。
Here is a field I need to get.这是我需要得到的一个字段。
Here is where I need to save it这是我需要保存的地方
So I need it to be saved so I can use it in code, specifically as an isEqual value.所以我需要保存它,以便我可以在代码中使用它,特别是作为 isEqual 值。 Because my goal is to display Players that play in that club.
因为我的目标是展示在那个俱乐部踢球的球员。 And every game its another club.
每场比赛都是另一个俱乐部。
firstly you have link you app with firebase then you need to import 3 plugin firebase core plugin firebase Firestore and cloud firebase then you need to in your Main.dart here first you create a Class Then you control it by TextController then you'll post you data After the data will successfully post on firebase then you will get response from firebase.. Actually I'll work on Firebase you can say rule Put Get Update Delete & fetch in other word these are the Queries. firstly you have link you app with firebase then you need to import 3 plugin firebase core plugin firebase Firestore and cloud firebase then you need to in your Main.dart here first you create a Class Then you control it by TextController then you'll post you数据在数据将成功发布到 firebase 之后,您将收到 firebase 的响应。实际上我将在 Firebase 上工作,您可以说规则 Puteries 删除其他字词。
I found solution:我找到了解决方案:
String? valueFromFirebase;
Future<String?> getData() async{
var a = await clubData.doc('Home').get();
setState(() {
valueFromFirebase= a['homeClubName'];
});
}
So when I need value from field ( in my case homeClubName) I just call string valueFromFirebase where I need it.因此,当我需要来自字段的值(在我的情况下为 homeClubName)时,我只需在需要它的地方调用字符串 valueFromFirebase。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.