从ListView.builder Flutter中删除项目 [英] removing item from ListView.builder Flutter
问题描述
您好,我想问一下如何从ListViewBuilder中删除一个项目,通常,如果我有一个数组,就称它为x就足够了;然后我可以使用remoteAt删除我想要的任何项目
hi may i ask how to remove an item from the ListViewBuilder, normally it must be enough if i have an array let's call it x; then i can remove any item that i want by using remoteAt
x.removeAt(index);
但是在这种情况下,我无法确切知道该怎么做.所以在这种情况下,我没有x数组或列表,请参见下面的代码.我刚刚声明了如果我有一个列表并将其包括在列表生成器中,该怎么做,那么我可以通过调用removeAt属性来删除屏幕上的任何小部件.预先感谢
but in this case i couldn't know exactly how can i do that. so i don't have an x array or list in this case , see please the code below. i just declared how can i do that if i have a list and including it inside a list builder , then i can remove any widget on the screen by calling removeAt property thanks in advance
child: Column(
children: <Widget>[BlocBuilder(
cubit: BlocProvider.of<AppBloc>(context),
builder: (BuildContext context, AppState state) {
if (state is AppUpdated && state.services.count > 0) {
return Expanded(
child: ListView.builder(
itemCount: state.services.count,
itemBuilder: (BuildContext context, int index) =>
Dismissible(
key: Key(state.service.toString()),
推荐答案
ListView.builder(
itemCount: state.services.count,
itemBuilder: (BuildContext context, int index) =>
Dismissible(
key: Key(state.service.toString()),
onDismissed: (direction) {
// Remove the item from the data source.
setState(() {
x.removeAt(index);
});
},
child: //your child here (maybe listivew)
),
),
这篇关于从ListView.builder Flutter中删除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!