如何从 Cloud firestore 继承到另一个页面?
How to inherit to another page from cloud firestore?
我有带卡片的页面,填写cloud firestore:
child: StreamBuilder(
stream:
FirebaseFirestore.instance.collection('Items').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return const Text('Loading...');
return GridView.count(
crossAxisCount: 2,
shrinkWrap: true,
mainAxisSpacing: 15.0,
crossAxisSpacing: 20.0,
childAspectRatio:
(SizeConfig.itemWidth / SizeConfig.itemHeight),
children: [
...List.generate(snapshot.data.docs.length, (index) {
return buildItemCard(
context, snapshot.data.docs[index]);
})
],
);
},
),
如何将卡片中的信息通过点击卡片转移到另一个页面(有描述的页面)显示?
首先,在您的应用程序执行的这一点上,这与 Firestore 没有任何关系,因为您只会操作您的 GridViewItems。
您需要做的是在您的项目中创建一个 onTap
操作,例如 ,将其应用到您的代码中,您可以执行如下操作:
children: [
...List.generate(snapshot.data.docs.length, (index) {
return buildItemCard(
context,
snapshot.data.docs[index],
onTap: doSomething(snapshot.data.docs[index])
);
})
],
void _onTileClicked(DocumentSnapshot doc){
//do something here
}
我有带卡片的页面,填写cloud firestore:
child: StreamBuilder(
stream:
FirebaseFirestore.instance.collection('Items').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return const Text('Loading...');
return GridView.count(
crossAxisCount: 2,
shrinkWrap: true,
mainAxisSpacing: 15.0,
crossAxisSpacing: 20.0,
childAspectRatio:
(SizeConfig.itemWidth / SizeConfig.itemHeight),
children: [
...List.generate(snapshot.data.docs.length, (index) {
return buildItemCard(
context, snapshot.data.docs[index]);
})
],
);
},
),
如何将卡片中的信息通过点击卡片转移到另一个页面(有描述的页面)显示?
首先,在您的应用程序执行的这一点上,这与 Firestore 没有任何关系,因为您只会操作您的 GridViewItems。
您需要做的是在您的项目中创建一个 onTap
操作,例如
children: [
...List.generate(snapshot.data.docs.length, (index) {
return buildItemCard(
context,
snapshot.data.docs[index],
onTap: doSomething(snapshot.data.docs[index])
);
})
],
void _onTileClicked(DocumentSnapshot doc){
//do something here
}