How to add a package from command line?


npm (and so yarn) has a greate feature that you can add needed packages just by knowing the package name (like yarn add xxx_yyy) and it adds the latest stable release to your project. Does flutter have any equivalent hero? Or we have to search our needed package on and find version to add to our pubspec.yaml?


Update 2

Based on @CopsOnRoad answer, now dart has add command which is the best way for adding packages from cmd. Full documentation is here.


Right now you can have exactly similar experience like npm or yarn in flutter with the help of get_cli package. One of the tools it provides will let you just write the package name and it automatically installs the latest version with mentioning the version number inside the yaml file.

From its documentation

// To install a package in your project (dependencies):
get install camera

// To install several packages from your project:
get install http path camera 

// To install a package with specific version:
get install path:1.6.4

// You can also specify several packages with version numbers

// To install a dev package in your project (dependencies_dev): 
get install flutter_launcher_icons --dev

Old answer

About the cli verb add, there is no any equivalent in flutter and pub yet. But about the versioning and adding packages just with their names, try to add them in pubspec.yaml file without version number. Just like this:

  http: ^0.12.0+2
  dio: ^2.1.13

Answered By – Hamed Hamedi

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published