Book Image

DART Cookbook

By : Ivo Balbaert
Book Image

DART Cookbook

By: Ivo Balbaert

Overview of this book

Table of Contents (18 chapters)
Dart Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Solving problems when pub get fails


The pub package manager is a complex tool with many functionalities, so it is not surprising that occasionally something goes wrong. The pub get command downloads all the libraries needed by your app, as specified in the pubspec.yaml file. Running pub get behind a proxy or firewall used to be a problem, but it was solved in the majority of cases. If this still haunts you, look at the corresponding section at https://www.dartlang.org/tools/editor/troubleshoot.html.

Getting ready

This recipe is especially useful when you encounter the following error in your Dart console while trying to open a project in Dart Editor during the pub get phase:

Pub install fails with 'Deletion failed'

How to do it...

First try this; right-click on your project and select Close Folder. Then, restart the editor and open your project again. In many cases, your project will load fine. If this does not work, try the pub gun command:

  1. Delete the pub cache folder from C:\Users\{your username}\AppData\Roaming\Pub.

  2. Delete all the packages folders in your project (also in subfolders).

  3. Delete the pubspec.lock file in your project.

  4. Run pub get again from a command line or select Tools in the Dart Editor menu, and then select Pub Get.

How it works...

The Pub\Cache subfolder contains all the packages that have been downloaded in your Dart environment. Your project contains symlinks to the projects in this cache, which sometimes go wrong, mostly on Windows. The pubspeck.lock file keeps the downloaded projects constrained to certain versions; removing this constraint can also be helpful.

There's more...

Temporarily disabling the virus checker on your system can also help pub get to succeed when it fails with the virus checker on.

The following script by Richard Schmidt that downloads packages from the pub repository and unpacks it into your Dart cache may also prove to be helpful for this error, which can be found at https://github.com/hangstrap/downloadFromPub. Use it as dart downloadFromPub.dart package m.n.l.

Here, package is the package you want to install and m.n.l is the version number such as 0.8.1. You will need to build this like any other dart package, and if during this process the pub get command fails, you will have to download the package and unpack it manually; however, from then on, you should be able to use this script to work around this issue.

When pub get fails in Dart Editor, try the following on the command line to get more information on the possible reasons for the pub --trace 'upgrade' failure.

There is now also a way to condense these four steps into one command in a terminal as follows:

pub cache repair