gpt4 book ai didi

flutter - Flutter:如何获取值以供引用

转载 作者:行者123 更新时间:2023-12-03 04:27:32 25 4
gpt4 key购买 nike

我只是android编程的新手。现在我在 flutter / Dart 方面有问题。因此,我有一个卡片列表,其中显示了数据,这些数据来自Firestore数据库,并且卡片中还有一个名为“ View ”的按钮。所以我想做的是,如果我单击“查看”按钮,它将显示一个对话框,其中包含我单击的卡的详细信息。我在获取详细信息并在对话框中显示时遇到问题。请帮忙 :(

这是我的用户界面:

My UI

这是使用流生成器检索数据Im时的代码:

 StreamBuilder<QuerySnapshot>(
stream: db.collection('HELP REQUEST').snapshots(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Column(
children: snapshot.data.documents
.map((doc) => buildItem(doc))
.toList());
} else {
return SizedBox();
}
})

然后将数据放入卡中并输出:
return Card(
elevation: 5,
child: Padding(
padding: const EdgeInsets.all(8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Name of Requestor: ${doc.data['Name_ofUser']}',
style: TextStyle(fontSize: 20),
),
Text(
'Help description: ${doc.data['Help_Description']}',
style: TextStyle(fontSize: 20),
),
Text(
'Type of help needed: ${doc.data['Help_TypeNeeded']}',
style: TextStyle(fontSize: 20),
),
Text(
'Help location: ${doc.data['Help_Location']}',
style: TextStyle(fontSize: 20),
),
SizedBox(
height: 12,
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
FlatButton(
onPressed: () {},
child: Text('View'),
)
],
),
],
),
),
);

请帮忙 :(

最佳答案

假设您有一个卡片 list ,称为 list

您可以使用@mertcan答案来显示这样的对话框。

return Card(
elevation: 5,
child: Padding(
padding: const EdgeInsets.all(8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Name of Requestor: ${doc.data['Name_ofUser']}',
style: TextStyle(fontSize: 20),
),
Text(
'Help description: ${doc.data['Help_Description']}',
style: TextStyle(fontSize: 20),
),
Text(
'Type of help needed: ${Text('Help description: $help')}',
style: TextStyle(fontSize: 20),
),
Text(
'Help location: ${doc.data['Help_Location']}',
style: TextStyle(fontSize: 20),
),
SizedBox(
height: 12,
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
FlatButton(
onPressed: () {
//Note change here
_showMydialog(doc.data)
},
child: Text('View'),
)
],
),
],
),
),
)


void _showMydialog(dynamic data){
showDialog<void>(
context: context,
builder: (context) {
return SimpleDialog(
children: [
Text(Name of Requestor: ${data['Name_ofUser']),
Text('Help description: ${doc.data['Help_Description'])
],
);
},
);
}

关于flutter - Flutter:如何获取值以供引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58521904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com