从 ListView.builder Flutter 中删除项目
removing item from ListView.builder Flutter
你好,请问如何从 ListViewBuilder 中删除一个项目,
通常,如果我有一个数组就足够了,我们称它为 x;
然后我可以使用 remoteAt
删除我想要的任何项目
x.removeAt(index);
但在这种情况下,我无法确切地知道我该怎么做。
所以在这种情况下我没有 x 数组或列表,请参阅下面的代码。
我刚刚声明如果我有一个列表并将其包含在列表生成器中我该怎么做,然后我可以通过调用 removeAt 属性 删除屏幕上的任何小部件
提前致谢
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)
),
),
你好,请问如何从 ListViewBuilder 中删除一个项目, 通常,如果我有一个数组就足够了,我们称它为 x; 然后我可以使用 remoteAt
删除我想要的任何项目 x.removeAt(index);
但在这种情况下,我无法确切地知道我该怎么做。 所以在这种情况下我没有 x 数组或列表,请参阅下面的代码。 我刚刚声明如果我有一个列表并将其包含在列表生成器中我该怎么做,然后我可以通过调用 removeAt 属性 删除屏幕上的任何小部件 提前致谢
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)
),
),