fix: guard _runFocus against disposed controller (forward() after dispose) - #233
Open
thinklanguages wants to merge 1 commit into
Open
Conversation
_runFocus runs asynchronously (Future.delayed(Duration.zero) in initState, plus an optional `await widget.beforeFocus`), then calls _controller.forward() with no mounted check. If the widget is disposed during that async gap (the host overlay is removed via removeOverlayEntry()/route pop while the tutorial is mid-presentation), forward() runs on a disposed AnimationController whose _ticker is null. In release builds the `assert(_ticker != null)` inside AnimationController.stop() is stripped, so instead of a debug assertion the app throws an uncaught "Null check operator used on a null value" (_TypeError). Reproduced in production on a coach mark shown on a screen the user navigated away from. Add a `mounted` guard immediately before forward(). safeSetState above is already mounted-guarded, so this is the only remaining unguarded controller access on that path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
AnimatedFocusLightState._runFocus()is scheduled asynchronously —Future.delayed(Duration.zero, _runFocus)ininitState, plus anawait widget.beforeFocus(...)— and then calls_controller.forward()with nomountedcheck.If the widget is disposed during that async gap (the host overlay is removed via
removeOverlayEntry()/ a route pop while the tutorial is mid-presentation),forward()runs on a disposedAnimationController._tickeris null, and becauseassert(_ticker != null)insideAnimationController.stop()is stripped in release builds, it throws an uncaughtNull check operator used on a null value(_TypeError) instead of a debug assertion.We hit this in production (release) on a coach mark shown on a screen the user navigated away from before the focus animation started. In debug it surfaces as:
Fix
Add a
mountedguard immediately beforeforward()in_runFocus:safeSetStateabove is alreadymounted-guarded, so this is the only remaining unguarded controller access on that path. Minimal, no behavior change when the widget is still mounted.(The same pattern exists on the
developbranch's restructured_runFocus; happy to mirror it there if you prefer.)