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
16
lib/app.dart
16
lib/app.dart
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'backend.dart';
|
import 'backend.dart';
|
||||||
|
|
@ -14,6 +16,7 @@ class _AppState extends State<App> with SingleTickerProviderStateMixin {
|
||||||
|
|
||||||
AnimationController playerBarAnimation;
|
AnimationController playerBarAnimation;
|
||||||
Backend backend;
|
Backend backend;
|
||||||
|
StreamSubscription<bool> playerActiveSubscription;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
|
@ -30,7 +33,12 @@ class _AppState extends State<App> with SingleTickerProviderStateMixin {
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
|
|
||||||
backend = Backend.of(context);
|
backend = Backend.of(context);
|
||||||
backend.playerActive.listen((active) =>
|
|
||||||
|
if (playerActiveSubscription != null) {
|
||||||
|
playerActiveSubscription.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
playerActiveSubscription = backend.playerActive.listen((active) =>
|
||||||
active ? playerBarAnimation.forward() : playerBarAnimation.reverse());
|
active ? playerBarAnimation.forward() : playerBarAnimation.reverse());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,4 +87,10 @@ class _AppState extends State<App> with SingleTickerProviderStateMixin {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
super.dispose();
|
||||||
|
playerActiveSubscription.cancel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import '../backend.dart';
|
import '../backend.dart';
|
||||||
|
|
@ -11,6 +13,7 @@ class _PlayPauseButtonState extends State<PlayPauseButton>
|
||||||
with SingleTickerProviderStateMixin {
|
with SingleTickerProviderStateMixin {
|
||||||
AnimationController playPauseAnimation;
|
AnimationController playPauseAnimation;
|
||||||
Backend backend;
|
Backend backend;
|
||||||
|
StreamSubscription<bool> playingSubscription;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
|
@ -25,7 +28,12 @@ class _PlayPauseButtonState extends State<PlayPauseButton>
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
|
|
||||||
backend = Backend.of(context);
|
backend = Backend.of(context);
|
||||||
backend.playing.listen((playing) =>
|
|
||||||
|
if (playingSubscription != null) {
|
||||||
|
playingSubscription.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
playingSubscription = backend.playing.listen((playing) =>
|
||||||
playing ? playPauseAnimation.forward() : playPauseAnimation.reverse());
|
playing ? playPauseAnimation.forward() : playPauseAnimation.reverse());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -39,4 +47,10 @@ class _PlayPauseButtonState extends State<PlayPauseButton>
|
||||||
onPressed: backend.playPause,
|
onPressed: backend.playPause,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
super.dispose();
|
||||||
|
playingSubscription.cancel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue