Where does `pub get` download pubspec dependencies to?

Viewed 9714

In javascript, we have NPM and the node_modules folder in every project. I was not able to find a similar concept for Dart/ Flutter, except the build folder in my app, which contains a folder of a few dependencies I have in pubspec.yaml. It doesn't have any of the source code though, and I think it's actually built from something else. I've also looked in /usr/local/flutter/packages which is where my flutter is installed, but it only shows flutter_driver, flutter_goldens, and more seemingly unrelated folders.

I guess if wanted to read the source code, I really need to find the repo and read from that, or is there a location for dependencies I haven't looked?


I even found projectDir/.dart_tool/pub, which didn't have any of my packages.

6 Answers

From the documentation:

Dependencies downloaded over the internet, such as those from Git and the pub.dev site, are stored in a system-wide cache. This means that if multiple packages use the same version of the same dependency, it only needs to be downloaded and stored locally once.

By default, the system package cache is located in the .pub-cache subdirectory of your home directory (on Mac and Linux), or in %APPDATA%\Pub\Cache (on Windows; the location might vary depending on the Windows version). You can configure the location of the cache by setting the PUB_CACHE environment variable before running pub.

So for Mac and Linux for example, this would be ~/.pub-cache/hosted/pub.dartlang.org by default.

In Android Studio

I could directly view the source code of the package under `

[External Libraries/Dart Packages/Your Packages]

enter image description here `

You can get pubspec downloaded from your flutter sdk location .

/flutter/.pub-cache/hosted/pub.dartlang.org/

You can also clone package git .

If you have installed flutter using snap then the location might be

/home/user/snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org

I had forgotten that I've been command + clicking into these libraries all the time in VSCode.

However, it looks like packages are not stored in the app folder. Packages that we use in our projects are downloaded to $FLUTTER_PATH/.pub-cache, so if I'm looking for camera picker plugin, its in

/usr/local/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.6.5+2/lib/image_picker.dart

If you are running Windows as your OS, you can find the packages under the folder that you installed your Flutter SDK to when setting up Android Studio.

In my case - using Windows 10 - the path is as follows, where C:\ is my primary harddrive and flutter\ the folder containing the Flutter SDK...

C:\flutter\.pub-cache\hosted\pub.dartlang.org\english_words-4.0.0

The above path for instance points to the "english words package", containing the most ~5000 used English words and some utility functions, which are mentioned and used in the Flutter tutorial on their official page for writing and running your first Flutter app.

https://pub.dev/packages/english_words

Related