How to add github hosted package as dependency in pubspec.yml? (Flutter)

Harsh Vardhan Gautam
2 min readFeb 18, 2023

--

If you’re here reading the article, it’s likely that you have some flutter package hosted on github or any other service. And you want to refer to this package inside your pubspec.yml file of your flutter application.
In that case, I must mention that you’re at the right place. Continue reading the article, you’ll surely get to know what you’re looking for.

Without further ado, let’s get started.

Let’s say that we have a flutter package named test_package hosted on github.com. We have one flutter application in which we want to use the test_package.

Now, generally, we publish the package on pub.dev and use it normally as any other package we use. But, for our particular case, the test_package is what we want to keep private or basically unpublished on pub.dev, so in this case we can refer to our hosted package like below:

In your pubspec.yml file, add test_package as dependency like this:

test_package:
git:
url: https://github.com/<route-to-your-package>/test_package.git
ref: main

Let me explain the above code snippet. So, we mentioned the package name i.e. test_package and we’ll mention it’s hosted URL and the branch name from which we want to refer the package.

But as the package is hosted as .git (on github.com for say), we’ll add url tag and ref (branch name) tag under git tag.

That’s it.

Thank you for taking out some time to learn something new. I hope that the article has added some value to your time spent. I like feedbacks, please let me know your comments in the comment section.

Reference: Using packages | Flutter

Thank You!

--

--