github_colour 1.2.1 copy "github_colour: ^1.2.1" to clipboard
github_colour: ^1.2.1 copied to clipboard

outdated

Receive ozh's GitHub colour to Flutter's colour implementation with caching and fallback.

Apply GitHub's languages colours into Flutter's Color object. #

Pub Version GitHub Sponsors

Receiving ozh's github-colors repository with latest commit of colors.json to Flutter's Color object.

It also provide web demo for the demo.

Usage #

You can either initalized GitHubColour before runApp(Widget) (Call it after WidgetsFlutterBinding.ensureInitialized() if want to get data from offline):

// With offline last resort
void main() async {
    WidgetsFlutterBinding.ensureInitialized();
    await GitHubColour.getInstance();
    runApp(const YourApp());
}

// Without offline last resort
void main() async {
    await GitHubColour.getInstance(offlineLastResort: false);
    runApp(const YourApp());
}

then uses getExistedInstance() inside the Widget:

class YourAppWidget extends StatelessWidget {
    @override
    Widget build(BuildContext context) => Scaffold(
        appBar: AppBar(
            backgroundColor: GitHubColour.getExistedInstance().find("Go")
        )
    );
}

or wrapped into FutureBuilder with initalized Future<GitHubColour> variable from State's initState (not recommended uses getInstance() directly in FutureBuilder):

class _YourAnotherAppWidgetState extends State<YourAnotherAppWidget> {
    late final Future<GitHubColour> _ghc;

    @override
    void initState() {
        super.initState();
        _ghc = GitHubColour.getInstance();
    }

    @override
    Widget build(BuildContext context) => FutureBuilder<GitHubColour>(
        future: _ghc,
        builder: (context, snapshot) {
            // Implement whatever you want
        }
    );
}

Cache for connection failed #

This package supported caching system as a backup when making request failed. It uses LZMA compress data and store as a file under temporary directory (for VM) or store as shared_preference (for Web, which is LocalStorage).

If no cache available, by default, GitHubColour.getInstance() will uses local's colors.json as last resort. However, this package will not synchronized when newer commit of color.json pushed since it minified that ensure the package can be downloaded as fast as possible.

Note for American English developers #

It's provide alias class GitHubColor for who uses "color" mostly.

Screenshots #

C++ Dart

Go Java

Python

License #

BSD-3

1
likes
0
pub points
11%
popularity

Publisher

verified publisherrk0cc.xyz

Receive ozh's GitHub colour to Flutter's colour implementation with caching and fallback.

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, hex, http, lzma, meta, path, path_provider, sha3, shared_preferences

More

Packages that depend on github_colour