Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
DART Cookbook

You're reading from   DART Cookbook Over 110 incredibly effective, useful, and hands-on recipes to design Dart web client and server applications

Arrow left icon
Product type Paperback
Published in Oct 2014
Publisher Packt
ISBN-13 9781783989621
Length 346 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Ivo Balbaert Ivo Balbaert
Author Profile Icon Ivo Balbaert
Ivo Balbaert
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Working with Dart Tools FREE CHAPTER 2. Structuring, Testing, and Deploying an Application 3. Working with Data Types 4. Object Orientation 5. Handling Web Applications 6. Working with Files and Streams 7. Working with Web Servers 8. Working with Futures, Tasks, and Isolates 9. Working with Databases 10. Polymer Dart Recipes 11. Working with Angular Dart Index

Using the command-line tools

Some things can be done more easily on the command-line, or are simply not (yet) included in Dart Editor. These tools are found in dart-sdk/bin. They consist of the following:

  • dart: The standalone Dart VM to run Dart command-line apps, such as server-side scripts and server apps
  • dartanalyzer: This is used to check code statically
  • pub: This is the package and repository manager
  • dartfmt: This is the code formatting tool
  • docgen: This is the documentation generator tool

How to do it...

  1. For every tool, it might be useful to know or check its version. This is done with the -- version option such as dart --version with a typical output of Dart VM version: 1.3.0 (Tue Apr 08 09:06:23 2014) on "windows_ia32".
  2. The dart –v –h option lists and discusses all the possible options of the VM. Many tools also take the --package_root=<path> or –p=<path> option to indicate where the packages used in the imports reside on the filesystem.
  3. dartanalyzer is written in Java and works in Dart Editor whenever a project is imported or Dart code is changed; it is started dartanalyzer prorabbits.dart with output:

    Analyzing prorabbits.dart...

    No issues found (or possibly errors and hints to improve the code)

  4. The previous output verifies that the code conforms to the language specification https://www.dartlang.org/docs/spec/, pub functionality is built into Dart Editor, but the tool can also be used from the command line (refer to test_pub). To fetch packages (for example, for the test_pub app), use the following command in the folder where pubspec.yaml lives, pub get, with a typical output as follows:
    Resolving dependencies... (6.6s)
    Got dependencies!
  5. A packages folder is created with symlinks to the central package cache on your machine. The latest versions are downloaded and the package versions are registered in the pubspec.lock file, so that your app can only use these versions.
  6. If you want to get a newer version of a package, use the pub upgrade command. You can use the –v and -- trace options to produce a detailed output to verify its workings.

    Tip

    Always do a pub upgrade if the project you start working on already contains versions of packages!

  7. The dartfmt tool is also a built in Dart Editor. Right-click on any Dart file and choose Format from the context menu. This applies transformations to the code so that it conforms to the Dart Style Guide, which can be seen at https://www.dartlang.org/articles/style-guide/.You can also use it from the command line, but then the default operation mode is cleaning up whitespace. Use the –t option to apply code transforms such as dartfmt -t –w bank_terminal.dart.

See also

  • Solving problems when pub get fails
  • Compiling your app to JavaScript (for pub build)
  • Documenting your code from Chapter 2, Structuring, testing, and deploying an application
  • Publishing your app to a pub (for pub publishing)
  • Using snapshotting to start an app in Dart VM
  • For additional information, refer to https://www.dartlang.org/tools/
You have been reading a chapter from
DART Cookbook
Published in: Oct 2014
Publisher: Packt
ISBN-13: 9781783989621
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image