Closed tk2232 closed 2 years ago
@tk2232 thank you for these edge cases issues. You are one of the best contributor. Here is the source of the bug
In states_rebuilder if a future resolves with a stream or on other function, the state will be mutated to listed to the stream.
All I have to do to fix the issue is to check that the state is not itself a stream.
Here is the fix:
subscription = stream.listen(
(event) {
if (event is T Function() || (event is Stream && this is! ReactiveModelImp<Stream<dynamic>>)) {
// This is called from async read persisted state.
// The state is read from local storage asynchronously. So as in
// InjectedImpRedoPersistState.mockableCreator the creator return
// a function after awaiting for the future.
_snapState = _snapState
.oldSnapState!; // Return to old state without notification.
setStateNullable(
(_) => event is T Function() ? event() : event,
middleSetState: middleSetState,
);
return;
}
middleSetState(StateStatus.hasData, event);
if (completer?.isCompleted == false) {
completer!.complete();
}
},
Thank you for the quick solution. Ok something in the direction I thought. I will test it.
Of course I will try to find more bugs and suggest improvements. For me there is no better state management solution
I tested the new builder OnBuilder.createFuture and noticed a strange behavior.
The reactive model loses its state on complex objects.
Working example
Not working
is in waiting state forever. In another case, the stream is even zero, but this example is unfortunately too complex to reproduce here