-
-
Notifications
You must be signed in to change notification settings - Fork 504
Closed
Description
I'm having an issue with the new stream apis, where setState
is being called after my widget is disposed. I can't work out what I've done wrong.
Relevant code:
void connect() async {
AudioService.connect();
playbackStateSubscription?.cancel();
playbackStateSubscription = AudioService.playbackStateStream.listen((PlaybackState playbackState) {
setState(() {
_playbackState = playbackState;
print(playbackState);
});
});
}
void stopListening() {
playbackStateSubscription?.cancel();
playbackStateSubscription = null;
}
@override
void initState() {
super.initState();
connect();
}
@override
void dispose() {
stopListening();
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
switch (state) {
case AppLifecycleState.resumed:
connect();
break;
case AppLifecycleState.paused:
stopListening();
AudioService.disconnect();
break;
default:
break;
}
}
Metadata
Metadata
Assignees
Labels
No labels