How to Add a Package From GitHub In Flutter?
Earlier we have been through various articles based on flutter How to Print Firestore Timestamp as Formatted Date and Time In Flutter So in this article we will go through how to Add a Package From GitHub In Flutter?
As you develop Flutter applications, you’ll often find the need to incorporate external packages to enhance functionality, save development time, or leverage existing solutions. While many packages are available on pub.dev, the official package repository for Flutter, there may be cases where you need to add a package directly from GitHub. Adding packages from GitHub allows you to access the latest features, bug fixes, or custom modifications from the package’s repository. In this blog post, we will walk you through a step-by-step guide on how to add a package from GitHub to your Flutter project.
How to Add a Package From GitHub In Flutter?
Example of pubspec.yaml
dependencies: flutter: sdk: flutter carousel_pro: git: url: git://github.com/jlouage/flutter-carousel-pro.git ref: master
Example of a file importing the package
import 'package:carousel_pro/src/carousel_pro_widgets.dart'; import 'package:flutter/material.dart'; class NewsCarousel extends StatelessWidget { @override Widget build(BuildContext context) { return SizedBox( height: 200.0, child: WidgetCarousel( autoplay: false, pages: [], ), ); } }
To make that easier, you can depend directly on a package stored in a Git repository.
dependencies: kittens: git: https://github.com/munificent/kittens.git
The git here says this package is found using Git, and the URL after that is the Git URL that can be used to clone the package.
Even if the package repo is private, if you can connect to the repo using SSH, then you can depend on the package by using the repo’s SSH URL:
dependencies: kittens: git: [email protected]:munificent/kittens.git
If you want to depend on a specific commit, branch, or tag, add a ref argument:
ependencies: kittens: git: url: [email protected]:munificent/kittens.git ref: some-branch
The ref can be anything that Git allows to identify a commit.
Git dependency on a package in a folder
The pub tool assumes the package is located at the root of the Git repository. If that is not the case, specify the location with the path argument.
To specify a different location in the repo, use the path argument: For example:
dependencies: package1: git: url: git://github.com/flutter/packages.git path: packages/package1
The path is relative to the Git repo’s root. For more details, see Package dependencies.
Conclusion:
Hope you enjoyed this article !!!
In this article, we have been through how to add a Package From GitHub in flutter ??
Do not forget to drop your valuable suggestions/feedback. We would love to assist you.
FlutterAgency.com is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget Guide, Flutter Projects, Code libs and etc.