Closed synstin closed 2 months ago
Hi @synstin
Thanks for your interest in the package.
Try to convert the Stream to a Broadcast Stream: This allows multiple listeners. You can do this by using the .asBroadcastStream()
method on your stream. This is useful if you need multiple parts of your app to listen to the same stream.
subscription = Alarm.ringStream.stream.asBroadcastStream().listen((event) => print('ring'));
Let me know if it fixes you issue.
@gdelataillade
The same thing happens when apply asBroadcastStream(). And I only want to keep one stream, and I want to close the stream when I'm done using it. I don't know why I'm still getting that error after calling close.
Hi @synstin
Ok I will see if I can change the plugin's stream to fix your issue. In the meantime, can you keep the same stream all the time ?
Hey @synstin
Are you sure your subscription.cancel();
is called ?
@gdelataillade I'm pretty sure cancel is called. Streams from other plugins ex) FGBG are closing without problems
We really appreciate your attention to the issue and will be using one stream unclosed for now while it is fixed.
@synstin
Alright. Just to be sure you can log the onClose
method, maybe your controller is not disposed well.
In the meantime, you can make your stream static. This way, you can keep it in the HomeController scope and initialize only once. It's what I did in the example app.
class HomeController extends GetxController {
static StreamSubscription<AlarmSettings>? subscription;
@override
void onInit() {
subscription ??= Alarm.ringStream.stream.listen((event) => print('ring'));
}
@override
void onClose() async {
subscription?.cancel();
print('HomeController: onClose');
}
}
Hi @synstin
Any updates on this issue ?
Could this perhaps help you?
if (!Alarm.ringStream.hasListener) {
print("Alarm STREAMING");
Alarm.ringStream.stream.listen((_) => print('ring'));
} else {print("STREAM is already active");}
Similar issue: #153 Status: Work in progress
Hi @synstin @Flash0509
I just released version 3.1.0
. It may fix your issues with the stream. Let me know how it goes.
Alarm plugin version 2.1.1
Describe the bug
I subscribe to ringStream when I go to the home page and close the subscription when I leave the page.
However, when I go to the homepage, then back, then go to the homepage, I get the error
Bad state: Stream has already been listened to.
I don't know why I get that error even though I closed the stream. can you help?Device info every device