— Flutter, GitHub, Dependencies — 1 min read
Flutter devs often need to include packages that are hosted on GitHub(I've had to personally do this a couple of times), especially when using the latest source code of a package that hasn't been published yet. This guide explains how to add a GitHub package to your Flutter project.
To include a package from a public GitHub repository, specify the package in your pubspec.yaml
under dependencies.
1dependencies:2 some_package:3 git:4 url: https://github.com/username/some_package.git
You can target a specific branch using the ref
property.
1dependencies:2 some_package:3 git:4 url: https://github.com/username/some_package.git5 ref: branch-name
To pin the package to a specific commit, use the commit's SHA hash in the ref
property.
1dependencies:2 some_package:3 git:4 url: https://github.com/username/some_package.git5 ref: commit-hash
For packages that are developed locally or are not yet pushed to a remote repository, you can reference them by their local paths.
1dependencies:2 local_package:3 path: ../path/to/local_package
After adding the package to pubspec.yaml
, run flutter pub get
in your terminal to fetch the package. Then, you can import and use the package in your Dart files.
1import 'package:some_package/some_package.dart';
pubspec.yaml
matches the package name defined in the package's own pubspec.yaml
.