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

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

Closed
kirill-21 opened this issue Dec 8, 2022 · 19 comments
Closed

Comments

@kirill-21
Copy link

[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

@kirill-21
Copy link
Author

image
And one more similar error

@errajibadr
Copy link

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.

@kirill-21
Copy link
Author

  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

@faiyaz-shaikh
Copy link
Contributor

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

@kirill-21
Copy link
Author

pointing out the issue. Can you please share the reproducible

You can just approve this #333 pull request, i already fixed this problem there

@faiyaz-shaikh
Copy link
Contributor

@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.

@dhvanit-v-simformsolutions
Copy link
Contributor

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

@kirill-21
Copy link
Author

kirill-21 commented Mar 16, 2023

@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

@dhvanit-v-simformsolutions
Copy link
Contributor

@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
Copy link
Author

@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

@ujas-m-simformsolutions
Copy link
Contributor

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.

@ramanraja
Copy link

ramanraja commented Dec 30, 2023

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
Copy link

@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
Copy link

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".

@aditya-css
Copy link
Collaborator

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.

@kirill-21
Copy link
Author

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.

@aditya-css
Copy link
Collaborator

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.

@kirill-21
Copy link
Author

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

@ramanraja
Copy link

ramanraja commented Mar 8, 2024

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.

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

7 participants