diff --git a/CHANGELOG.md b/CHANGELOG.md index f3095f45..2f4b09ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 5.1.1 [#unreleased] - Fixed [#659](https://github.com/SimformSolutionsPvtLtd/showcaseview/issues/659) - Fix null-check crash in `ShowcaseController._initRootWidget` when the `Showcase` is unmounted in the same frame it mounts. Fixed by @[apurva-simform](https://github.com/apurva-simform) +- Fixed [#662](https://github.com/SimformSolutionsPvtLtd/showcaseview/issues/662) - Fix crash and stuck scroll-loading overlay when an auto-scroll target is unmounted while the scroll animation is running. Fixed by @[fellmonkey](https://github.com/fellmonkey) ## 5.1.0 diff --git a/lib/src/showcase/showcase_controller.dart b/lib/src/showcase/showcase_controller.dart index 42ee379f..1c7fe436 100644 --- a/lib/src/showcase/showcase_controller.dart +++ b/lib/src/showcase/showcase_controller.dart @@ -181,13 +181,43 @@ class ShowcaseController { duration: showcaseView.scrollDuration, alignment: config.scrollAlignment, ); + // The target may have been unmounted while we were waiting for the + // animation to finish (e.g. the page rebuilt after async data arrived). + if (!_mounted) { + isScrollRunning = false; + _recoverFromLostTarget(); + return; + } // For the cases when scrollAlignment causes overscroll. await _waitForScrollToSettle(); + if (!_mounted) { + isScrollRunning = false; + _recoverFromLostTarget(); + return; + } isScrollRunning = false; setupShowcase(shouldUpdateOverlay: shouldUpdateOverlay); } + /// Recovers the sequence when the target is unmounted mid auto-scroll. + /// + /// The overlay is still showing [Showcase.scrollLoadingWidget] and cannot be + /// rebuilt from here without a context, so control is handed back to + /// [ShowcaseView]: skip ahead when [ShowcaseView.skipIfTargetNotPresent] is + /// set, otherwise end the showcase instead of leaving the barrier stuck. + void _recoverFromLostTarget() { + // [ShowcaseView._onStart] is still awaiting scrollIntoView, so defer until + // after the frame rather than re-entering the sequence mid-await. + _runLater(() { + if (showcaseView.skipIfTargetNotPresent) { + showcaseView.next(force: true); + } else { + showcaseView.dismiss(); + } + }); + } + /// Handles tap on barrier area. /// /// Respects [Showcase.disableBarrierInteraction] and [ShowcaseView @@ -468,6 +498,7 @@ class ShowcaseController { Duration checkInterval = const Duration(milliseconds: 60), int maxChecks = 120, }) async { + if (!_mounted) return; final scrollableState = Scrollable.maybeOf(_context); if (scrollableState == null) return;