flutter-autocomplete-textfield
flutter-autocomplete-textfield copied to clipboard
AutoCompleteTextFieldState not disposing
- Navigation is Popped while autocomplete is in focus with a list of items being displayed and no item is selected.
- When the ensuing Navigation screen is popped, the following exception is thrown.
Both Widgets use which create back button at the top: return new Scaffold( appBar: AppBar( title: Text("Title"), ), body: ....
════════ Exception caught by gesture ═══════════════════════════════════════════════════════════════ The following assertion was thrown while handling a gesture: setState() called after dispose(): AutoCompleteTextFieldState<Constant>#0a15a(lifecycle state: defunct, not mounted)
This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.
The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree. This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().
When the exception was thrown, this was the stack:
#0 State.setState.
Same issue here!