You are currently viewing How To Install A Flutter Package From GitHub Repository?

How To Install A Flutter Package From GitHub Repository?

Introduction

Installing a Flutter package from GitHub repository is a simple process and quite easy to understand too. In today’s post, I aim to help you do just that. By the end of this post, you’ll learn how you can install a Flutter package / library directly from the Git URL.

Installing The Package

Selecting The Package

We will be using a favorite package of mine called tabbed_view from pub.dev but you can use any other package that has its associated GitHub repository linked on the pub.dev page.

Install Flutter Package From GitHub Repository

  • Navigate to the GitHub repository home page of the package. In our case it is tabbed_view.
  • Now click the green “Code” dropdown button and copy then paste this URL in an accessible file
flutter package from github repo's url
  • For ease of access, I’ll link the URL here.
https://github.com/caduandrade/tabbed_view.git
  • Now go to your Flutter project’s pubspec.yaml file and under dependencies: add the following
dependencies:
  flutter:
    sdk: flutter
  tabbed_view:
    git:
      url: https://github.com/caduandrade/tabbed_view.git

The snippet above loads the tabbed_view package directly from the GitHub repository it is being hosted on all we do is provide the git and url parameters.

  • Now save your pubspec.yaml file and wait for confirmation.
flutter package from github repo's installation confirmation
  • There we have it, this is the confirmation that our package was successfully installed.

Install Flutter Package From A Specific Branch in GitHub Repository

Adding on to the previous pubspec.yaml example, just add the ref keyword with branch name by default the main branch is installed but ref overrides that behavior and installs the package from the provided argument

  tabbed_view:
    git:
      url: https://github.com/caduandrade/tabbed_view.git
      ref: main
  • Now again save your pubspec.yaml file and wait for confirmation.
  • Once again the result is the same as we can see our package was installed successfully.

Conclusion

We learned how to install a Flutter package directly from GitHub repository rather than pubspec.dev. You can utilize this to implement your libraries / packages in your other projects without having to publish them to pubspec.dev or importing your own code locally. If you liked this post consider visiting the Flutter archives for more.