博客
关于我
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 1088 滑雪
查看>>
POJ 1095 Trees Made to Order
查看>>
POJ 1113 Wall(计算几何--凸包的周长)
查看>>
poj 1125Stockbroker Grapevine(最短路)
查看>>
Qualitor processVariavel.php 未授权命令注入漏洞复现(CVE-2023-47253)
查看>>
poj 1151 (未完成) 扫描线 线段树 离散化
查看>>
POJ 1151 / HDU 1542 Atlantis 线段树求矩形面积并
查看>>
poj 1163 数塔
查看>>
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(回溯)
查看>>