I'm using DismissibleWidget to remove a note from a list. When the note is removed a Snackbar is called to give the chance for the user to undo the action. When the button is clicked, and the note is reinserted in the list, this error appears:
The following assertion was thrown while handling a gesture: Looking up a deactivated widget's ancestor is unsafe. At this point the state of the widget's element tree is no longer stable.
The dismissible widget
Dismissible( direction: DismissDirection.endToStart, onDismissed: (direction){ var removedNote = list.notes[index]; Provider.of<ListProvider>(context, listen: false).removeNote(index); Scaffold.of(context).showSnackBar( SnackBar( content: Text("Nota removida"), action: SnackBarAction( label: "Desfazer", onPressed: (){ Provider.of<ListProvider>(context, listen: false).insertNote(removedNote, index); }, ), duration: Duration(seconds: 3), ), ); },...
The method in the provider
void insertNote(NoteModel note, int index){ notes.insert(index, note); fileRepository.saveToFile(notes); notifyListeners();}