0
I have a Future Builder that takes a list, and then returns a column with a Listview.Builder() and a button below, when using the button to add an element the list updates successfully, now when using a button that is inside Listtile to delete the element, the element is deleted but the list does not update. Follow an example of what it would be.
Dialog(
FutureBuilder(
future: getChapters(),
builder (context, snapshot) {
return Column(
children: <Widget>[
Container(
child: ListView.builder(
itemCount:snapshot.data.length,
builder: (context, index) {
return ListTile(
title: Text("teste");
trailing: InkWell(
child: Icon(Icons.delete),
onTap: (){
deleteChapter();
setState((){});
}
),
);
}
)
),
RaisedButton() {
onPressed: () {
addChapter();
setState((){});
}
}
]
);
}
)
)
When deleting an item from the list, it only updates by closing and opening the widget.
It would be good to analyze a complete code in this case, if we do not need to keep guessing what 'deleteChapter()' does, the 'Futurebuilder' is inside what, etc..
– Julio Henrique Bitencourt
Yes, I also think, it is very big, I agreed to this problem, but it was not solved.
– NelsonThiago
Oh that is, the ideal would be to create a new project and 'replicate' only the error that you are with doubt of the behavior, then share this code. The entire project ends up making it difficult to analyze unnecessary things rather than focusing on the error. I’ve done it a lot and most of the time I find the problem myself trying to isolate the mistake in another project.
– Julio Henrique Bitencourt
Dude, a tip is when you’re using
setState()
put inside it the method you want to execute, not outside, following your example do:setState((){deleteChapter();});
– Matheus Ribeiro
Inform what exists within the method
deleteChapter()
that we can help you better.– Matheus Ribeiro
I edited the example, I’m new to the questions so I didn’t post the well specified problem. deleteChapter() changes the list in the same way as addChapter(), of course, one adds an element and the other removes, and then the database is updated with the new list. The button you add is outside Futurebuilder() and it successfully updates the Dialog() after adding, now the button that is in Listtile() removes an element from the list, but you can only see the change by closing and opening the Dialog().
– NelsonThiago
In a nutshell, the add and remove processes are nearly the same, but when removing an element from the list using a button inside the listTile the screen does not update, but it successfully alters the list.
– NelsonThiago
@Nelsonthiago Edit your question and add the code inside your method
deleteChapter()
andaddChapter()
then we can better understand the situation.– Matheus Ribeiro
I edited the post. really the problem was due to deleteChapter() being async
– NelsonThiago
@Nelsonthiago as it is your first time here and as our help was not so well accepted by you to improve your question, take a little time to read this here:How to create a Minimum, Complete and Verifiable example... This will help us help you in the near future.
– Matheus Ribeiro
Actually I just didn’t improve the question why I was running out of time, if I had improved you probably would have found the problem well before I.
– NelsonThiago
@Nelsonthiago If you managed to solve the problem, the solution should be published in the answer area, not as an edition in the question. The question should only be related to the question itself. Read Answer your own question. I already reversed the edit you made by adding the answer to the question.
– Woss