flutter_showcaseview
flutter_showcaseview copied to clipboard
This widget has been unmounted, so the State no longer has a context
[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.
Happens when you try switching between screens very fast and ShowCaseWidget.of(context).startShowCase doesn't have time to start showing the showcase
And one more similar error
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.
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
Hi @kirill-21, Thanks for pointing out the issue. Can you please share the reproducible code as I am not able to reproduce it?
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
@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.
@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
@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
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.
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".
@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.
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"
.
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.
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.
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.
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
Could you try my suggestion above please?
- Call any async method.
- Before it returns, pop the current widget using Navigator.pop(context);
- 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.