ReactiveX / rxdart

The Reactive Extensions for Dart
http://reactivex.io
Apache License 2.0
3.37k stars 271 forks source link

Bad state: Stream has already been listened to CombineLatestStream #763

Open victorcode1 opened 3 months ago

victorcode1 commented 3 months ago

I have this problem when navigating between widgets either with go router or with navigator I think a dispose() event is necessary for this class

`

When the exception was thrown, this was the stack:

4 _StreamBuilderBaseState._subscribe (package:flutter/src/widgets/async.dart:130:38)

async.dart:130

5 _StreamBuilderBaseState.initState (package:flutter/src/widgets/async.dart:104:5)

async.dart:104

6 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5748:55)

framework.dart:5748

7 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5593:5)

framework.dart:5593 ... Normal element mounting (9 frames)

16 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4468:16)

framework.dart:4468

17 Element.updateChild (package:flutter/src/widgets/framework.dart:3963:18)

framework.dart:3963

18 _LayoutBuilderElement._rebuildWithConstraints.updateChildCallback (package:flutter/src/widgets/layout_builder.dart:207:18)

layout_builder.dart:207

19 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:3038:19)

framework.dart:3038

20 _LayoutBuilderElement._rebuildWithConstraints (package:flutter/src/widgets/layout_builder.dart:231:12)

layout_builder.dart:231

21 RenderObject.invokeLayoutCallback. (package:flutter/src/rendering/object.dart:2719:59)

object.dart:2719

22 PipelineOwner._enableMutationsToDirtySubtrees (package:flutter/src/rendering/object.dart:1098:15)

object.dart:1098

23 RenderObject.invokeLayoutCallback (package:flutter/src/rendering/object.dart:2719:14)

object.dart:2719

24 RenderConstrainedLayoutBuilder.rebuildIfNecessary (package:flutter/src/widgets/layout_builder.dart:278:5)

layout_builder.dart:278

25 _RenderLayoutBuilder.performLayout (package:flutter/src/widgets/layout_builder.dart:369:5)

layout_builder.dart:369

26 RenderObject.layout (package:flutter/src/rendering/object.dart:2608:7)

object.dart:2608

27 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:21)

proxy_box.dart:111

28 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:2446:7)

object.dart:2446

29 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:1052:18)

object.dart:1052

30 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:1065:15)

object.dart:1065

31 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:602:23)

binding.dart:602

32 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:1164:13)

binding.dart:1164

33 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:468:5)

binding.dart:468

34 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1397:15)

binding.dart:1397

35 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1318:9)

binding.dart:1318

36 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1176:5)

binding.dart:1176

40 _invoke (dart:ui/hooks.dart:314:10)

hooks.dart:314

41 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:419:5)

platform_dispatcher.dart:419

42 _drawFrame (dart:ui/hooks.dart:283:31)

hooks.dart:283 (elided 7 frames from dart:async)

`

hoc081098 commented 3 months ago

It is single-subscription stream, consider converting it to broadcast stream by using share(), shareValue(), shareValueSeeded(), ...

hoc081098 commented 3 months ago
late final valueStream = originalStream.publishValueSeeded(...)
late final StreamSubscription<void> sub;

initState() {
  sub = valueStream.connect();
}

dispose() {
  sub.cancel()
}

// Use valueStream with StreamBuilder...