larryaasen / upgrader

A Flutter package for prompting users to upgrade when there is a newer version of the app in the store.
MIT License
531 stars 262 forks source link

Bad state: Stream has already been listened to. #312

Closed fotiDim closed 11 months ago

fotiDim commented 1 year ago

After upgrading to 8.0.0 I am getting:

════════ Exception caught by widgets library ═══════════════════════════════════
The following StateError was thrown building UpgradeAlert-[<'ua_1'>](state: UpgradeBaseState#4656c):
Bad state: Stream has already been listened to.

My app uses UpgradeAlert in two separate places and the exceptions is thrown during the second UpgradeAlert. I tried passing key with the same and also different values but makes no difference.

markalroberts commented 1 year ago

I get the same problem where I use onGenerateRoute to create a new MaterialPageRoute - it displays fine the first time but then breaks whenever I try to navigate to a different route - guessing somewhere it needs to dispose/stop listening to the stream?

larryaasen commented 1 year ago

@fotiDim @markalroberts Thanks for reporting this issue with upgrader. Can you attach the upgrader log here so we can review it? https://github.com/larryaasen/upgrader#reporting-issues

sgrodzicki commented 1 year ago

This for me only happens with the shared instance, so I guess including logs is not possible in that case.

return UpgradeAlert(
  child: Scaffold(),
);
adar2378 commented 1 year ago

Same issue. The stacktrace has no reference to code but rather to only stream controller library of dart

adar2378 commented 1 year ago

I guess this should be a broadcast stream

final _streamController = StreamController<UpgraderEvaluateNeed>(); 
// should be StreamController<UpgraderEvaluateNeed>.broadcast()

@larryaasen Could you please check? https://github.com/larryaasen/upgrader/blob/db563d2b8f9648358ddc0456a114d99898fbe908/lib/src/upgrader.dart#L160

larryaasen commented 1 year ago

The use of upgrader has far surpassed what I had envisioned for this package, and it is being used in cases where I had never imagined. This particular issue was never a case I had anticipated: instantiating more than one UpgradeAlert.

Thanks for pointing out this issue and suggesting changes. I will get a fix out as soon as possible.

larryaasen commented 12 months ago

I created a branch with a fix and posted this new pre-release version: https://pub.dev/packages/upgrader/versions/8.1.0-alpha.1 Please check it out and let me know if this solves your issues.

larryaasen commented 12 months ago

I fixed a few small issues with the first fix and posted an updated pre-release version: https://pub.dev/packages/upgrader/versions/8.1.0-alpha.2

larryaasen commented 11 months ago

Version 8.1.0 has been published with this fix.