Skip to content

Side effects inside a factory capsule? #205

Closed Answered by GregoryConrad
opsb asked this question in Q&A
Discussion options

You must be logged in to vote

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 ..."));
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@GregoryConrad
Comment options

Answer selected by GregoryConrad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants