我正在嘗試檢索當前用戶資料,但它在應用程式中顯示來自 firestore 的所有用戶資料這是我的代碼
Widget build(BuildContext context){
CollectionReference users = FirebaseFirestore.instance.collection('users');
return FutureBuilder<DocumentSnapshot>(
future: users.doc(documentId).get(),
builder: ((context, snapshot){
if(snapshot.connectionState == ConnectionState.done){
Map<String, dynamic> data =
snapshot.data!.data() as Map<String, dynamic>;
return Container(
child: Column(
children: [
Text('Email : '"${data['Email name'].toString()}",
style: const TextStyle(fontWeight: FontWeight.bold,wordSpacing: 10),),
const SizedBox(
width: 10,
),
Text('Contact : '"${data['age'].toString()}",
style: const TextStyle(fontWeight: FontWeight.bold,wordSpacing: 10),),
const SizedBox(
width: 10,
),
Text('Name : '"${data['firstname'].toString()}",
style: const TextStyle(fontWeight: FontWeight.bold,wordSpacing: 10),),
const SizedBox(
width: 10,
),
Text('Last Name : '"${data['lastname'].toString()}",
style: const TextStyle(fontWeight: FontWeight.bold,wordSpacing: 10),),
const SizedBox(
width: 10,
),
],
),
);
}
return const Text('Loading');
}),
這是documentId代碼
List<String> docIDs = [];
Future getDocId() async{
await FirebaseFirestore.instance.collection('users').get().then(
(snapShot) => snapShot.docs.forEach(
(documant){
print(documant.reference);
docIDs.add(documant.reference.id);
}));
}
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// ignore: prefer_const_constructors
Text('SignUp as ${user!.email!}',style: TextStyle(
fontSize: 20,
),),
Expanded(child: FutureBuilder(
future: getDocId(),
builder: (context, snapshot){
return ListView.builder(
itemCount: docIDs.length,
itemBuilder: (context, index){
return ListTile(
title: GetuserData(documentId: docIDs[index]),
);
},
);
},
))
當用戶發布它成功提交的表單并生成一個像登頂表單歷史這樣的帖子但它向其他用戶顯示但我不會只為當前用戶如何做到這一點請任何人都可以幫助我
uj5u.com熱心網友回復:
您可以使用 firestore 查詢回傳當前用戶where()
上getDocId():
await FirebaseFirestore.instance.collection('users').get()
改成
await FirebaseFirestore.instance.collection('users')
.where('Email name', isEqualTo: '[email protected]').get()
您可以將電子郵件替換為您的或考慮使用引數動態傳遞用戶電子郵件。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/519718.html
標籤:Google Cloud Collective 扑火力基地谷歌云火库
