我正在尝试将listview项的id传递到另一个页面,以便它可以用该id引用的项填充listview:
<script>
这是传递ID并将ID插入表中的代码:
return SideHeaderListView(
itemCount: order.length,
itemExtend: 230.0,
headerBuilder: (BuildContext context, index) {
return new SizedBox(
child: Text(order[index]['Month'],
style: TextStyle(
color: Colors.green,
fontWeight: FontWeight.bold,
fontSize: 30.0),),);
},
hasSameHeader: (int a, int b) {
return order[a]['Month'] ==
order[b]['Month'];
},
itemBuilder: (BuildContext context, index) {
String value;
return new GestureDetector(
//onLongPress: _showPopupMenu(),
onTap: () {
Navigator.push(context, MaterialPageRoute(
builder: (context) =>
MyItemList(orders: order[index],)
));
},
这是我的提供程序类方法:
class MyItemList extends StatelessWidget{
final Map<String, dynamic> orders;
// final Items items;
MyItemList({this.orders});
}
FlatButton(
color: Colors.lightGreen,
child: Text('ADD',style: TextStyle(color: Colors.white),),
onPressed: () async {
OrderProvider.insertItem({
'ref':MyItemList().orders,
'Quantity': _quantityController.text,
'Unit': getDropDownItem().toString(),
'TypeOfProduct': _typeController.text,
'UnitPrice':_unitpriceController.text,
'TotalPrice':getTotalPrice()
});
答案 0 :(得分:0)
首先,我建议您使用StateFul小部件而不是MyItemList Class
中的StateLess小部件,然后在InitState
中,您可以基于相应的ID获取数据,例如:>
class MyItemList extends StatefulWidget {
// final Map<String, dynamic> orders;
// instead of receive a Map receive only the OrderID
final int orderId;
MyItemList({this.orderId});
@override
_MyItemListState createState() => _MyItemListState();
}
class _MyItemListState extends State<MyItemList> {
List<dynamic> itemsToSave;
@override
void initState() {
super.initState();
getItems(widget.orderId);
}
@override
Widget build(BuildContext context) {
return Container();
}
getItems(int orderId) async {
itemsToSave = await yourProvider.getItems(orderId);
print(itemsToSave);
}
}
例如,在您的提供商中最好使用whereArgs
:
await db.rawQuery(
'SELECT * FROM Items WHERE ref = ?',
[order],
),
如果您有订单地图,则最好迭代该地图并分别获取每个商品的数据,或者查看SQLite的IN Operator
文档以获取更多说明,可以查看此{{ 3}}。
希望有帮助。