想要删除 flutter 列表视图中的索引项
Want to remove indexed item in flutter's listview
有一个订单列表(包含订单),它配置了 pageview builder(水平滚动)并且在每个订单页面中都有 listview.builder(垂直滚动)中的项目,我能够成功配置动态地。
现在每个订单都有n个商品,每个商品都有一个按钮,调用成功。现在,在成功操作之后,我希望从 listview.builder 中删除执行操作的订单中的订单项,因为它在服务器后端被删除。
当订单没有剩余物品时,它也应该从 pageview.builder 中删除,因为它也从服务器中删除。
下面是 pageview.builder 和 list.viewbuilder
小部件的代码
FutureBuilder(
future: _future,
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
return Text('none');
case ConnectionState.waiting:
return Center(child: CircularProgressIndicator());
case ConnectionState.active:
return Text('');
case ConnectionState.done:
if (snapshot.hasError) {
return Text(
'${snapshot.error}',
style: TextStyle(color: Colors.red),
);
} else {
return PageView.builder(
scrollDirection: Axis.horizontal,
itemCount: snapshot.data.content.length,// length of total orders
itemBuilder: (context, index) {
var firstdata = jsonResponse['content'];
var list = firstdata[index]['order_items'];
return Column(
children:<Widget>[
Text( firstdata[index]['order_no]),
ListView.builder(
shrinkWrap: true,
itemCount: //lenght of the items in the order to be determined,
itemBuilder: (context, index) {
return Column(
children: [
Text(list[index]['item_number']),
RaisedButton(
onPressed: (){
callaction();
},
)
],
);
},
),
])
});
}
}
})
函数调用
callaction(){
print('action called on server');
var response = await http.post(url, body: data);
if (response.statusCode == 200) {
print('success');
}
}
请指导我如何实现所需的功能。 json flutter 索引 flutter-listview flutter-pageview
您可以将 firstdata
的项目索引传递给 callaction()
。问题是第二个构建器的索引覆盖了第一个,因此您需要至少重命名两者中的一个。然后你可以做 callaction(firstIndex)
然后从那里,从 firstdata
.
中删除正确的项目
有一个订单列表(包含订单),它配置了 pageview builder(水平滚动)并且在每个订单页面中都有 listview.builder(垂直滚动)中的项目,我能够成功配置动态地。
现在每个订单都有n个商品,每个商品都有一个按钮,调用成功。现在,在成功操作之后,我希望从 listview.builder 中删除执行操作的订单中的订单项,因为它在服务器后端被删除。
当订单没有剩余物品时,它也应该从 pageview.builder 中删除,因为它也从服务器中删除。
下面是 pageview.builder 和 list.viewbuilder
小部件的代码FutureBuilder(
future: _future,
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
return Text('none');
case ConnectionState.waiting:
return Center(child: CircularProgressIndicator());
case ConnectionState.active:
return Text('');
case ConnectionState.done:
if (snapshot.hasError) {
return Text(
'${snapshot.error}',
style: TextStyle(color: Colors.red),
);
} else {
return PageView.builder(
scrollDirection: Axis.horizontal,
itemCount: snapshot.data.content.length,// length of total orders
itemBuilder: (context, index) {
var firstdata = jsonResponse['content'];
var list = firstdata[index]['order_items'];
return Column(
children:<Widget>[
Text( firstdata[index]['order_no]),
ListView.builder(
shrinkWrap: true,
itemCount: //lenght of the items in the order to be determined,
itemBuilder: (context, index) {
return Column(
children: [
Text(list[index]['item_number']),
RaisedButton(
onPressed: (){
callaction();
},
)
],
);
},
),
])
});
}
}
})
函数调用
callaction(){
print('action called on server');
var response = await http.post(url, body: data);
if (response.statusCode == 200) {
print('success');
}
}
请指导我如何实现所需的功能。 json flutter 索引 flutter-listview flutter-pageview
您可以将 firstdata
的项目索引传递给 callaction()
。问题是第二个构建器的索引覆盖了第一个,因此您需要至少重命名两者中的一个。然后你可以做 callaction(firstIndex)
然后从那里,从 firstdata
.