flutter_easy_autocomplete icon indicating copy to clipboard operation
flutter_easy_autocomplete copied to clipboard

An OverlayEntry must first be removed from the Overlay before dispose is called.

Open niyazm524 opened this issue 3 years ago • 3 comments

Bug

The following assertion was thrown while finalizing the widget tree:
An OverlayEntry must first be removed from the Overlay before dispose is called.
'package:flutter/src/widgets/overlay.dart':
Failed assertion: line 210 pos 12: '_overlay == null'

When the exception was thrown, this was the stack: 
#2      OverlayEntry.dispose (package:flutter/src/widgets/overlay.dart:210:12)
#3      _EasyAutocompleteState.dispose (package:easy_autocomplete/easy_autocomplete.dart:275:47)
#4      StatefulElement.unmount (package:flutter/src/widgets/framework.dart:5105:11)
#5      _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1917:13)
#6      _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1915:7)
#7      MultiChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6398:16)
#8      _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1913:13)
#9      _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1915:7)
#10     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4931:14)
#11     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1913:13)
#12     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1915:7)
#13     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4931:14)
#14     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1913:13)
#15     _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:1915:7)
#16     ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4931:14)
#17     _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1913:13)
#18     ListIterable.forEach (dart:_internal/iterable.dart:39:13)
#19     _InactiveElements._unmountAll (package:flutter/src/widgets/framework.dart:1926:25)
#20     BuildOwner.lockState (package:flutter/src/widgets/framework.dart:2523:15)
#21     BuildOwner.finalizeTree (package:flutter/src/widgets/framework.dart:2947:7)
#22     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:885:19)
#23     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:378:5)
#24     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1175:15)
#25     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1104:9)
#26     SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:881:7)
(elided 6 frames from class _AssertionError, class _RawReceivePortImpl, class _Timer, and dart:async-patch)
====================================================================================================

niyazm524 avatar Sep 18 '22 23:09 niyazm524

Hello @niyazm524,

First of all I would like to apologize for the late reply and for negleting the package issues for so long. I know it's been a long time and you may not even remember this issue, but could you provide more info on how to reproduce so I may be able to fix it.

Have a nice day

eunicevassoa avatar May 02 '23 16:05 eunicevassoa

Had the same issue here:

I/flutter (17964): [2023-06-03 10:12:13.590774 | Catcher | INFO] I/flutter (17964): [2023-06-03 10:12:13.590856 | Catcher | INFO] ---------- ERROR ---------- I/flutter (17964): [2023-06-03 10:12:13.590969 | Catcher | INFO] 'package:flutter/src/widgets/overlay.dart': Failed assertion: line 213 pos 12: '_overlay == null': An OverlayEntry must first be removed from the Overlay before dispose is called. I/flutter (17964): [2023-06-03 10:12:13.591073 | Catcher | INFO] I/flutter (17964): [2023-06-03 10:12:13.591197 | Catcher | INFO] ------- STACK TRACE ------- I/flutter (17964): [2023-06-03 10:12:13.592138 | Catcher | INFO] #0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61) I/flutter (17964): [2023-06-03 10:12:13.592253 | Catcher | INFO] #1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5) I/flutter (17964): [2023-06-03 10:12:13.592343 | Catcher | INFO] #2 OverlayEntry.dispose (package:flutter/src/widgets/overlay.dart:213:12) I/flutter (17964): [2023-06-03 10:12:13.592427 | Catcher | INFO] #3 _EasyAutocompleteState.dispose (package:easy_autocomplete/easy_autocomplete.dart:275:47) I/flutter (17964): [2023-06-03 10:12:13.592811 | Catcher | INFO] #4 StatefulElement.unmount (package:flutter/src/widgets/framework.dart:5179:11) I/flutter (17964): [2023-06-03 10:12:13.592926 | Catcher | INFO] #5 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1960:13) I/flutter (17964): [2023-06-03 10:12:13.593049 | Catcher | INFO] #6 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1958:7) .... I/flutter (17964): [2023-06-03 10:12:13.645748 | Catcher | INFO] #283 ListIterable.forEach (dart:_internal/iterable.dart:39:13) I/flutter (17964): [2023-06-03 10:12:13.645922 | Catcher | INFO] #284 _InactiveElements._unmountAll (package:flutter/src/widgets/framework.dart:1969:25) I/flutter (17964): [2023-06-03 10:12:13.646097 | Catcher | INFO] #285 BuildOwner.lockState (package:flutter/src/widgets/framework.dart:2601:15) I/flutter (17964): [2023-06-03 10:12:13.646168 | Catcher | INFO] #286 BuildOwner.finalizeTree (package:flutter/src/widgets/framework.dart:3023:7) I/flutter (17964): [2023-06-03 10:12:13.646214 | Catcher | INFO] #287 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:866:19) I/flutter (17964): [2023-06-03 10:12:13.646253 | Catcher | INFO] #288 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:381:5) I/flutter (17964): [2023-06-03 10:12:13.646349 | Catcher | INFO] #289 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1289:15) I/flutter (17964): [2023-06-03 10:12:13.646424 | Catcher | INFO] #290 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1218:9) I/flutter (17964): [2023-06-03 10:12:13.646484 | Catcher | INFO] #291 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1076:5) I/flutter (17964): [2023-06-03 10:12:13.646563 | Catcher | INFO] #292 _rootRun (dart:async/zone.dart:1398:13) I/flutter (17964): [2023-06-03 10:12:13.646691 | Catcher | INFO] #293 _CustomZone.run (dart:async/zone.dart:1300:19) I/flutter (17964): [2023-06-03 10:12:13.646813 | Catcher | INFO] #294 _CustomZone.runGuarded (dart:async/zone.dart:1208:7) I/flutter (17964): [2023-06-03 10:12:13.647013 | Catcher | INFO] #295 _invoke (dart:ui/hooks.dart:147:10) I/flutter (17964): [2023-06-03 10:12:13.647132 | Catcher | INFO] #296 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:338:5) I/flutter (17964): [2023-06-03 10:12:13.647278 | Catcher | INFO] #297 _drawFrame (dart:ui/hooks.dart:112:31)

Reproducible if you enter the TextFormField, select a suggestion and then navigate back to the previous page.

mrclauss avatar Jun 03 '23 10:06 mrclauss

A fix could be on the class easy_autocomplete.dart on line 277 where the dispose() method is called.

Instead of: if (_overlayEntry != null) _overlayEntry!.dispose();

Use:

if (_overlayEntry != null) {
      if (!mounted) {
        _overlayEntry!.dispose();
      }
    }

florentin89 avatar Nov 23 '23 10:11 florentin89