flutter_graphql 1.0.0-rc.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 44

Flutter GraphQL #

version MIT License All Contributors PRs Welcome

Watch on GitHub Star on GitHub

Table of Contents #

About this project #

GraphQL brings many benefits, both to the client: devices will need less requests, and therefore reduce data useage. And to the programer: requests are arguable, they have the same structure as the request.

This project combines the benefits of GraphQL with the benefits of Streams in Dart to deliver a high performace client.

The project took inspriation from the Apollo GraphQL client, great work guys!

Note: Still in Beta Docs is coming soon Support for all Apollo Graphql component supported props is coming soon

Installation #

First depend on the library by adding this to your packages pubspec.yaml:

dependencies:
  flutter_graphql: ^1.0.0-rc.1

Now inside your Dart code you can import it.

import 'package:flutter_graphql/flutter_graphql.dart';

Usage #

To use the client it first needs to be initialized with an link and cache. For this example we will be uing an HttpLink as our link and InMemoryCache as our cache. If your endpoint requires authentication you can provide some custom headers to HttpLink.

For this example we will use the public GitHub API.

...

import 'package:flutter_graphql/flutter_graphql.dart';

void main() {
  HttpLink link = HttpLink(
    uri: 'https://api.github.com/graphql',
    headers: <String, String>{
      'Authorization': 'Bearer <YOUR_PERSONAL_ACCESS_TOKEN>',
    },
  );

  ValueNotifier<GraphQLClient> client = ValueNotifier(
    GraphQLClient(
      cache: InMemoryCache(),
      link: link,
    ),
  );

  ...
}

...

GraphQL Provider #

In order to use the client, you Query and Mutation widgets to be wrapped with the GraphQLProvider widget.

We recommend wrapping your MaterialApp with the GraphQLProvider widget.

  ...

  return GraphQLProvider(
    client: client,
    child: MaterialApp(
      title: 'Flutter Demo',
      ...
    ),
  );

  ...

Offline Cache #

The in-memory cache can automatically be saved to and restored from offline storage. Setting it up is as easy as wrapping your app with the CacheProvider widget.

It is required to place the CacheProvider widget is inside the GraphQLProvider widget, because GraphQLProvider makes client available trough the build context.

...

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GraphQLProvider(
      client: client,
      child: CacheProvider(
        child: MaterialApp(
          title: 'Flutter Demo',
          ...
        ),
      ),
    );
  }
}

...

You can setup authentication headers and other custom links just like you do with Apollo Graphql

  import 'dart:async';

  import 'package:flutter/material.dart';
  import 'package:flutter_graphql/flutter_graphql.dart';
  import 'package:flutter_graphql/src/link/operation.dart';
  import 'package:flutter_graphql/src/link/fetch_result.dart';

  class AuthLink extends Link {
    AuthLink()
        : super(
      request: (Operation operation, [NextLink forward]) {
        StreamController<FetchResult> controller;

        Future<void> onListen() async {
          try {
            var token = await AuthUtil.getToken();
            operation.setContext(<String, Map<String, String>>{
              'headers': <String, String>{'Authorization': '''bearer $token'''}
            });
          } catch (error) {
            controller.addError(error);
          }

          await controller.addStream(forward(operation));
          await controller.close();
        }

        controller = StreamController<FetchResult>(onListen: onListen);

        return controller.stream;
      },
    );
  }

  var cache = InMemoryCache();

  var authLink = AuthLink()
      .concat(HttpLink(uri: 'http://yourgraphqlserver.com/graphql'));
      
  final ValueNotifier<GraphQLClient> client = ValueNotifier(
    GraphQLClient(
      cache: cache,
      link: authLink,
    ),
  );

  final ValueNotifier<GraphQLClient> anotherClient = ValueNotifier(
    GraphQLClient(
      cache: cache,
      link: authLink,
    ),
  );
    

However note that flutter-graphql does not inject __typename into operations the way apollo does, so if you aren't careful to request them in your query, this normalization scheme is not possible.

Normalization #

