KEMBAR78
Confusing behavior of Stream hooks with default preserveState=true behavior · Issue #312 · rrousselGit/flutter_hooks · GitHub
Skip to content

Confusing behavior of Stream hooks with default preserveState=true behavior #312

@rjpower

Description

@rjpower

Thanks for creating this library!

This isn't strictly a bug, but the preserveState=true default for useStream can lead to some confusing/inconsistent behavior. I observed this with an application where you have a parent stream that indicates transitions between application states, along with a child stream to show the underlying status:

class ChildEventType {}
class ChildEventA extends ChildEventType {}
class ChildEventB extends ChildEventType{}

enum AppState { a, b }

class AppEvent {
  AppState state;
  Stream<ChildEventType> childEvent;
}

Stream<AppEvent> appStream();

Expected behavior

I expect that should be impossible for an AppEvent to yield events which are inconsistent with the AppState, but the preserveState behavior on the stream gives this behavior.

You can see this behavior in the DartPad here:
https://dartpad.dev/?id=02aa39ef7799d520d4f6e7c3d332da23

I suspect "I'm holding it wrong", and there's a more correct way to do this, but having this as the default made it hard to track down. (I'm filing this partly in case others run into the same issue).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions