博客
关于我
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/

你可能感兴趣的文章
php详细学习1
查看>>
php语言优劣
查看>>
PHP语言最优雅的支付SDK扩展包
查看>>
PHP请求https域名发生segment fault段错误
查看>>
PHP读写XML文件
查看>>
PHP读写XML文件
查看>>
R&Python Data Science 系列:数据处理(3)
查看>>
php读取xml 数据库字段超长处理
查看>>
php课程 12-40 抽象类的作用是什么
查看>>
php课程 4-16 数组自定义函数(php数组->桶)
查看>>
PHP调用接口用post方法传送json数据
查看>>
php转化IP为整形
查看>>
php输出数据到csv文件
查看>>
php输出语句
查看>>
php运行原理详细说明
查看>>
php运行环境出现Undefined index 或variable时解决方法
查看>>
php进程通信
查看>>
R&Python Data Science 系列:数据处理(2)
查看>>
php递归算法总结
查看>>
PHP递归遍历文件夹
查看>>