firebase - 我如何使用路由检索文档 ID,并在详细页面中检索文档 ID 及其子集合的内部
问题描述
每个文档都有子集合。我真的不知道如何从 gridview 中检索到带有 firestore 查询的详细信息页面
我真的是这个行业的新手,我真的很抱歉。
有没有办法解决这个问题?在 youtube、google 上找不到。请帮我
StreamBuilder(
stream: FirebaseFirestore.instance
.collection('locationdata')
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData)
return Center(child: CircularProgressIndicator());
return GridView.builder(
primary: false,
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
scrollDirection: Axis.vertical,
itemCount: snapshot.data.docs.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2),
itemBuilder: (context, index) => _locationListItem(
context, snapshot.data.docs[index]));
},
),
SizedBox(height: 30),
],
),
));
}
}
Widget _locationListItem(BuildContext context, DocumentSnapshot document) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: GestureDetector(
onTap: () => Navigator.push(context,
MaterialPageRoute(builder: (context) => DestinationScreen())),
child: Card(
clipBehavior: Clip.antiAlias,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(24)),
child: ClipRRect(
borderRadius: BorderRadius.circular(20),
child: Stack(alignment: Alignment.center, children: [
Image.network(
document['imgURL'],
height: 240,
fit: BoxFit.cover,
),
Positioned(
bottom: 0,
child: Container(
//padding: EdgeInsets.only(top: 10, bottom: 10, right: 70, left: 70),
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height * 0.05,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.grey[600],
),
child: Center(
child: Text(
document['name'],
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: Colors.white),
),
),
))
]),
),
),
),
);
}
这是详细页面
return Scaffold(
body: StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance.collection('locationdata').doc('locationdataDocId').collection('restaurant').snapshots(),
builder: (BuildContext context,AsyncSnapshot snapshot) {
if (!snapshot.hasData){
return Center(child: CircularProgressIndicator());
}
return Column(
children: <Widget> [
Stack(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
boxShadow: [
BoxShadow(
color: Colors.black26,
offset: Offset(0.0, 2.0),
blurRadius: 6.0),
],
),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 10.0, vertical: 40.0),
child: Row(
children: <Widget>[
IconButton(
icon: Icon(
Icons.arrow_back,
),
iconSize: 30.0,
color: Colors.black,
onPressed: () => Navigator.pop(context),
)
]
),
),
]
),
]
);
}
),
);
}
}
解决方案
推荐阅读
- angular - 无法在 Angular 数据表的下拉更改中调用 API 并刷新当前数据
- android - 将适配器设置为 Spinner 后数据已更改
- jira - 如何让一组用户成为 JIRA 项目所有票证的默认观察者
- pymc3 - Custom multivariate Dirichlet priors in pymc3
- vba - 如何表格单元格值字体颜色更改VBA字?Font.Textcolor 为什么不起作用?
- java - 在 Java (JDBC) 中使用 SQL 语句时占位符不起作用
- node.js - Nodejs express API 500 internal server error when remove a semicolon ;
- wpf - Wpf ListBox single click event
- node.js - Sending sensitive data through Electron’s IPC renderer
- java - 设计 restful API 路径 - 用于返回过滤的资源和返回资源的修剪属性