removing item from ListView.builder Flutter

6.1k views Asked by At

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

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

There are 1 answers

2
Abhishek Ghaskata On BEST ANSWER
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)
     ),
   ),