To enable apollo-like normalization, use a NormalizedInMemoryCache:

ValueNotifier<GraphQLClient> client = ValueNotifier(
  GraphQLClient(
    cache: NormalizedInMemoryCache(
      dataIdFromObject: typenameDataIdFromObject,
    ),
    link: link,
  ),
);

dataIdFromObject is required and has no defaults. Our implementation is similar to apollo's, requiring a function to return a universally unique string or null. The predefined typenameDataIdFromObject we provide is similar to apollo's default:

String typenameDataIdFromObject(Object object) {
  if (object is Map<String, Object> &&
      object.containsKey('__typename') &&
      object.containsKey('id')) {
    return "${object['__typename']}/${object['id']}";
  }
  return null;
}

However note that flutter-graphql does not inject __typename into operations the way apollo does, so if you aren't careful to request them in your query, this normalization scheme is not possible.

Queries #

To create a query, you just need to define a String variable like the one below. With full support of fragments

const GET_ALL_PEOPLE = '''
  query getPeople{
    readAll{
      name
      age
      sex
    }
  }
''';

In your widget:

...

Query(
  options: QueryOptions(
    document: GET_ALL_PEOPLE, // this is the query string you just created
    pollInterval: 10,
  ),
  builder: (QueryResult result) {
    if (result.errors != null) {
      return Text(result.errors.toString());
    }

    if (result.loading) {
      return Text('Loading');
    }

    // it can be either Map or List
    List people = result.data['getPeople'];

    return ListView.builder(
      itemCount: people.length,
      itemBuilder: (context, index) {
        final repository = people[index];

        return Text(people['name']);
    });
  },
);

...

Other examples with query argments and passing in a custom graphql client

const READ_BY_ID = '''
  query readById(\$id: String!){
    readById(ID: \$id){
      name
      age
      sex
    }
  }
  
  
final ValueNotifier<GraphQLClient> userClient = ValueNotifier(
  GraphQLClient(
    cache: cache,
    link: authLinkProfile,
  ),
);

''';

In your widget:

...

Query(
  options: QueryOptions(
    document: READ_BY_ID, // this is the query string you just created
    pollInterval: 10,
    client: userClient.value
  ),
  builder: (QueryResult result) {
    if (result.errors != null) {
      return Text(result.errors.toString());
    }

    if (result.loading) {
      return Text('Loading');
    }

    // it can be either Map or List
    List person = result.data['getPeople'];

    return Text(person['name']);
  },
);

...

Mutations #

Again first create a mutation string:

const LIKE_BLOG = '''
  mutation likeBlog(\$id: Int!) {
    likeBlog(id: \$id){
      name
      author {
        name
        displayImage
      }
  }
''';

The syntax for mutations is fairly similar to that of a query. The only diffence is that the first argument of the builder function is a mutation function. Just call it to trigger the mutations (Yeah we deliberately stole this from react-apollo.)

...

Mutation(
  options: MutationOptions(
    document: LIKE_BLOG, // this is the mutation string you just created
  ),
  builder: (
    RunMutation runMutation,
    QueryResult result,
  ) {
    return FloatingActionButton(
      onPressed: () => runMutation({
        'id': <BLOG_ID>,
      }),
      tooltip: 'Star',
      child: Icon(Icons.star),
    );
  },
);

...

Subscriptions (Experimental) #

The syntax for subscriptions is again similar to a query, however, this utilizes WebSockets and dart Streams to provide real-time updates from a server. Before subscriptions can be performed a global intance of socketClient needs to be initialized.

We are working on moving this into the same GraphQLProvider stucture as the http client. Therefore this api might change in the near future.

socketClient = await SocketClient.connect('ws://coolserver.com/graphql');

Once the socketClient has been initialized it can be used by the Subscription Widget

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Subscription(
          operationName,
          query,
          variables: variables,
          builder: ({
            bool loading,
            dynamic payload,
            dynamic error,
          }) {
            if (payload != null) {
              return Text(payload['requestSubscription']['requestData']);
            } else {
              return Text('Data not found');
            }
          }
        ),
      )
    );
  }
}

