graphql_flutter mutation widget shows error –

Issue

I am not sure if I understand this error at all. Anyone with experience using graphql_flutter package please help out. Totally new to Flutter and graphql. But so far I have figured the backend.

My mutation works in graphiql, trying to make it work in flutter. This is error that shows up when I hover over those red lines.

ERROR – The argument type ‘Column Function(MultiSourceResult Function(Map<String, dynamic>, {Object? optimisticResult}), QueryResult)’ can’t be assigned to the parameter type ‘Widget Function(MultiSourceResult Function(Map<String, dynamic>, {Object? optimisticResult}), QueryResult?)’. (Documentation)

Here is the snip –
enter image description here

class GraphQlMutations {

  String createUser() { return"""
    mutation createUser(\$id: String!, \$name: String!, \$email: String!) {
      createUser(objects: [{ id: $id, name: $name, code: $code }]) {
        returning {
          id
          name
          email
        }
      }
    }
  """;
  } 
}

Solution

Compare both declarations in your error and see the difference:

Column Function(MultiSourceResult Function(Map<String, dynamic>, {Object? optimisticResult}), QueryResult)
Widget Function(MultiSourceResult Function(Map<String, dynamic>, {Object? optimisticResult}), QueryResult?)

Since Column is a Widget, the only real difference is the nullability of QueryResult.
Therefore, change

builder: (RunMutation createUser, QueryResult result)

to

builder: (RunMutation createUser, QueryResult? result)

and handle the case where the result is null.

Answered By – enzo

Answer Checked By – David Goodson (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.