Skip to content

fix: do not hide feedback on an unmounted context - #400

Open
leeyisoft wants to merge 2 commits into
ueman:masterfrom
leeyisoft:fix/mounted-guard-after-send
Open

leeyisoft wants to merge 2 commits into
ueman:masterfrom
leeyisoft:fix/mounted-guard-after-send

Conversation

@leeyisoft

Copy link
Copy Markdown

Problem

_sendFeedback awaits sendFeedback(...) and then unconditionally calls BetterFeedback.of(context).hide(), with the lint suppressed:

    await sendFeedback(...);

    // Close feedback mode
    // ignore: use_build_context_synchronously
    BetterFeedback.of(context).hide();

If the host screen is popped while the submission is still in flight — screenshot upload on a slow connection, back gesture, route discarded while the app is backgrounded — the lookup walks a deactivated element and throws:

Looking up a deactivated widget's ancestor is unsafe

Related to #359, which fixed the same class of problem for the focus restore on web.

Fix

Replace the lint suppression with a real guard:

    // Close feedback mode
    if (!context.mounted) return;
    BetterFeedback.of(context).hide();

When the context is gone there is nothing left to hide, so returning early is the correct behaviour. dart format clean, no API change.

`_sendFeedback` awaited `sendFeedback(...)` and then unconditionally called
`BetterFeedback.of(context).hide()` behind an `// ignore:
use_build_context_synchronously`. When the host screen is popped while the
submission is in flight (screenshot upload on a slow connection, back gesture,
app backgrounded and route discarded), the lookup walks a deactivated element
and throws:

    Looking up a deactivated widget's ancestor is unsafe

Guard the call with `context.mounted` instead of suppressing the lint.
@leeyisoft
leeyisoft requested a review from ueman as a code owner December 1, 2026 09:49
Submitting feedback and tearing the widget tree down before the send delay
elapses used to throw "Looking up a deactivated widget's ancestor is unsafe"
from BetterFeedback.of() in FeedbackWidgetState._sendFeedback.

The new test drives the real submit flow, replaces the tree with a bare
SizedBox while the send is in flight, and asserts that the onFeedback
callback still ran and that no exception escaped.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

1 participant