dart.webp

一、下载与安装

到如下地址下载最新版的Dart SDK安装即可:

image.png

如果是使用 zip 包解压的,需要手动将安装路径下的 bin 添加到环境变量。

二、第一个Dart程序

安装好Dart SDK后, 编写一个 test.dart 文件, 输入:

  1. main() {
  2. print("Hello, World!");
  3. }

执行 dart test.dart, 控制台输入 Hello, World!

三、命令行工具

dart

  1. $ dart
  2. A command-line utility for Dart development.
  3. Usage: dart [<vm-flags>] <command|dart-file> [<arguments>]
  4. Global options:
  5. -h, --help Print this usage information.
  6. -v, --verbose Show additional command output.
  7. --version Print the Dart SDK version.
  8. --enable-analytics Enable anonymous analytics.
  9. --disable-analytics Disable anonymous analytics.
  10. Available commands:
  11. analyze Analyze the project's Dart code.
  12. compile Compile Dart to various formats.
  13. create Create a new project.
  14. format Idiomatically format Dart source code.
  15. pub Work with packages.
  16. run Run a Dart program.
  17. test Run tests in this package.
  18. Run "dart help <command>" for more information about a command.
  19. See https://dart.dev/tools/dart-tool for detailed documentation.

pub

pub 是 Dart 的包管理工具。

  1. $ pub
  2. Pub is a package manager for Dart.
  3. Usage: pub <command> [arguments]
  4. Global options:
  5. -h, --help Print this usage information.
  6. --version Print pub version.
  7. --[no-]trace Print debugging information when an error occurs. --verbosity Control output verbosity.
  8. [all] Show all output including internal tracing
  9. messages.
  10. [error] Show only errors.
  11. [io] Also show IO operations.
  12. [normal] Show errors, warnings, and user messages.
  13. [solver] Show steps during version resolution.
  14. [warning] Show only errors and warnings.
  15. -v, --verbose Shortcut for "--verbosity=all".
  16. Available commands:
  17. cache Work with the system cache.
  18. deps Print package dependencies.
  19. downgrade Downgrade the current package's dependencies to oldest
  20. versions.
  21. get Get the current package's dependencies.
  22. global Work with global packages.
  23. logout Log out of pub.dartlang.org.
  24. outdated Analyze your dependencies to find which ones can be
  25. upgraded.
  26. publish Publish the current package to pub.dartlang.org.
  27. run Run an executable from a package.
  28. upgrade Upgrade the current package's dependencies to latest
  29. versions.
  30. uploader Manage uploaders for a package on pub.dartlang.org.
  31. version Print pub version.
  32. Run "pub help <command>" for more information about a command.
  33. See https://dart.dev/tools/pub/cmd for detailed documentation.

安装:

  1. pub global activate webdev
  2. pub global activate stagehand

Windows 注意将 ~\AppData\Roaming\Pub\Cache\bin~\AppData\Local\Pub\Cache\bin 添加到环境变量,以便使用pub安装的全局应用。

参考资料