mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 18:57:25 +01:00
Stop listening to streams in dispose()
This commit is contained in:
parent
437e30933a
commit
03fb8b2c49
2 changed files with 30 additions and 2 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../backend.dart';
|
||||
|
|
@ -11,6 +13,7 @@ class _PlayPauseButtonState extends State<PlayPauseButton>
|
|||
with SingleTickerProviderStateMixin {
|
||||
AnimationController playPauseAnimation;
|
||||
Backend backend;
|
||||
StreamSubscription<bool> playingSubscription;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
|
@ -25,7 +28,12 @@ class _PlayPauseButtonState extends State<PlayPauseButton>
|
|||
super.didChangeDependencies();
|
||||
|
||||
backend = Backend.of(context);
|
||||
backend.playing.listen((playing) =>
|
||||
|
||||
if (playingSubscription != null) {
|
||||
playingSubscription.cancel();
|
||||
}
|
||||
|
||||
playingSubscription = backend.playing.listen((playing) =>
|
||||
playing ? playPauseAnimation.forward() : playPauseAnimation.reverse());
|
||||
}
|
||||
|
||||
|
|
@ -39,4 +47,10 @@ class _PlayPauseButtonState extends State<PlayPauseButton>
|
|||
onPressed: backend.playPause,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
playingSubscription.cancel();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue