Replies: 2 comments 4 replies
-
This AsyncValue<T>? nullableStream<T>(Stream<T>? stream) {
final (getValue, setValue) = use.data<AsyncValue<T>>(
AsyncLoading<T>(None<T>()),
);
final (getSubscription, setSubscription) =
use.data<StreamSubscription<T>?>(null);
use.effect(() => getSubscription()?.cancel, [getSubscription()]);
final oldStream = use.previous(stream);
final needToInitializeState = stream != oldStream;
if (needToInitializeState) {
setValue(AsyncLoading(getValue().data));
setSubscription(
stream?.listen(
(data) => setValue(AsyncData(data)),
onError: (Object error, StackTrace trace) =>
setValue(AsyncError(error, trace, getValue().data)),
cancelOnError: false,
),
);
}
return stream == null ? null : getValue();
} |
Beta Was this translation helpful? Give feedback.
4 replies
-
Tracking this bug in #195 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a Scrollable widget whose children are disposed if they are not visible. One of the children is
_AsyncImage
, aRearchConsumer
that uses thefuture
side effect to precache the image (from the Internet) and show a loading spinner while loading. So the problem came when I scroll quickly enough to get this widget created and disposed before the image get loaded. I got a Stream error which I'm 99% sure it is related touse.future
. Do you have a solution for this scenario?Widget:
Error stack trace (on the web):
Beta Was this translation helpful? Give feedback.
All reactions