Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on hot reload #81

Closed
leidig54 opened this issue Nov 17, 2020 · 3 comments
Closed

Crash on hot reload #81

leidig54 opened this issue Nov 17, 2020 · 3 comments

Comments

@leidig54
Copy link

Describe the bug
Showcase View is causing hot reload to crash the app.

To Reproduce
Steps to reproduce the behavior:

  1. Change a widget.
  2. Hit reload.
  3. App crashes with below exception.

iOS and android. Simulator and physical devices.

Reloaded 7 of 1406 libraries in 2,257ms.
[VERBOSE-2:shell.cc(210)] Dart Unhandled Exception: This widget has been unmounted, so the State no longer has a context (and should be considered defunct).
Consider canceling any active work during "dispose" or using the "mounted" getter to determine if the State is still active., stack trace: #0      State.context.<anonymous closure>
package:flutter/…/widgets/framework.dart:1090
#1      State.context
package:flutter/…/widgets/framework.dart:1096
#2      _OverlayBuilderState.addToOverlay
package:showcaseview/layout_overlays.dart:165
#3      _OverlayBuilderState.showOverlay
package:showcaseview/layout_overlays.dart:157
#4      _OverlayBuilderState.syncWidgetAndOverlay
package:showcaseview/layout_overlays.dart:183
#5      _OverlayBuilderState.reassemble.<anonymous closure>
package:showcaseview/layout_overlays.dart:137
#6      SchedulerBinding._invokeFrameCallback
package:flutter/…/scheduler/binding.dart:1117
#7      SchedulerBinding.handleDrawFrame (package:flutter<…>

I'm not sure what to make of this. Does anyone have a good way of implementing the "mounted" feature mentioned in the exception? I have implemented the ShowCaseWidget like so...


return Builder(
          builder: (context) => (maskCategoryList.isNotEmpty ||
                  favouriteMask != null)
              ? ShowCaseWidget(
                  builder: Builder(builder: (context) {
                    WidgetsBinding.instance.addPostFrameCallback((_) async {
                      if (context
                              .read<UserDataRepo>()
                              .showCaseMap['maskHome'] !=
                          true) {
                        context.read<UserDataRepo>().setShowCase('maskHome');
                        return Future.delayed(Duration(milliseconds: 500)).then(
                            (value) => ShowCaseWidget.of(context).startShowCase(
                                [favouriteText, maskCategoryTile]));
                      }
                    });

                    return Padding(
@leidig54
Copy link
Author

...solved fairly easily by wrapping the WidgetsBinding callback in a if(mounted). I'll leave this here incase anyone else needs the prompt...

@sanket-simform
Copy link
Collaborator

Thanks , we'll update sample accordingly in next release.

@tomassasovsky
Copy link

I also have this problem:

E/flutter ( 3726): [ERROR:flutter/shell/common/shell.cc(103)] Dart Unhandled Exception: This widget has been unmounted, so the State no longer has a context (and should be considered defunct).
E/flutter ( 3726): Consider canceling any active work during "dispose" or using the "mounted" getter to determine if the State is still active., stack trace: #0      State.context.<anonymous closure>
E/flutter ( 3726): #1      State.context
E/flutter ( 3726): #2      _OverlayBuilderState.addToOverlay
E/flutter ( 3726): #3      _OverlayBuilderState.showOverlay
E/flutter ( 3726): #4      _OverlayBuilderState.syncWidgetAndOverlay
E/flutter ( 3726): #5      _OverlayBuilderState.reassemble.<anonymous closure>
E/flutter ( 3726): #6      SchedulerBinding._invokeFrameCallback
E/flutter ( 3726): #7      SchedulerBinding.handleDrawFrame
E/flutter ( 3726): #8      SchedulerBinding.scheduleWarmUpFrame.<anonymous closure>
E/flutter ( 3726): #9      Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
E/flutter ( 3726): #10     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:395:19)
E/flutter ( 3726): #11     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:426:5)
E/flutter ( 3726): #12     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
E/flutter ( 3726):

I tried this:

if (mounted)
      WidgetsBinding.instance?.addPostFrameCallback((_) {
        ShowCaseWidget.of(context)?.startShowCase(app.showcaseSettings.keys);
      });

inside my build method but this keeps happening. I also tried placing it inside the initState function but this error also appears.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants