【发布时间】:2020-04-04 00:52:18
【问题描述】:
我在单击按钮时触发了一个对话框,我想在该对话框中打印一些包含从 firestore 获取的数据的行。 'Dialog' 框有一个 Listview 小部件,我在其中循环浏览我的文档快照以打印行以及它们前面的复选框。基本上我想对使用复选框选择的所有项目执行操作。但是当我点击时,复选框不起作用。
请帮忙!我是新来的颤振。这是我的对话框的完整代码。
final snapshot = await Firestore.instance
.collection('students')
.where('vehicle_code', isEqualTo: _userId)
.getDocuments();
await showDialog<void>(
context: context,
builder: (BuildContext context) {
bool isChecked = false;
return Dialog(
shape:
RoundedRectangleBorder(borderRadius: new BorderRadius.circular(15)),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
padding: EdgeInsets.all(12),
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: new BorderRadius.only(
topLeft: const Radius.circular(15),
topRight: const Radius.circular(15)),
),
child: Text(
"Select Students",
style: TextStyle(
color: Colors.black,
fontSize: 18,
fontWeight: FontWeight.w600),
),
),
Container(
width: 300,
height: 400,
child: ListView(
//mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
for(var item in snapshot.documents )
//Text(item['first_name'])
Row(
children: [
SizedBox(
width: 100.0,
height: 100.0,
child: Image.asset('assets/newlogo.png'),
),
Text(item['first_name']),
Checkbox(
value: isChecked,
onChanged: (bool value) {
print(isChecked);
setState(() {
isChecked = value;
});
},
),
],
),
],
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
RaisedButton(
color: Colors.blue,
onPressed: () {
Navigator.of(context).pop();
},
child: Text(
'Okay',
style: TextStyle(fontSize: 18.0, color: Colors.white),
),
),
SizedBox(
width: 20,
),
RaisedButton(
color: Colors.red,
onPressed: () {
Navigator.of(context).pop();
},
child: Text(
'Cancel!',
style: TextStyle(fontSize: 18.0, color: Colors.white),
),
)
],
),
],
),
);
},
);
【问题讨论】:
标签: listview flutter dart google-cloud-firestore dialog