You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Null check operator used on a null value on Switch _pressedThumbExtension #179532
uses bang operator in _pressedThumbExtension . However, _pressedThumbExtension is nullable and _pressedThumbExtension insert value only when _stopPressAnimation is false.
It would be more helpful if you can provide a reproduction that triggers this crash. This issue can use such a production for future tracking, and your PR will certainly need this reproduction for regression test.
Looking at packages/flutter/lib/src/material/switch.dart, the crash comes from _pressedThumbExtension being declared as late double? (line 1507) but only assigned inside the if (!_stopPressAnimation) block (line 1526). When _stopPressAnimation is true (which happens when reaction.status == AnimationStatus.reverse on the very first paint call after a touch lifts), the field is never initialized.
_computeThumbPaintOffset uses _pressedThumbExtension! unconditionally at lines 1720 and 1724, regardless of _stopPressAnimation. So on the first paint() with _stopPressAnimation = true, you get a LateInitializationError.
The fix is to drop late and give the field a default value of 0 instead:
Then remove the ! in _computeThumbPaintOffset (lines 1720, 1724), since the field is no longer nullable. The isCupertino paths at lines 1559, 1565, and 1616 that use _pressedThumbExtension! are already inside the if (!_stopPressAnimation) guard, so they just become plain _pressedThumbExtension after the type change.
This guarantees the field always has a valid value before _computeThumbPaintOffset runs, regardless of animation state or frame timing.
Activity
dkwingsmt commentedon Dec 10, 2025
It would be more helpful if you can provide a reproduction that triggers this crash. This issue can use such a production for future tracking, and your PR will certainly need this reproduction for regression test.
ishaquehassan commentedon Feb 27, 2026
Looking at
packages/flutter/lib/src/material/switch.dart, the crash comes from_pressedThumbExtensionbeing declared aslate double?(line 1507) but only assigned inside theif (!_stopPressAnimation)block (line 1526). When_stopPressAnimationistrue(which happens whenreaction.status == AnimationStatus.reverseon the very first paint call after a touch lifts), the field is never initialized._computeThumbPaintOffsetuses_pressedThumbExtension!unconditionally at lines 1720 and 1724, regardless of_stopPressAnimation. So on the firstpaint()with_stopPressAnimation = true, you get aLateInitializationError.The fix is to drop
lateand give the field a default value of0instead:Then remove the
!in_computeThumbPaintOffset(lines 1720, 1724), since the field is no longer nullable. The isCupertino paths at lines 1559, 1565, and 1616 that use_pressedThumbExtension!are already inside theif (!_stopPressAnimation)guard, so they just become plain_pressedThumbExtensionafter the type change.This guarantees the field always has a valid value before
_computeThumbPaintOffsetruns, regardless of animation state or frame timing.[material_ui] Fix Switch throwing when first painted mid-animation (f…