flutter-autocomplete-textfield icon indicating copy to clipboard operation
flutter-autocomplete-textfield copied to clipboard

AutoCompleteTextFieldState.updateOverlay.<anonymous closure>

Open nihalreddy33 opened this issue 5 years ago • 11 comments

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... package:autocomplete_textfield/autocomplete_textfield.dart:240 STACK: 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. package:flutter/…/widgets/framework.dart:1095 flutter: #1 State.setState package:flutter/…/widgets/framework.dart:1121 flutter: #14 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue package:flutter/…/gestures/binding.dart:101 flutter: #15 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket package:flutter/…/gestures/binding.dart:85

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: ════════════════════════════════════════════════════════════════════════════════════════════════════

nihalreddy33 avatar May 14 '19 01:05 nihalreddy33

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

Ahmadre avatar May 19 '19 20:05 Ahmadre

I'll take a look into it.

felixmccuaig avatar Jun 24 '19 07:06 felixmccuaig

This issue should likely be fixed now that the dispose method has been implemented. Please let me know if it persists.

felixmccuaig avatar Jun 30 '19 04:06 felixmccuaig

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. (package:flutter/src/widgets/framework.dart:1100:9) flutter: #1 State.setState (package:flutter/src/widgets/framework.dart:1126:6) flutter: #2 AutoCompleteTextFieldState.updateOverlay... (package:autocomplete_textfield/autocomplete_textfield.dart:254:33) flutter: #3 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:635:14) flutter: #4 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:711:32) flutter: #5 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:181:24) flutter: #6 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:352:11) flutter: #7 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:264:7) flutter: #8 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:450:9) flutter: #9 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12) flutter: #10 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:100:11) flutter: #11 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19) flutter: #12 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22) flutter: #13 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7) flutter: #14 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7) flutter: #15 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7) flutter: #19 _invoke1 (dart:ui/hooks.dart:234:10) flutter: #20 _dispatchPointerDataPacket (dart:ui/hooks.dart:154:5) flutter: (elided 3 frames from package dart:async) flutter: flutter: Handler: "onTap" flutter: Recognizer: flutter: TapGestureRecognizer#591ea

patriciapg93 avatar Jul 01 '19 06:07 patriciapg93

@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.

felixmccuaig avatar Jul 02 '19 03:07 felixmccuaig

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,

patriciapg93 avatar Jul 02 '19 07:07 patriciapg93

Any update on this? Thank you!

patriciapg93 avatar Jul 09 '19 05:07 patriciapg93

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.

felixmccuaig avatar Jul 10 '19 00:07 felixmccuaig

Same issue here. I think you need to add if(!mounted) return; before setState(() => .... ) for mounted check. Thanks.

corsantic avatar Jul 16 '19 09:07 corsantic

We are experiencing same issue here. Hope @felixlucien could fix it soon.

Thank you!

joakiwpc avatar Jul 29 '19 14:07 joakiwpc

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.

Ainiuso avatar Aug 06 '19 07:08 Ainiuso