zino-hofmann / graphql-flutter

A GraphQL client for Flutter, bringing all the features from a modern GraphQL client to one easy to use package.
https://zino-hofmann.github.io/graphql-flutter
MIT License
3.23k stars 613 forks source link

'HookElement._currentHookElement != null' #1339

Closed jaimejazarenoiii closed 1 year ago

jaimejazarenoiii commented 1 year ago

Whenever I click a button that runs a mutation it throws that error. Using stacked framework btw.

Here's the widget calling it.


class _SignInButton extends StackedHookView<SignInViewModel> {
  @override
  Widget builder(BuildContext context, SignInViewModel model) {
    return Mutation(
      options: MutationOptions(
        document: gql(context.queries.signIn()),
        onCompleted: (data) => { print(data) },
      ),
      builder: (RunMutation runMutation, QueryResult? result) {
        // if (result!.isLoading) return const LoadingSpinner();

        if (result?.hasException ?? false) {
          print(result?.exception.toString());
        }

        return TextButton(
            child: const Text(
              'Sign in',
              style: TextStyle(
                fontSize: 32,
              ),
            ),
            onPressed: () => {

              addStarMutation.runMutation({
                'email': 'test@gmail.com',
                'password': '123123123'
              })
            }
        );
      },
    );
  }
}
jaimejazarenoiii commented 1 year ago

Nevermind, found the issue. I was calling this

final addStarMutation = useMutation(
  MutationOptions(
    document: gql(signIn), // this is the mutation string you just created
    // you can update the cache based on results
    // or do something with the result.data on completion
    onCompleted: (dynamic resultData) {
      print(resultData);
    },
  ),
);

outside of the builder