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

你可能感兴趣的文章
Oracle面试题:Oracle中truncate和delete的区别
查看>>
ThreadLocal线程内部存储类
查看>>
thinkphp 常用SQL执行语句总结
查看>>
Oracle:ORA-00911: 无效字符
查看>>
Text-to-Image with Diffusion models的巅峰之作:深入解读 DALL·E 2
查看>>
TCP基本入门-简单认识一下什么是TCP
查看>>
tableviewcell 中使用autolayout自适应高度
查看>>
Orcale表被锁
查看>>
svn访问报错500
查看>>
org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned
查看>>
org.apache.ibatis.type.TypeException: Could not resolve type alias 'xxxx'异常
查看>>
org.apache.poi.hssf.util.Region
查看>>
org.apache.xmlbeans.XmlOptions.setEntityExpansionLimit(I)Lorg/apache/xmlbeans/XmlOptions;
查看>>
org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /
查看>>
org.hibernate.HibernateException: Unable to get the default Bean Validation factory
查看>>
org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
查看>>
SQL-CLR 类型映射 (LINQ to SQL)
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>
org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded
查看>>