1

I have copied this code from the graphql_flutter pub.dev page still getting this error when I hover over the builder. All I did is put in my query and changed some values inside the builder that relates to my query.

Error - The argument type 'StatelessWidget Function(QueryResult, {Future Function(FetchMoreOptions) fetchMore, void Function() refetch})' can't be assigned to the parameter type 'Widget Function(QueryResult, {Future Function(FetchMoreOptions)? fetchMore, Future<QueryResult?> Function()? refetch})'.

  final String _query = """
    query {
      users {
          id
          name
          email
      }
  } """;
  @override
  Widget build(BuildContext context) {    
    return Query(
      options: QueryOptions(
        document: gql(_query), // this is the query string you just created
        pollInterval: Duration(seconds: 10),
      ),
      builder: (QueryResult result, {VoidCallback refetch, FetchMore fetchMore}) {
        if (result.hasException) {
          return Text(result.exception.toString());
        }

        if (result.isLoading) {
          return Text('Loading');
        }
        List repositories = result.data['users'];
        return ListView.builder(
            itemCount: repositories.length,
            itemBuilder: (context, index) {
              final repository = repositories[index];
              return Text(repository['name']);
            });
      },
    );
  }
}```

1 Answer 1

1
builder: (QueryResult result, {
                  Future<QueryResult> Function(FetchMoreOptions)? fetchMore,
                  Future<QueryResult?> Function()? refetch,
                }) {

Updating the builder function syntax to match the 'parameter type' works.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.