fix: prevent null crash in auto-play timer when pageController.page - #495
Open
laksh-scapia wants to merge 2 commits into
Open
fix: prevent null crash in auto-play timer when pageController.page#495laksh-scapia wants to merge 2 commits into
laksh-scapia wants to merge 2 commits into
Conversation
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.
fix: prevent null crash in auto-play timer when pageController.page is null
Problem
The auto-play timer callback crashed with
Null check operator used on a null valueatcarousel_slider.dart:144:Two compounding bugs caused this:
Bug 1 — wrong
dispose()ordersuper.dispose()synchronously detaches thePageControllerfrom thePageView, makingpageController.pagereturnnull. The timer was not cancelled until after that, leaving a window where the callback could fire against a detached controller.Bug 2 — unsafe null-unwrap of
pageController.pagepageController.pageis adouble?— it returnsnullwhenever the controller is not attached to a scrollable. This can happen aftersuper.dispose()runs, and also during the window indidUpdateWidgetwhere a brand-newPageControlleris assigned tocarouselState!.pageControllerbefore the widget rebuilds. The existing!mountedguard does not protect against either case.Fix
1. Swap
dispose()order — cancel the timer before any Flutter teardown:2. Guard
pagebefore unwrapping — treat a null page as a bail-out signal, layered alongside the existing!mountedguard: