Dart 环境搭建
- 从Flutter 1.21开始,Flutter SDK 会同时包含完整的Dart SDK
- Dart绑定环境变量
- export PATH=
f
l
u
t
t
e
r
/
b
i
n
:
{flutter}/bin:
flutter/bin:PATH
- export PATH=
f
l
u
t
t
e
r
/
b
i
n
/
c
a
c
h
e
/
d
a
r
t
−
s
d
k
/
b
i
n
:
{flutter}/bin/cache/dart-sdk/bin:
flutter/bin/cache/dart−sdk/bin:PATH
- export PATH=
f
l
u
t
t
e
r
/
.
p
u
b
−
c
a
c
h
e
/
b
i
n
:
{flutter}/.pub-cache/bin:
flutter/.pub−cache/bin:PATH
Dart 资源网站
- 官网
- https://dart.dev/
- https://dart.cn/
- 在线运行代码
- https://dartpad.dartlang.org/
- https://dartpad.cn/
- 生态(类似npm)
Dart 语法基础
void printInteger(int aNumber) {
print('abc $aNumber');
}
void main() {
var number = 12;
printInteger(number);
}
变量
- 变量是一个引用,Dart万物皆对象,变量存储的是对象的引用,大小写敏感
- 变量的默认值是 null
- Dart类型不会进行隐式转换 (null 不会自动转换为false)
int age = 18;
var abc = 18; 或者 dynamic age = 18;
常量
const age = 18;
final age = 18;
const time = Date.getTime.new();
const final = Date.getTime.new();