Date
Oct. 26th, 2024
 
2024年 9月 24日

Post: Dart Primer 001 : Hello, world!

Dart Primer 001 : Hello, world!

Published 12:05 May 17, 2018.

Created by @ezra. Categorized in #Programming, and tagged as #Dart.

Source format: Markdown

Table of Content

今天开始一起来学习一下 Dart 语言。

安装

首先第一步来 安装 Dart, 以 macOS 为例:

homebrew

先来安装 homebrew, 然后执行:

$ brew tap dart-lang/dart
$ brew install dart

如果你要安装开发者版本, 使用 --devel 选项:

$ brew install dart --devel

如果你已经安装过了, 可以通过这个指令来更新新版本:

$ brew upgrade dart

IDE

早期官方推荐的 Dart Editor 已经弃用, 现在你可以使用 WebStormAtom, 当然, 你需要安装 Dart 相关插件。

Hello, word!

现在, 我们来编写第一个程序吧。

main.dart 中写入以下代码:

void main() {
  print("Hello, world!");
}

需要指出的是, Dart 有两种运行模式:

  • 检查模式 (checked): 进行类型检查,如果发现实际类型与声明或期望的类型不匹配就报错
  • 生产模式 (production): 不进行类型检查,忽略声明的类型信息,忽略 assert 语句

如果你是用 WebStorm, 可以在 Run => Edit Configurations 中对运行模式进行修改。

Pinned Message
HOTODOGO
The Founder and CEO of Infeca Technology.
Developer, Designer, Blogger.
Big fan of Apple, Love of colour.
Feel free to contact me.
反曲点科技创始人和首席执行官。
开发、设计与写作皆为所长。
热爱苹果、钟情色彩。
随时恭候 垂询