Somxhai
Somxhai

Reputation: 25

How to edit/delete item in listview.builder in different classes

I've tried

setState(() => queueData.removeAt(widget.number-1);

button from QueueGenerator class

TextButton(
                      onPressed: () {
                        Navigator.pop(context, "OK");
                        setState(() {
                          // remove and update listview ?
                          queueData[widget.number-1] = _controller
                              .text
                              .toString();
                        });
                      },
                      child: Text("Confirm",
                          style: Theme.of(context).textTheme.labelSmall))

lists for listview.builder (this is in different file from both classes)

List<String> queueData = [];
List<String> queueTemp = [];

Listview.builder

ListView.builder(
                            itemCount: qList.length,
                            itemBuilder: (context, index) {

                              return QueueGenerator(
                                  number: index + 1,
                                  description: qList[index]);
                            })

Upvotes: 0

Views: 352

Answers (1)

Aimen SAYOUD
Aimen SAYOUD

Reputation: 365

well you can either make these two lists

List<String> queueData = [];
List<String> queueTemp = [];

as global variables and use them there without passing them as a parameter in the widget fast solution but I don't recommend it

or you need to put them in the provider as private variables and create functions of getters and setters for them so you can edit them

note: when you call the provider which they are in it make sure the listen is true to see the changes

Upvotes: 1

Related Questions