1.Dart环境安装
官网:Get the Dart SDK | Dart
Mac环境:
2.vscode配置
-
安装dart插件
-
安装code runner 插件
3.dart语法(一):
print('你好,dart');//脚本类语言,可以不预先定义类型,自动类型辨别var str = "this is var";String str1 = "this is var";int str2 = 123;//常量 值不变,开始就要初始化const var str3 = "var" ;//常量 可以开始不赋值,只能赋值一次final var str4 = DateTime.now();//常用数据类型bool flag = true;int num1 = 1;double num2 = 1.1;String str5 = "str5";var list = ["str","str1",123,true];print(list.length);print(ist[0]);var list1 = <String>["str","str1","str2"];var list2 = [];list2.add("str1");var list3 = List.filled(2, ""); //固定长度 2 list3[0] = "str";var list4 = List<String>.filled[2,""];var person = {"age":18,"sex":"男","work":["程序员","滴滴"]} var sex = person["sex"];var p = new Map();p["name"] = "王哥";//判断类型 isvar str45 = "1234";if(str45 is String) {print("yes");}else if(str45 is int) {print("no");}else {print("no");}