Hi Guys, Welcome to Proto Coders Point. In this Article we will learn how to add github package to flutter project.
Sometimes we need to use latest flutter packages that is not yet been published in pub.dev but available in github repo.
or
In you have built your own flutter package & pushed it on github repository but not published in pub.dev, at that time you can add packages from github to flutter project directly.
How to Download Packages from Github to flutter
Open pubspec.yaml file and under dependencies section add the path to your get repository.
1. Method One
dependencies: package_name: git: <--- url --->
2. Method two – git from target branch
package_name: git: url: <--url--> ref: dev
Here package_name descrives the name of the package,
git
, it say pubspec.yaml to search for the package from github repo & url
after that is to specify from where to clone the package.
Here package name, should be same as the name specified in pubspec.yaml of that github flutter package.
how to add package from github in flutter pubspec.yaml – Example
dependencies: http: git: url: https://github.com/dart-lang/http.git
The above, will download the package directly from github repo into your flutter project.
now you can import it and use anywhere in your flutter project eg: main.dart
import 'package:http/http.dart' as http;