Graphql Consumer #

You can always access the client direcly from the GraphQLProvider but to make it even easier you can also use the GraphQLConsumer widget. You can also pass in a another client to the consumer

  ...

  return GraphQLConsumer(
    builder: (GraphQLClient client) {
      // do something with the client

      return Container(
        child: Text('Hello world'),
      );
    },
  );

  ...

A different client:

  ...

  return GraphQLConsumer(
    client: userClient,
    builder: (GraphQLClient client) {
      // do something with the client

      return Container(
        child: Text('Hello world'),
      );
    },
  );

  ...

Fragments #

There is support for fragments and it's basically how you use it in Apollo React. For example define your fragment as a dart String.

  ...
const UserFragment = '''
  fragment UserFragmentFull on Profile {
    address {
      city
      country
      postalCode
      street
    }
    birthdate
    email
    firstname
    id
    lastname]
  }
  ''';

  ...

Now you can use it in your Graphql Query or Mutation String like below

  ...

  const CURRENT_USER = '''
    query read{
      read {
      ...UserFragmentFull
      }
    }
    $UserFragment
  ''';

  ...

or

  ...

  const GET_BLOGS = '''
    query getBlogs{
      getBlog {
        title
        description
        tags
        
        author {
          ...UserFragmentFull
        }
    }
    $UserFragment
  ''';

  ...

Outside a Widget #

