- Dart Cookbook
- Ivo Balbaert
- 482字
- 2021-08-05 17:42:45
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 appsdartanalyzer
: This is used to check code staticallypub
: This is the package and repository managerdartfmt
: This is the code formatting tooldocgen
: This is the documentation generator tool
How to do it...
- For every tool, it might be useful to know or check its version. This is done with the
-- version
option such asdart --version
with a typical output of Dart VM version: 1.3.0 (Tue Apr 08 09:06:23 2014) on "windows_ia32". - 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. - 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)
- 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 thetest_pub
app), use the following command in the folder wherepubspec.yaml
lives,pub get
, with a typical output as follows:Resolving dependencies... (6.6s) Got dependencies!
- 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 thepubspec.lock
file, so that your app can only use these versions. - 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!
- 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 then the default operation mode is cleaning up whitespace. Use the–t
option to apply code transforms such asdartfmt -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/
推薦閱讀
- 網(wǎng)絡(luò)云百問百答
- Application Development with Qt Creator(Second Edition)
- MERN Quick Start Guide
- 網(wǎng)管員典藏書架:網(wǎng)絡(luò)管理與運維實戰(zhàn)寶典
- 電子政務(wù)效益的經(jīng)濟分析與評價
- 萬物互聯(lián):蜂窩物聯(lián)網(wǎng)組網(wǎng)技術(shù)詳解
- 物聯(lián)網(wǎng)關(guān)鍵技術(shù)及應(yīng)用
- JBoss EAP6 High Availability
- Drush User’s Guide
- PLC、現(xiàn)場總線及工業(yè)網(wǎng)絡(luò)實用技術(shù)速成
- 互聯(lián)網(wǎng)安全的40個智慧洞見:2015年中國互聯(lián)網(wǎng)安全大會文集
- 射頻通信系統(tǒng)
- Practical Web Design
- 網(wǎng)絡(luò)基礎(chǔ)與網(wǎng)絡(luò)管理項目化教程
- 面向5G-Advanced的關(guān)鍵技術(shù)