Operation Widget
Since the entire Ferry architecture is built around native Dart Streams, the Operation
Widget is just a simple wrapper around the Flutter StreamBuilder
Widget.
This example assumes we've registered our Client
instance with get_it
, but you can use any dependency injection method.
Usage with Mutations
While you can use the Operation
widget with any GraphQL operation, including Mutations, you probably don't need to use the widget.
It's often easier to just execute the Mutation directly:
However, sometimes we may want to show the result of calling a mutation in our Flutter UI. In that case, we can still use the Operation
Widget, but we probably don't want the mutation to run immediately when the Widget loads. To tell Ferry not to execute the mutation immediately, we can set executeOnListen = false
on our request.
Now we can use this request in our Operation
Widget just as we did with our AllPokemon
Query above. When we are ready to execute our mutation, we simply add it to the Client.requestController
.