从ListView.builder Flutter中删除项目

时间:2020-10-04 15:14:16

标签: list flutter listview bloc

您好,我想问一下如何从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()),

1 个答案:

答案 0 :(得分:2)

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)
     ),
   ),