随笔分类 - 6-Dart
摘要:https://api.dart.dev/stable/2.9.3/dart-mirrors/dart-mirrors-library.html
阅读全文
摘要:隔离并发,不共享内存,使用消息进程通信 import 'dart:isolate';
阅读全文
摘要:目前Typedefs只能赋值函数,未来可能有其他类型 //定义一个别名 typedef Fu = int Function(int a, int b); class A { //生命一个别名类型 Fu f; A(this.f); } main(List<String> args) { //传一个函数
阅读全文
摘要:相当于java里的注解,C#里的特性, Metadate library todo; class Todo { final String who; final String what; const Todo(this.who, this.what); } @Todo('seth', 'make th
阅读全文
摘要:导入库 导入内置库 import 'dart:html'; 拆分成多个库 a.dart part of "./sum.dart"; class A { static int a = 10; } b.dart part of "./sum.dart"; class B { static int b =
阅读全文
摘要:1.命名 对同一个事物使用相同的名称表示 除非缩写比未缩写的术语更加普遍,否则不要用缩写 优先把描述性强的词语方法最后 pageCount buildRectangles IOStream HttpRequest 考虑把代码读取来像句子一样流畅 // "If errors is empty..."
阅读全文
摘要:一、dart风格 1.大小写 UpperCamelCase 每个单词首字母大写 lowerCamelCase 第一个单词的首字母小写 lowercase_with_underscores 全部小写,字母使用下划线分割 (1)类、枚举类型、typedef和类型参数应使用 UpperCamelCase
阅读全文
摘要:1.库 在 part of 后要使用相对路径的字符串,不要直接使用库名称 part "some/other/file.dart";//好 part of my_library;//坏 导入自己的lib库时要使用相对路径 import 'src/utils.dart'; //好 import 'pac
阅读全文
摘要:1.同步迭代器 函数命名时要在后面加上sync*,使用yield跳出函数体,返回Iterable类型 main() { for (var item in ceshi(0)) { print(item); } } Iterable<int> ceshi(n) sync* { print("Begin"
阅读全文
摘要:https://dart.dev/tools 1.即时编译 2.提前编译
阅读全文
摘要:使用extension on 关键字 main(List<String> args) { String a = 'tom'; print(a.hello()); } extension NumberParsing on String { String hello() { return 'hello
阅读全文
摘要:一、使用包 1.创建一个文件 pubspec.yaml 2.搜索包 在https://pub.flutter-io.cn/ 下搜索dart包 找到对应的包名 写入 name: my_app dependencies: json_serializable: ^3.2.5 http: ^0.12.0+4
阅读全文
摘要:1.一个最简单的异步 main(){ test(); print("end"); } Future<void> test(){ return Future.delayed(Duration( seconds: 3),()=> print("hello")); } end 3秒后打印后打印hello;
阅读全文
摘要:1.异步循环 逻辑上是按顺序执行的,但是这种写法,在有UI界面的情况下耗时的方法不会卡死界面。 main() async{ var data = [1, 2, 3, 4]; var stream = new Stream.fromIterable(data); var sum=await sumSt
阅读全文
摘要:延迟执行 Future.delayed main(){ print('abc'); Duration drt = new Duration(seconds:10);//设置一个10秒的延迟 Future.delayed(drt,(){ print('edf');//延迟执行的程序 }); }
阅读全文
摘要:String s; int str; //无论是字符串还是其他,如果是null这转为“” print(str ?? "");
阅读全文
摘要:一、构造函数 1.默认构造函数 如果不声明构造函数,将为您提供默认构造函数。默认构造函数没有参数,并调用超类中的无参数构造函数 dart不支持重载构造函数,只能有一个构造函数,可以带参数也可以不带参数 2.非默认构造函数不继承 子类不会从其超类继承构造函数。声明没有构造函数的子类只有默认(没有参数,
阅读全文