Closed SkyOfFeather closed 11 months ago
Same here. Having the same error
═══════ Exception caught by widgets library ═══════════════════════════════════ Bad state: Stream has already been listened to. The relevant error-causing widget was SlideCountdownSeparated payment_board.dart:91 ════════════════════════════════════════════════════════════════════════════════
Hi thanks for filling this issue. Just release dev version for fix this issue checkout slide_countdown: ^1.1.0-dev.1.
The error is still present in 1.0.2
The error is still present in 1.0.2
@JgomesAT Please checkout pre release version https://pub.dev/packages/slide_countdown/versions/1.1.0-dev.2
the following changes to duration_stream fixes the bad state issue; however, i am still a little confused about the stream handling in general and why SliceCountdown.didUpdateWidget
disposes streams frequently...
@@ -12,7 +12,7 @@ class StreamDuration {
}
final StreamController<Duration> _streamController =
- StreamController<Duration>();
+ StreamController<Duration>.broadcast();
Duration _durationLeft = Duration.zero;
@@ -52,17 +52,18 @@ class StreamDuration {
}
void play() {
- _streamSubscription = Stream<Duration>.periodic(
+ _streamSubscription ??= Stream<Duration>.periodic(
config.periodic,
(_) {
- if (!(_streamSubscription?.isPaused ?? true)) {
- if (_isCountUp) {
- return _durationLeft += config.periodic;
- } else {
- return _durationLeft -= config.periodic;
- }
+ final paused = _streamSubscription?.isPaused ?? true;
+ if (paused) return _durationLeft; // was: Duration.zero; why?
+
+ if (_isCountUp) {
+ _durationLeft += config.periodic;
+ } else {
+ _durationLeft -= config.periodic;
}
- return Duration.zero;
+ return _durationLeft;
},
).listen(
followup: i activated ExampleControlDuration()
in example.dart, and found the play
, resume
behavior to be broken.
removing SlideCountdown#didUpdateWidget
entirely fixed this.
@tomquas i have release a new version, remove didUpdateWidget from both SlideCountdown
and SlideCountdownSeparated
.
@farhanfadila1717 thank you! may i ask: was didUpdateWidget
an evil leftover from past, or what was the intention behind it?
When I refactor SlideCountdown
to improve performance, full customize i also upgrade StreamDuration
package. The error seems come from StreamDuration
reinit when didUpdateWidget
called.
@farhanfadila1717 1.2.1 After the upgrade, the error does not occur, but the textStyle property is not applied.
@synstin yep the property depercated, try style
instead
@farhanfadila1717 It works perfectly. Thank you.
When I use hot reload, this error will be reported on 1.0.2. Strangely, I saw a more detailed description of 1.0.2 that fixed this error.
The following StateError was thrown building RawSlideCountdown: Bad state: Stream has already been listened to.