darioielardi / flutter_speed_dial

Flutter plugin to implement a Material Design Speed Dial
https://pub.dev/packages/flutter_speed_dial
MIT License
416 stars 182 forks source link

'_overlay != null': is not true #329

Open imrikim opened 5 months ago

imrikim commented 5 months ago

Exception Log :

======== Exception caught by widgets library =======================================================
The following assertion was thrown while finalizing the widget tree:
'package:flutter/src/widgets/overlay.dart': Failed assertion: line 207 pos 12: '_overlay != null': is not true.

When the exception was thrown, this was the stack: 
#2      OverlayEntry.remove (package:flutter/src/widgets/overlay.dart:207:12)
#3      _SpeedDialState.dispose (package:flutter_speed_dial/src/speed_dial.dart:252:48)
#4      StatefulElement.unmount (package:flutter/src/widgets/framework.dart:5689:11)
#5      _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:2076:13)
#6      _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:2074:7)
#7      ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:5532:14)
#8      _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:2072:13)
#9      ListIterable.forEach (dart:_internal/iterable.dart:49:13)
#10     _InactiveElements._unmountAll (package:flutter/src/widgets/framework.dart:2085:25)
#11     BuildOwner.lockState (package:flutter/src/widgets/framework.dart:2764:15)
#12     BuildOwner.finalizeTree (package:flutter/src/widgets/framework.dart:3174:7)
#13     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:992:19)
#14     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:448:5)
#15     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1386:15)
#16     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1311:9)
#17     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1169:5)
#18     _invoke (dart:ui/hooks.dart:312:13)
#19     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:399:5)
#20     _drawFrame (dart:ui/hooks.dart:283:31)
(elided 2 frames from class _AssertionError)

Caused by overlayEntry != null :

  @override
  void dispose() {
    if (overlayEntry != null) {
      if (overlayEntry!.mounted) overlayEntry!.remove();
      overlayEntry!.dispose();
    }
    if (widget.renderOverlay && backgroundOverlay != null) {
      if (backgroundOverlay!.mounted) backgroundOverlay!.remove();
      backgroundOverlay!.dispose();
    }
    _controller.dispose();
    widget.openCloseDial?.removeListener(_onOpenCloseDial);
    super.dispose();
  }

suggested solution , do this instead:

   @override
  void dispose() {
    if (overlayEntry != null) {
      if (overlayEntry!.mounted) {
        overlayEntry!.remove();
        overlayEntry = null;
      }
      overlayEntry!.dispose();
    }
    if (widget.renderOverlay && backgroundOverlay != null) {
      if (backgroundOverlay!.mounted) backgroundOverlay!.remove();
      backgroundOverlay!.dispose();
    }
    _controller.dispose();
    widget.openCloseDial?.removeListener(_onOpenCloseDial);
    super.dispose();
  }
imrikim commented 5 months ago

no OverlayEntry inserted to the Overlay and you try to call the remove method. that is why '_overlay != null': is not true.

@prateekmedia do you have a different approach to resolve this issue ?

94Sip commented 1 month ago

I also just started getting this error, again. Looking at the change log, it looks like this was solved with version 6.2, but something has caused it to reappear.