Skip to content

Commit 7e4c9e5

Browse files
author
Dhemas Nurjaya
committed
fix: add mounted guards to swipe animation callbacks to prevent setState after dispose
1 parent cda21bf commit 7e4c9e5

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

lib/screens/now_playing_screen.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ class _NowPlayingScreenState extends State<NowPlayingScreen>
183183
));
184184

185185
void listener() {
186+
if (!mounted) return;
186187
setState(() {
187188
_horizontalDragOffset = animation.value;
188189
});
@@ -192,6 +193,7 @@ class _NowPlayingScreenState extends State<NowPlayingScreen>
192193

193194
_swipeAnimationController.forward().then((_) {
194195
animation.removeListener(listener);
196+
if (!mounted) return;
195197
setState(() {
196198
_horizontalDragOffset = 0.0;
197199
_previewSong = null;
@@ -224,6 +226,7 @@ class _NowPlayingScreenState extends State<NowPlayingScreen>
224226
));
225227

226228
void listener() {
229+
if (!mounted) return;
227230
setState(() {
228231
_horizontalDragOffset = animation.value;
229232
});
@@ -233,6 +236,7 @@ class _NowPlayingScreenState extends State<NowPlayingScreen>
233236

234237
_swipeAnimationController.forward().then((_) {
235238
animation.removeListener(listener);
239+
if (!mounted) return;
236240
setState(() {
237241
_previewSong = null;
238242
_isSwipeAnimating = false;

0 commit comments

Comments
 (0)