You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i was using flutter_hooks (but the problem will probably show for streambuilder, provider etc. as well) where i have a widget like this:
HookBuilder(builder: (context) {
final snapshot =useStream(cmd.isExecuting);
returnText('hello');
})
The problem is, useStream will listen to a stream until it receives a new stream, then it will unsub to the previous and listen to the new stream...
isExecuting is a BehaviorSubject and immediately pushes the latest value, which useStream will take and calls setState();
Now the HookBuilder will build again, cmd.isExecuting returns a new stream, useStream will listen to the new stream, gets the first value from BehaviorSubject and rebuilds the widget... and again and again.
I can solve this with cmd.isExecuting.skip(1) but wouldn't it be better to change
Stream<bool> get canExecute => _canExecuteSubject.startWith(true).distinct();
into
Stream<bool> _canExecute
Stream<bool> get canExecute => _canExecute ??= _canExecuteSubject.startWith(true).distinct();
The text was updated successfully, but these errors were encountered:
Hi,
i was using flutter_hooks (but the problem will probably show for streambuilder, provider etc. as well) where i have a widget like this:
The problem is, useStream will listen to a stream until it receives a new stream, then it will unsub to the previous and listen to the new stream...
isExecuting is a BehaviorSubject and immediately pushes the latest value, which useStream will take and calls setState();
Now the HookBuilder will build again, cmd.isExecuting returns a new stream, useStream will listen to the new stream, gets the first value from BehaviorSubject and rebuilds the widget... and again and again.
I can solve this with
cmd.isExecuting.skip(1)
but wouldn't it be better to changeinto
The text was updated successfully, but these errors were encountered: