flutter-autocomplete-textfield
flutter-autocomplete-textfield copied to clipboard
AutoCompleteTextFieldState.updateOverlay.<anonymous closure>
The Plugin is crashing when we go back & forth in the App with setState() called after dispose() at line 240, we need to have the setState mounted in the plugin
AutoCompleteTextFieldState.updateOverlay.
flutter: #19 _invoke1 (dart:ui/hooks.dart:223:10) flutter: #20 _dispatchPointerDataPacket (dart:ui/hooks.dart:144:5) flutter: (elided 3 frames from package dart:async) flutter: flutter: Handler: onTap flutter: Recognizer: flutter: TapGestureRecognizer#6e03f(debugOwner: GestureDetector, state: accepted, won arena, finalPosition: flutter: Offset(34.5, 39.5), sent tap down) flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
The problem is: he/she implemented a stateful widget without adding initState and dispose !!! fork it and correct it, if you want a quick fix
I'll take a look into it.
This issue should likely be fixed now that the dispose method has been implemented. Please let me know if it persists.
Hi, I have the same issue. I have a screen with an autocomplete textfield but when I go back and forth then tap on the textfield to write something, it throws an error. I have tried it today, since I saw your comment about the implementation of the dispose method, but the issue persists.
I am working with the plugin version ^1.7.1.
Exception:
flutter: ══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
flutter: The following assertion was thrown while handling a gesture:
flutter: setState() called after dispose():
flutter: AutoCompleteTextFieldState<ArbitrarySuggestionType>#b351e(lifecycle state: defunct, not mounted)
flutter: This error happens if you call setState() on a State object for a widget that no longer appears in
flutter: the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error
flutter: can occur when code calls setState() from a timer or an animation callback. The preferred solution
flutter: is to cancel the timer or stop listening to the animation in the dispose() callback. Another
flutter: solution is to check the "mounted" property of this object before calling setState() to ensure the
flutter: object is still in the tree.
flutter: This error might indicate a memory leak if setState() is being called because another object is
flutter: retaining a reference to this State object after it has been removed from the tree. To avoid memory
flutter: leaks, consider breaking the reference to this object during dispose().
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0 State.setState.
@patriciapg93 I'm not really sure what you mean by "go back and forth"... do you mean navigating to different screens? If you could clarify the problem in more detail and provide code that was running at the time, I can look into this.
Yes, I have a page (PAGE 1) with an empty text that should be filled with the autocomplete selected suggestions (which I have in another page). There is a button in this page that takes the user to another page (PAGE 2) where I have the autocomplete textfield.
When I go from Page 1 to Page 2 the first time, the autocomplete textfield works fine, I can tap on it for it to gain focus and as I write, the suggestions show up.
But, when I go back to Page 1 and then to Page 2 again and tap on the autocomplete textfield, it throws the exception I pasted in the comment above.
I hope I have clarified the problem. I think it is the same (or almost) that happened to @nihalreddy33.
Thank you,
Any update on this? Thank you!
Not yet... I haven't had time to look into this. Hopefully I'll be able to fix soon, I'm sure it's doable.
Same issue here. I think you need to add if(!mounted) return;
before setState(() => .... )
for mounted check.
Thanks.
We are experiencing same issue here. Hope @felixlucien could fix it soon.
Thank you!
The solution might be to manually remove Overlay in onDispose (Example can be found in Tooltip class). The bug appears when you navigate to different screen while overlay is open, however it's not removed during navigation and continues to consume onTap events.