Side effects inside a factory capsule? #205
-
I have the following AsyncValue<File> Function(String uri) imageStoreImage(CapsuleHandle use) {
final env = use(syncEnvCapsule);
return (uri) {
return use.future(env.imageStore.openImage(uri));
};
} which I intend to use as Widget _image(BuildContext context, WidgetHandle use) {
final asyncImage = use(imageStoreImage)(uri);
return asyncImage
.map<Widget>((data) => Image.file(data, width: 140, height: 140, fit: BoxFit.cover))
.dataOr(Text("Loading ..."));
} The issue is that the Rearch wants the |
Beta Was this translation helpful? Give feedback.
Answered by
GregoryConrad
Jul 13, 2024
Replies: 1 comment 1 reply
-
Easy fix! Just move the side effect to whatever consumes the factory/action capsule. Future<File> Function(String uri) imageStoreImage(CapsuleHandle use) {
final env = use(syncEnvCapsule);
return env.imageStore.openImage;
}
Widget _image(BuildContext context, WidgetHandle use) {
// See comment below for why this wouldn't work directly:
// final imageFuture = use(imageStoreImage)(uri);
return use.future(imageFuture)
.map<Widget>((data) => Image.file(data, width: 140, height: 140, fit: BoxFit.cover))
.dataOr(Text("Loading ..."));
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
GregoryConrad
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Easy fix! Just move the side effect to whatever consumes the factory/action capsule.