Minimal package for fetching GitHub user info and paginated list of repositories
Minimal package for fetching GitHub user info and paginated list of repositories. The project is similar to my NPM library
github-repo-fetch, with the exception that, obviously, it's written in Dart, and that it supports pagination, as well as filterning of private and public repositories.
Depend on the package
dependencies: flutter_gh_fetch: ^0.0.3
and then import it inside your Dart code
This library uses GitHub GraphQL API in order to fetch data related to the user and their repositories. The authentication is conducted through the use of Personal Access Token, which you need to generate.
First, you need to create an instance of
FlutterGHFetch class and call
final FlutterGhFetch ghFetch = FlutterGHFetch('token'); await ghFetch.init();
To fetch user details, call
Map<String, dynamic> userData = await ghFetch.queryUserData();
For fetching repositories, you have three options: you can simply query first
final reposData = await ghFetch.queryRepositoryData(n);
or use a cursor to achieve pagination, so first
n repositories after
final reposData = await ghFetch.queryRepositoryData(n, after: cursor);
Lastly, you can filter out private repositories (so you only display public ones) by setting
filterPrivate optional argument to
final reposData = await ghFetch.queryRepositoryData(n, filterPrivate: true);
In order to fetch the total repository count for the user (both public and private repositories, you can call
final totalCount = await ghFetch.queryTotalRepoCount();
Development and License #
The library is not gonna get any additional development after the last version, but feel free to fork the project and work on it. Upon cloning it, install necessary dependencies with
flutter pub get.
test directory holds a single test file which tests all public methods of the
FlutterGHFetch class. You will need to hardcore your Personal Access Token, and cursor string.
This project is licensed under the MIT license.