我有这个挑战。我要做的就是在数据表上显示其数量已更新的项目。我可以显示项目和数量。我也可以重置数量,但是当我尝试单击“保存”时,它应该填充在数据表上,并可能在稍后发出更新请求,它在下面显示此错误:
这是物品清单:
这是允许我更新数量的表格:
也可以在Listile中显示数据。我想用Divider在ListBody中显示数据,但我不知道该怎么做。我尝试过的所有方法都抛出错误。 widget.farmerBvn和widget.dc_dcOid,用户名可以替换为以下参数:
farmerBvn = 22499183844 dcOid = 11,agentName = johndoh
我已经尝试过,但是在此问题以及如何将视图从Listile更改为ListBody(我可以在其中显示更多属性)的过程中,我一直遇到此错误。请有人可以帮我,我是新来的。
以下代码可帮助我在列表上显示项目:
//List Start Here
child: ListView(
children: eops.map((e) {
return ListTile(
onTap: () {
showDialog(
context: context,
builder: (context) {
return AlertDialog(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(20)),
title: Text(e.itemName),
content: TextField(
controller: quantity,
keyboardType:
TextInputType.number,
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius:
BorderRadius.circular(
7),
),
labelText:
'Input Quantity Collected',
hintText:
e.quantityAllocated),
),
actions: <Widget>[
FlatButton(
child: Text('Reset'),
onPressed: () {
setState(() {
quantity.text = '';
});
},
),
FlatButton(
child: Text('Save'),
onPressed: () {
bool neww = true;
for (EopLine n
in selectedEops) {
if (n.oid == e.oid) {
setState(() {
n.quantityCollected =
quantity.text;
});
neww = false;
break;
}
}
if (neww == true) {
setState(() {
selectedEops.add(EopLine(
oid: e.oid,
itemName: e.itemName,
quantityCollected: e
.quantityCollected,
createdBy:
e.createdBy,
createdOn:
DateTime.now()
.toString(),
itemType: e.itemType,
measuringUnit:
e.measuringUnit));
});
neww = false;
}
Navigator.pop(context);
},
),
],
);
});
},
leading: (
FittedBox(
fit: BoxFit.contain,
child:Text(e.itemName),
)
),
title: Text('${e.quantityAllocated}'),
trailing: Text('${e.quantityCollected}'),
);
// separatorBuilder:
// (context, index) {
// return Divider();
// };
}).toList(),
),
// ],
// ),
),
//And it ends here
这是我要填充的数据表:
//Table starts here
child: DataTable(
columns: [
DataColumn(
label: Text('S/N'),
),
DataColumn(
label: Text('EOP Items'),
),
DataColumn(
label: Text('Qty Collected'),
),
// Lets add one more column to show a delete button
DataColumn(
label: Text('Update'),
)
],
rows: selectedEops
.map(
(eop) => DataRow(
selected: selectedEops.contains(eop),
cells: [
DataCell(
Text('${eop.oid}'),
onTap: () {
print('Selected ${eop.oid}');
},
),
DataCell(
Text(eop.itemName),
onTap: () {
print(
'Selected ${eop.itemName}');
},
),
DataCell(
Text(eop.quantityCollected ?? 0),
onTap: () {
print(
'Selected ${eop.quantityCollected ?? 0}');
},
),
DataCell(
Text(eop.quantityAllocated.toString() ?? 0),
onTap: () {
print(
'Selected ${eop.quantityAllocated.toString() ?? 0}');
},
showEditIcon: true,
),
]),
)
.toList(),
),
),
),
///Table Ends here
在此 eops 中的产品数组中,通过map函数,我可以看到QuantityAllocated显示为null,但其他项也在显示。在eops.map(e)下方此数量已分配的任何行,另一些行显示为null,其余的行显示其值。
children: eops.map((e)
这是执行http请求的功能:
Future<EopLine> get_farmer_eop() async {
SharedPreferences localStorage = await SharedPreferences.getInstance();
var userJson = localStorage.getString('loginRes');
user = json.decode(userJson);
print(user['UserName']);
final response = await http.get(
'http://api.ergagro.com:112/GenerateFarmersEop?farmerBvn=${widget.result}&dcOid=${widget.dc_result}&agentName=${user['UserName']}',
headers: _setHeaders());
print('${response.statusCode}popo');
if (response.statusCode == 200 && response.body != null) {
final jsonStatus = jsonDecode(response.body);
maineops = jsonStatus['Eop'];
List<dynamic> EopItems = maineops['EopLines'];
for (var i in EopItems) {
print('${i['Oid'].toString()} eopitemid');
setState(() {
eops.add(EopLine(
oid: i['Oid'],
itemType: i['EopType'].toString(),
itemName: i['ItemName'],
quantityAllocated: i['QuantityAllocated'].toString(),
quantityCollected: i['QuantityCollected'].toString(),
measuringUnit: i['MeasuringUnit'],
));
// r = maineops;
});
}
} else {
Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.green),
backgroundColor: Colors.grey,
),
);
}
throw Exception();
}
_setHeaders() => {
'Content-type': 'application/json',
'Accept': 'application/json',
};