flutter_showcaseview icon indicating copy to clipboard operation
flutter_showcaseview copied to clipboard

This widget has been unmounted, so the State no longer has a context

Open krll-kov opened this issue 2 years ago • 14 comments

[DartError] 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.; #0 State.context. (package:flutter/src/widgets/framework.dart:935:9) #1 State.context (package:flutter/src/widgets/framework.dart:941:6) #2 _OverlayBuilderState.addToOverlay (package:showcaseview/src/layout_overlays.dart:172:47) #3 _OverlayBuilderState.showOverlay (package:showcaseview/src/layout_overlays.dart:164:7) #4 _OverlayBuilderState.syncWidgetAndOverlay (package:showcaseview/src/layout_overlays.dart:195:7) #5 _OverlayBuilderState.reassemble. (package:showcaseview/src/layout_overlays.dart:144:39) #6 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1175:15) #7 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1113:9) #8 SchedulerBinding.scheduleWarmUpFrame. (package:flutter/src/scheduler/binding.dart:881:7) #9 Timer._createTimer. (dart:async-patch/timer_patch.dart:18:15) #10 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19) #11 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5) #12 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)

Happens when you try switching between screens very fast and ShowCaseWidget.of(context).startShowCase doesn't have time to start showing the showcase

krll-kov avatar Dec 08 '22 17:12 krll-kov

image And one more similar error

krll-kov avatar Dec 08 '22 17:12 krll-kov

Hello,

i'm having the same issue, when hot reloading a page with a showcase widget. not even calling the postframecallback yet.

This widget has been unmounted, so the State no longer has a context (and should be considered defunct).

is there any work-around?

thank you.

errajibadr avatar Dec 28 '22 10:12 errajibadr

  showcaseview:
    git:
      url: https://github.com/kirill-21/flutter_showcaseview
      ref: master

Just use this version of package until fix is merged into this repo

krll-kov avatar Dec 28 '22 10:12 krll-kov

Hi @kirill-21, Thanks for pointing out the issue. Can you please share the reproducible code as I am not able to reproduce it?

faiyaz-shaikh avatar Feb 22 '23 12:02 faiyaz-shaikh

pointing out the issue. Can you please share the reproducible

You can just approve this https://github.com/SimformSolutionsPvtLtd/flutter_showcaseview/pull/333 pull request, i already fixed this problem there

krll-kov avatar Feb 22 '23 12:02 krll-kov

@kirill-21 Unfortunately, we can not merge PR until we can reproduce it. Please share the reproducible code so we can check the root cause.

faiyaz-shaikh avatar Feb 22 '23 12:02 faiyaz-shaikh

@kirill-21 Could you please use the latest version of showcaseview? I guess it will fix your concern. Thank you!!

@kirill-21 Could you please use the latest version of showcaseview? I guess it will fix your concern. Thank you!!

My issue can only be fixed after this changes: https://github.com/kirill-21/flutter_showcaseview/commit/152c484318f29b3ea890b65af6fa6157fe857c19, official branch works with errors

krll-kov avatar Mar 16 '23 06:03 krll-kov

@kirill-21 Could you please use the latest version of showcaseview? I guess it will fix your concern. Thank you!!

My issue can only be fixed after this changes: kirill-21@152c484, official branch works with errors

Okay, so could you please share the code snippet which produces these errors? It would be helpful for us to find the root cause.

@kirill-21 Could you please use the latest version of showcaseview? I guess it will fix your concern. Thank you!!

My issue can only be fixed after this changes: kirill-21@152c484, official branch works with errors

Okay, so could you please share the code snippet which produces these errors? It would be helpful for us to find the root cause.

No, this issue is being automatically reported to apps server as an unhandled exception, many users face this error, but I have no idea how to reproduce it, so I fixed it on my own branch and am using it right now to avoid errors, fix is simple and does not do anything bad, you can implement it within a minute

krll-kov avatar Mar 16 '23 07:03 krll-kov

I think the error suggest that somehow Showcase is trying to show tooltip and at same time that screen is closed so context for that screen is no longer available.

ujas-m-simformsolutions avatar Jul 14 '23 05:07 ujas-m-simformsolutions

I am not even using a Showcase widget. I come back from an async task that writes to a secured storage. After the await, I want to navigate to a different page for which I call Navigator.of(context). As I am across an async gap, I checked if the context is still valid - and that crashed the app. I expected a check like if (!context.mounted) to be safe. But performing this very check raises the exception. Then I inserted a lower level check if (context == null) which could at least flag a null check error. But this line also raised the same exception "This widget has been unmounted, so the State no longer has a context".

ramanraja avatar Dec 30 '23 09:12 ramanraja

@kirill-21 Unfortunately, we can not merge PR until we can reproduce it. Please share the reproducible code so we can check the root cause.

Are we still waiting to reproduce this bug - or have you found a way to reproduce it ? I have a piece of code that may bring up the error.

ramanraja avatar Dec 31 '23 06:12 ramanraja

This invalid-context bug can be reproduced by introducing a deliberate flaw in our workflow:

We have a button handler that calls an async method; but it pops the context without waiting for the method to return:


  onPressed: () {
    uploadToCloud(); 
    Navigator.pop(context);  // this is a bug: it prematurely pops the current page
  }
  
  Future<void> uploadToCloud() async{
    await someLongRunningAPICall ();
    // the following line crashes the app:
    if (context == null) return;
    // if the above line was commented out,the following check crashes the app:
    if (!context.mounted) return;
    Navigator.pop(context);
  }
  

Note 1: If the context is invalid, we are not able to perform the check if (!context.mounted) Note 2: We cannot even null-check the context. The mere mention of context on the left side of an expression raises an exception. Note 3: In both the above cases, the exception thrown is "This widget has been unmounted, so the State no longer has a context".

ramanraja avatar Dec 31 '23 06:12 ramanraja

Hey @kirill-21, due to not being able to reproduce this issue, I am closing it along with your PR for the same. If you face this issue again then please feel free to re open along with reproducible code.

aditya-css avatar Mar 07 '24 06:03 aditya-css

Lol, i LITERALLY made pull request with a fix for that.... 2 times... Why can't you just merge it? I showed you the place and fixed it

Hey @kirill-21, due to not being able to reproduce this issue, I am closing it along with your PR for the same. If you face this issue again then please feel free to re open along with reproducible code.

krll-kov avatar Mar 07 '24 06:03 krll-kov

We totally appreciate your contribution, but we have to know the underlying issue and how to reproduce it before merging a fix for it. If you can provide a reproducible code then we would be happy to check and accept your contribution.

aditya-css avatar Mar 07 '24 06:03 aditya-css

We totally appreciate your contribution, but we have to know the underlying issue and how to reproduce it before merging a fix for it. If you can provide a reproducible code then we would be happy to check and accept your contribution.

I guess you just never used this package before because issue is reproducible within a few seconds after just testing this inside a real project

krll-kov avatar Mar 07 '24 06:03 krll-kov

Could you try my suggestion above please?

  1. Call any async method.
  2. Before it returns, pop the current widget using Navigator.pop(context);
  3. After the async method returns, test if the context is still mounted (which of course, will not be) We would expect it to return false, but the app crashes.

ramanraja avatar Mar 08 '24 11:03 ramanraja