此问题已存在:
How can i retrieve a list of recipe data document(which is a field value) that store under a specific user document?
7天前关闭
我在Firebase中有两个集合,一个是users集合,我存储了所有用户的详细信息,另一个集合是colrecipe,每个用户都有一个子集合。uid作为文档。我正在尝试基于数组列表获取Firestore集合。
如何从用户集合中检索这些配方的详细信息?
body: StreamBuilder(
stream: Firestore.instance
.collection('users')
.document(globals.user.email)
.collection('colrecipes')
.snapshots(),
builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) {
return Center(
child: CircularProgressIndicator(),
);
}
return ListView.builder(
itemCount: snapshot.data!.documents.length,
itemBuilder: (context, index) {
final DocumentSnapshot doc =
snapshot.data!.documents[index];
if ((recipemodel.recipeName)!.isEmpty) {
return Card(
margin: const EdgeInsets.all(4.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
elevation: 20,
shadowColor: Color.fromARGB(255, 0, 0, 0),
child: GestureDetector(
onTap: () => navigateToInfo(doc),
onTapDown: (details) => _getTapPosition(details),
onLongPress: () => _showContextMenu(context),
child: Container(
child: ClipRRect(
borderRadius: BorderRadius.circular(20.0),
child: Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Stack(
children: <Widget>[
Container(
height: MediaQuery.of(context)
.size
.height *
0.17,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
'${doc["image"]}' +
'?alt=media&token',
),
fit: BoxFit.cover,
),
)),
],
),
Container(
padding: EdgeInsets.symmetric(
horizontal: 8, vertical: 6),
height:
MediaQuery.of(context).size.height *
0.05,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color:
Color.fromARGB(146, 205, 204, 204),
),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
doc["recipeName"],
style: TextStyle(
overflow: TextOverflow.clip,
color:
Color.fromARGB(255, 51, 44, 25),
fontWeight: FontWeight.bold,
fontSize:
displayWidth(context) * 0.050,
),
),
),
),
Container(
padding: EdgeInsets.all(5),
height:
MediaQuery.of(context).size.height *
0.06,
decoration: BoxDecoration(
color: Color.fromARGB(255, 98, 91, 94),
),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: [
Row(
children: [
Transform.scale(
scale: 1.4,
child: Icon(
Icons.room_service,
color: Colors.white,
),
),
SizedBox(
width: 10,
),
Text(
doc["recipeServe"],
style: TextStyle(
fontSize:
displayWidth(context) *
0.045,
color: Colors.white,
),
),
],
),
Row(
children: [
Transform.scale(
scale: 1.4,
child: Icon(
Icons.access_time_filled,
color: Color.fromARGB(
255, 255, 255, 255),
),
),
SizedBox(
width: 10,
),
Text(
doc["recipeTimePrepared"],
style: TextStyle(
fontSize:
displayWidth(context) *
0.045,
color: Colors.white,
),
),
],
)
],
),
)
],
),
),
),
));
}
}
1条答案
按热度按时间9nvpjoqh1#
问题是你的colrecipes id在users中不是一个集合,把它作为一个集合并命名为iit为
recipeIds
,然后下面的代码就可以工作了。如果你不想做一个集合,那么就像这样更新你的代码
在您的列表视图中。构建器使用如下