Home > Software engineering >  How to edit/delete item in listview.builder in different classes
How to edit/delete item in listview.builder in different classes

Time:04-15

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

CodePudding user response:

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

  • Related