博客
关于我
dart学习 之旅
阅读量:261 次
发布时间:2019-03-01

本文共 1108 字,大约阅读时间需要 3 分钟。

Dart语言入门指南

1. 基本语法

void printInteger(int aNumber) {  print('The number is $aNumber.');}
void main() {  var number = 42;  printInteger(number);}

2. 变量声明

int? lineCount;
void main() {  late String description = 'Feijoada!';  print(description);}

3. 最终和常量

  • 实例变量只能是 final
  • 常用内置数据类型包括:intdoubleStringboolList(数组)、SetMapRunes(UTF-32字符集)。
runesDemo() {  Runes runes = new Runes('\u2665, \u{1f605}, \u{1f60e}');  print(runes);  print(new String.fromCharCodes(runes));}

4. 列表和集合

var list = [1, 2, 3];

5. 函数

enableFlags(paramName: value, hidden: false);
void printElement(int element) {  print(element);}
var list = [1, 2, 3];list.forEach(printElement);

6. 条件表达式

condition ? expr1 : expr2
expr1 ?? expr2

7. 类定义

class Point {  double x = 0;  double y = 0;  Point(this.x, this.y);}

8. 类继承

9. 混合使用

class MyMixin {  void method() {}}
class MyClass extends Object with MyMixin {}

10. 运算符

var paint = Paint()  ..color = Colors.black  ..strokeCap = StrokeCap.round  ..strokeWidth = 5.0;

11. 异步操作

Future
future = someAsyncFunction();
void someAsyncFunction() async {  // 异步操作逻辑}

通过以上内容,可以快速入门 Dart语言的基础知识和实践应用。

转载地址:http://wakx.baihongyu.com/

你可能感兴趣的文章
POJ 1177 Picture(线段树:扫描线求轮廓周长)
查看>>
Qualitor checkAcesso.php 任意文件上传漏洞复现(CVE-2024-44849)
查看>>
POJ 1182 食物链(并查集拆点)
查看>>
POJ 1185 炮兵阵地 (状态压缩DP)
查看>>
POJ 1195 Mobile phones
查看>>
POJ 1228 Grandpa's Estate (稳定凸包)
查看>>
poj 1236(强连通分量分解模板题)
查看>>
poj 1258 Agri-Net
查看>>
quagga 和 zebos
查看>>
poj 1286 Necklace of Beads
查看>>
POJ 1321 棋盘问题
查看>>
poj 1321(回溯)
查看>>
Qt高级——Qt元对象系统源码解析
查看>>
qt调用vs2008编写的dll动态库(隐式调用)
查看>>
Qt读取注册表默认值
查看>>
poj 1679 判断MST是不是唯一的 (次小生成树)
查看>>
POJ 1703 Find them, Catch them
查看>>
POJ 1703 Find them, Catch them 并查集
查看>>
POJ 1738 An old Stone Game(石子合并)
查看>>
POJ 1740 A New Stone Game(博弈)题解
查看>>