Skip to content

Mutations cannot be used in FutureBuilder #4390

@Curs3W4ll

Description

@Curs3W4ll

Describe the bug
Mutations cannot always be used where ref.read can.
For example, we cannot trigger a mutation in a FutureBuilder future method.

I'm not sure if this is a bug or a limitation of the mutation feature, but I didn't find anything mentioning this limitation.

To Reproduce

<Please add a small sample to that can be executed to reproduce the problem. As a general rule, 100 lines is the maximum>
Try using a mutation inside of a FutureBuilder future, like the following:

  Future<String> _myFuture() async {
    return myMutation.get(ref);
  }

And using a FutureBuilder in the widget tree:

        FutureBuilder<String>(
          future: _myFuture,
          builder: (context, snapshot) {
            ...
          }

Expected behavior
A clear and concise description of what you expected to happen.

I'm not sure if this should work or not. But I didn't find anything mentioning this limitation of mutations.

If this is indeed not possible, what is the recommended way to retrieve data (ideally using a mutation so we don't have to handle the loading state ourself) on widget initialization?

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions