An OverlayEntry must first be removed from the Overlay before dispose is called.
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)
====================================================================================================
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
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.
Reproducible if you enter the TextFormField, select a suggestion and then navigate back to the previous page.
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();
}
}