Similar to withApollo or graphql HoC that passes the client to the component in react, you can call a graphql query from any part of your code base even in a your service class or in your Scoped MOdel or Bloc class. Example

  ...

  class AuthUtil{
    static Future<String> getToken() async {
      SharedPreferences prefs = await SharedPreferences.getInstance();
      return await prefs.getString('token');
    }

    static Future setToken(value) async {
      SharedPreferences prefs = await SharedPreferences.getInstance();
      return await prefs.setString('token', value);
    }

    static removeToken() async {
      SharedPreferences prefs = await SharedPreferences.getInstance();
      return await prefs.remove('token');
    }

    static clear() async {
      SharedPreferences prefs = await SharedPreferences.getInstance();
      return await prefs.clear();
    }
    
    static Future<bool> logIn(String username, String password) async {
      var token;

      QueryOptions queryOptions = QueryOptions(
          document: LOGIN,
          variables: {
            'username': username,
            'password': password
          }
      );

      if (result != null) {
        this.setToken(result);
        return clientProfile.value.query(queryOptions).then((result) async {

          if(result.data != null) {
            token = result.data['login']['token];
            notifyListeners();
            return token;
          } else {
            return throw Error;
          }

        }).catchError((error) {
            return throw Error;
        });
      } else
        return false;
    }
  }

  ...

In a scoped model:

  ...
class AppModel extends Model {

  String token = '';
  var currentUser = new Map <String, dynamic>();

  static AppModel of(BuildContext context) =>
      ScopedModel.of<AppModel>(context);

  void setToken(String value) {
    token = value;
    AuthUtil.setAppURI(value);
    notifyListeners();
  }


  String getToken() {
    if (token != null) return token;
    else AuthUtil.getToken();
  }

  getCurrentUser() {
    return currentUser;
  }

  Future<bool> isLoggedIn() async {

    var result = await AuthUtil.getToken();
    print(result);

    QueryOptions queryOptions = QueryOptions(
        document: CURRENT_USER
    );

    if (result != null) {
      print(result);
      this.setToken(result);
      return clientProfile.value.query(queryOptions).then((result) async {

        if(result.data != null) {
          currentUser = result.data['read'];
          notifyListeners();
          return true;
        } else {
          return false;
        }

      }).catchError((error) {
        print('''Error => $error''');
        return false;
      });
    } else
      return false;
  }
}

Roadmap #

This is currently our roadmap, please feel free to request additions/changes.

FeatureProgress
Queries
Mutations
Subscriptions
Query polling
In memory cache
Offline cache sync
Optimistic results🔜
Client state management🔜
Modularity🔜
Documentation🔜

Contributing #

Feel free to open a PR with any suggestions! We'll be actively working on the library ourselves. If you need control to the repo, please contact me Rex Raphael. Please fork and send your PRs to the v.1.0.0 branch.

This project follows the all-contributors specification. Contributions of any kind are welcome!

[1.0.0-alpha.11] - October 28 2018

Breaking changes #

n/a

Fixes / Enhancements #

  • Added NormalizedInMemoryCache as a new cache option. @micimize
  • Fixed Mutation calling onCompleted for loading state. @rafaelring
  • Fix type annotations. @HofmannZ
  • Fixed http versions. @HofmannZ

Docs #

  • Added docs for the new NormalizedInMemoryCache option. @micimize
  • Added @rafaelring as a contributor. @HofmannZ

[1.0.0-alpha.10] - October 6 2018

Breaking changes #

n/a

Fixes / Enhancements #

  • Fixed Query variables not updating in the query. @micimize
  • Fixed Mutation widget's behavior to properly set loading status. @Igor1201

Docs #

  • Added @micimize as a contributor. @HofmannZ
  • Added @Igor1201 as a contributor. @HofmannZ

[1.0.0-alpha.9] - September 25 2018

Breaking changes #

n/a

Fixes / Enhancements #

  • Fixed connectivity errors not being thrown and streamed. @HofmannZ

Docs #

n/a

[1.0.0-alpha.8] - September 21 2018

Breaking changes #

n/a

Fixes / Enhancements #

  • Removed an unused class. @HofmannZ
  • Formatted the query manger. @HofmannZ
  • Handle charset encoding in responses @kolja-esders

Docs #

  • Added some inline docs to Query widget. @HofmannZ
  • Improved the inline docs of the client. @HofmannZ
  • Update the example. @HofmannZ

[1.0.0-alpha.7] - September 14 2018

Breaking changes #

n/a

Fixes / Enhancements #

  • Fixed a bug where getting the operation name was always returning null. @HofmannZ
  • Override the fetch policy if the default query option is used. @HofmannZ
  • Split up fetching and polling in the observable query. @HofmannZ
  • Check if the stream is closed, before adding a new event to it. @HofmannZ
  • Check if the variables have actually changed form or to null. @HofmannZ
  • Added a new getter to check if a query result has errors. @HofmannZ
  • Refactored the scheduler to only handle polling queries. @HofmannZ
  • Updated the mutation widget to use the new api in observable query. @HofmannZ
  • Resolve type cast exception when handling GraphQL errors. @kolja-esders @HofmannZ
  • Propagate GraphQL errors to caller instead of throwing network exception. @kolja-esders

Docs #

n/a

[1.0.0-alpha.6] - September 10 2018

Breaking changes #

n/a

Fixes / Enhancements #

  • Updated lint options in preparation for upcoming CI checks. @HofmannZ

Docs #

n/a

[1.0.0-alpha.5] - September 7 2018

Breaking changes #

n/a

Fixes / Enhancements #

  • Fixed a bug where the wrong key was selected from the context map. @HofmannZ
  • Fixed a scenario where the dispose method was calling the close method on the observableQuery class which might not have been initialised yet. @HofmannZ
  • Added the onComplete callback for the Mutation widget. @HofmannZ
  • Added the initPayload as an optional parameter for the connect method on the SocketClient class. @lordgreg

Docs #

  • Added an example of optionally overriding http options trough the context. @HofmannZ
  • Added @lordgreg as a contributor. @HofmannZ
  • Updated the example with explicit type casting. @HofmannZ
  • Updated the Mutation example with the new onComplete callback. @HofmannZ

[1.0.0-alpha.4] - September 4 2018

Breaking changes #

n/a

Fixes / Enhancements #

  • Always return something from the read method in the cache class. @HofmannZ
  • Only save to cache with certain fetch policies. @HofmannZ
  • Throw an error when no data from network with certain fetch policies. @HofmannZ
  • Added a document parser. @HofmannZ
  • Added operation name from document to the operation. @HofmannZ
  • Only create a new observable query if options have changed. @HofmannZ
  • Add context to the links. @HofmannZ
  • Parse context in the http link to update the config. @HofmannZ
  • Change the type of context from dynamic to Map<String, dynamic. @HofmannZ

Docs #

n/a

[1.0.0-alpha.3] - September 2 2018

Breaking changes #

n/a

Fixes / Enhancements #

  • Reverted changes to the required Dart version. @HofmannZ
  • Added missing return statsments. @HofmannZ

Docs #

n/a

[1.0.0-alpha.2] - September 2 2018

Breaking changes #

n/a

Fixes / Enhancements #

  • GraphQLClient now reads and writes data from the Cache based on the provided FetchPolicy option. @HofmannZ
  • Implemented caching for data from FetchResults. @HofmannZ
  • The library now tagets Dart version >=2.1.0-dev.0.0 <3.0.0 as recomended by Flutter 0.6.0. @HofmannZ
  • Removed the old client from the library. @HofmannZ

Docs #

  • Document the new API. @HofmannZ
  • Write an upgrade guide. @HofmannZ
  • Clean up the example. @HofmannZ

[1.0.0-alpha.1] - September 2 2018

Breaking changes #

  • Renamed Client to GraphQLClient to avoid name collision with other packages. @HofmannZ
  • Renamed GraphqlProvider to GraphQLProvider to align with new naming. @HofmannZ
  • Renamed GraphqlConsumer to GraphQLConsumer to align with new naming. @HofmannZ
  • Renamed GQLError to GraphQLError to align with new naming. @HofmannZ
  • GraphQLClient requires a Link to passed into the constructor. @HofmannZ
  • GraphQLClient no longer requires a endPoint or apiToken to be passed into the constructor. Instead you can provide it to the Link. @HofmannZ
  • The Query and Mutation widgets are now StreamBuilders, there the api did change slightly. @HofmannZ

Fixes / Enhancements #

  • Improved typing throughout the library. @HofmannZ
  • Queries are handled as streams of operations. @HofmannZ
  • Added the HttpLink to handle requests using http. @HofmannZ
  • HttpLink allows headers to be customised. @HofmannZ
  • The api allows contributors to write their own custom links. @HofmannZ

Docs #

  • Implement the new link system in the example. @HofmannZ

[0.9.3] - September 5 2018

Breaking changes #

n/a

Fixes / Enhancements #

  • Fix wrong typedef causing runtime type mismatch. @HofmannZ

Docs #

  • Update the reference to the next branch. @HofmannZ

[0.9.2] - 2 September 2018

Breaking changes #

n/a

Fixes / Enhancements #

  • Upgrade dependencies. @HofmannZ

Docs #

  • Added a refrence to our next major release. @HofmannZ

[0.9.1] - August 30 2018

Breaking changes #

n/a

Fixes / Enhancements #

  • Move test dependency to the dev section. @fabiocarneiro
  • Fix version resolving for test dependencies. @HofmannZ

Docs #

n/a

[0.9.0] - August 23 2018

Breaking changes #

n/a

Fixes / Enhancements #

  • Added error extensions support. @dustin-graham
  • Changed the mutation typedef to return a Future, allowing async/await. @HofmannZ
  • Fixed error handling when location is not provided. @adelcasse
  • Fixed a bug where the client might no longer be in the same context. @HofmannZ

Docs #

n/a

[0.8.0] - August 10 2018

Breaking changes #

n/a

Fixes / Enhancements #

  • Added basic error handeling for queries and mutations @mmadjer
  • Added missing export for the GraphqlConsumer widget @AleksandarFaraj

Docs #

n/a

[0.7.1] - August 3 2018

Breaking changes #

n/a

Fixes / Enhancements #

  • Code formatting @HofmannZ

Docs #

  • Updated the package description @HofmannZ

[0.7.0] - July 22 2018

Breaking changes #

n/a

Fixes / Enhancements #

  • Added support for subsciptions in the client. @cal-pratt
  • Added the Subscription widget. You can no direcly acces streams from Flutter. @cal-pratt

Docs #

  • Added instructions for adding subscripton to your poject. @cal-pratt
  • Updated the About this project section. @HofmannZ

[0.6.0] - July 19 2018

Breaking changes #

  • The library now requires your app to be wrapped with the GraphqlProvider widget. @HofmannZ
  • The global client variable is no longer available. Instead use the GraphqlConsumer widget. @HofmannZ

Fixes / Enhancements #

  • Added the GraphqlProvider widget. The client is now stored in an InheritedWidget, and can be accessed anywhere within the app. @HofmannZ
Client client = GraphqlProvider.of(context).value;
  • Added the GraphqlConsumer widget. For ease of use we added a widget that uses the same builder structure as the Query and Mutation widgets. @HofmannZ

Under the hood it access the client from the BuildContext.

  • Added the option to optionally provide the apiToken to the Client constructor. It is still possible to set the apiToken with setter method. @HofmannZ
  return new GraphqlConsumer(
    builder: (Client client) {
      // do something with the client

      return new Container();
    },
  );

Docs #

  • Added documentation for the new GraphqlProvider @HofmannZ
  • Added documentation for the new GraphqlConsumer @HofmannZ
  • Changed the setup instructions to include the new widgets @HofmannZ
  • Changed the example to include the new widgets @HofmannZ

[0.5.4] - July 17 2018

Breaking changes #

n/a

Fixes / Enhancements #

  • Query: changed Timer to Timer.periodic @eusdima
  • Minor logic tweak @eusdima
  • Use absolute paths in the library @HofmannZ

Docs #

  • Fix mutations example bug not updating star bool @cal-pratt

[0.5.3] - July 13 2018

Breaking changes #

n/a

Fixes / Enhancements #

  • Added polling timer as a variable for easy deletion on dispose
  • Fixed bug when Query timer is still active when the Query is disposed
  • Added instant query fetch when the query variables are updated

Docs #

n/a

[0.5.2] - July 11 2018

Breaking changes #

n/a

Fixes / Enhancements #

  • Fixed error when cache file is non-existent

Docs #

n/a

[0.5.1] - June 29 2018

Breaking changes #

n/a

Fixes / Enhancements #

  • Fixed json error parsing.

Docs #

n/a

[0.5.0] - June 25 2018

Breaking changes #

n/a

Fixes / Enhancements #

  • Introduced onCompleted callback for mutiations.
  • Excluded some config files from version control.

Docs #

  • Fixed typos in the readme.md.
  • The examples inculde an example of the onCompleted callback.

[0.4.1] - June 22 2018

Breaking changes #

n/a

Fixes / Enhancements #

n/a

Docs #

  • The examples now porperly reflect the changes to the library.

[0.4.0] - June 21 2018

Breaking changes #

  • The Client now requires a from of cache.
  • The name of the execute method on the Client class changed to query.

Fixes / Enhancements #

  • Implemented in-memory cache.
  • Write memory to file when in background.
  • Added provider widget to save and restore the in-memory cache.
  • Restructure the project.

Docs #

  • Update the README.md to refelct changes in the code.
  • update the example to refelct changes in the code.

[0.3.0] - June 16 2018

Breaking changes #

  • Changed data type to Map instaid of Object to be more explicit.

Fixes / Enhancements #

  • Cosmatic changes.

Docs #

  • Added a Flutter app example.
  • Fixed the example in README.md.
  • Added more badges.

[0.2.0] - June 15 2018

Breaking changes #

  • Changed query widget polling argument to pollInterval, following the react-apollo api.

Fixes / Enhancements #

  • Query polling is now optional.

Docs #

  • Updated the docs with the changes in api.

[0.1.0] - June 15 2018

My colleague and I created a simple implementation of a GraphQL Client for Flutter. (Many thanks to Eus Dima, for his work on the initial client.)

Breaking changes #

n/a

Fixes / Enhancements #

  • A client to connect to your GraphQL server.
  • A query widget to handle GraphQL queries.
  • A mutation widget to handle GraphQL mutations.
  • Simple support for query polling.

Docs #

  • Initial documentation.

example/README.md

app #

A new Flutter project.

Getting Started #

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  flutter_graphql: ^1.0.0-rc.3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:flutter_graphql/flutter_graphql.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
62
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
65
Overall:
Weighted score of the above. [more]
44
Learn more about scoring.

We analyzed this package on Oct 11, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms:

Error(s) prevent platform classification:

Make sure flutter format successfully runs on your package's source files.

Analysis issues and suggestions

Make sure flutter format successfully runs on your package's source files.

Running flutter format failed with the following output:

Exception: dartfmt on lib/ failed with exit code 65
Could not format because the source could not be parsed:

line 11, column 3 of lib/src/widgets/subscription.dart: Function-typed parameters can't specify 'const', 'final' or 'var' in place of a return type.
   ╷
11 │   final bool loading,
   │   ^^^^^
   ╵
line 12, column 3 of lib/src/widgets/subscription.dart: Function-typed parameters can't specify 'const', 'final' or 'var' in place of a return type.
   ╷

Health issues and suggestions

Fix lib/src/widgets/subscription.dart. (-57.81 points)

Analysis of lib/src/widgets/subscription.dart failed with 3 errors:

line 11 col 3: Function-typed parameters can't specify 'const', 'final' or 'var' in place of a return type.

line 12 col 3: Function-typed parameters can't specify 'const', 'final' or 'var' in place of a return type.

line 13 col 3: Function-typed parameters can't specify 'const', 'final' or 'var' in place of a return type.

Fix lib/src/cache/normalized/sql/sql-normalized-cache.dart. (-2.48 points)

Analysis of lib/src/cache/normalized/sql/sql-normalized-cache.dart reported 5 hints:

line 27 col 28: The value of the field '_inMemoryCache' isn't used.

line 35 col 3: The class 'Future' wasn't exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

line 35 col 42: The declaration '_readFromStorage' isn't referenced.

line 61 col 3: The class 'Future' wasn't exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

line 63 col 11: The value of the local variable 'deletedObj' isn't used.

Fix lib/src/cache/cache.dart. (-1 points)

Analysis of lib/src/cache/cache.dart reported 2 hints:

line 2 col 3: This function has a return type of 'Future

line 2 col 3: The class 'Future' wasn't exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

Fix lib/src/cache/normalized/sql/sql_helper.dart. (-1 points)

Analysis of lib/src/cache/normalized/sql/sql_helper.dart reported 2 hints:

line 20 col 3: The class 'Future' wasn't exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

line 29 col 3: The class 'Future' wasn't exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.

Fix lib/src/cache/normalized/record_field_json_adapter.dart. (-0.50 points)

Analysis of lib/src/cache/normalized/record_field_json_adapter.dart reported 1 hint:

line 10 col 28: Use ; instead of {} for empty constructor bodies.

Maintenance issues and suggestions

Fix platform conflicts. (-20 points)

Error(s) prevent platform classification:

Make sure flutter format successfully runs on your package's source files.

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (path_provider).

Package is pre-release. (-5 points)

Pre-release versions should be used with caution; their API can change in breaking ways.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
flutter 0.0.0
graphql_parser ^1.1.1 1.1.4
http ^0.12.0 0.12.0+2
http_parser ^3.1.3 3.1.3
meta ^1.1.6 1.1.7
path_provider ^0.4.1 0.4.1 1.3.0
sqflite ^1.1.0 1.1.7+1
uuid ^2.0.0 2.0.2
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.11 1.14.12
convert 2.1.1
crypto 2.1.3
path 1.6.4
pedantic 1.8.0+1
sky_engine 0.0.99
source_span 1.5.5
string_scanner 1.0.5
synchronized 2.1.0+1
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
test ^1.3.0