没有合适的资源?快使用搜索试试~ 我知道了~
1.3 将引用使用as转换的名字也需要小写加下划线,如下所示:import 'dart:math' as math 1.4 变量名、方法、参数名都应该是小驼峰命
资源详情
资源评论
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/86373196/bg1.jpg)
前端编程规范(使用 Dart 语言)
1. 样式规范
1.1 类、枚举、类型定义和泛型,都需要大写开头的驼峰命名法,如下所示:
class Foo() {
const Foo([args])
}
1.2 命名库、包、目录、dart 文件都应该是小写加下划线,如下所示:
library peg_parser.source_scanner;
import 'file_system.dart';
1.3 将引用使用 as 转换的名字也需要小写加下划线,如下所示:
import 'dart:math' as math;
import 'package:js/js.dart' as js;
1.4 变量名、方法、参数名都应该是小驼峰命名法,如下所示:
const pi = 3.14;
const defaultTimeout = 1000;
final urlScheme = RegExp('^([a-z]+):');
2. 文档规范
2.1 注释使用///
2.2 使用一句简明扼要的话作为开头 空一格 将参数和返回值使用[]加持,如下所示:
/// Throws an [IOError] if the file could not be found.Throws a
/// [PermissionError] if the file is present but could not be deleted.
3. 使用规范
3.1 使用相对路径导入依赖,如下所示:
import 'src/utils.dart';
4. 字符串
4.1 dart 中,不需要使用+连接字符串,使用 ${} 连接字符串和变量,如下所示:
'Hello, $name! You are ${year - birthday} years old. '
5. 集合
5.1 尽可能使用简单的字面量创建集合,如下所示:
var points = [];
var addressses = {};
5.2 使用 isEmpty 或 isNotEmpty 判断集合是否为空,如下所示:
if(lunchBox.isEmpty) return 'so hungry...'
if(words.isNotEmpty) return words.join(' ');
5.3 使用高阶方法转换序列,如下所示:
var aquaticNames = animals
.where((animal) => animal.isAquatic)
.map((animal) => animal.name);
5.4 不要使用 List.from() 除非打算更改结果的类型,有两种方法可以获取 Iterable,分
别是 List.from() 和 Iterable.toList(),如下所示:
var iterable = [1, 2, 3];
/// 输出`List<int>`
/// 如果使用 List.from 的话,会输出`List<dynamic>`
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![js](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![vsix](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![exe](https://img-home.csdnimg.cn/images/20210720083343.png)
![apk](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![thumb](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![avatar](https://profile-avatar.csdnimg.cn/02a6fb2834cc4ccd9f848d10202d6230_weixin_35760923.jpg!1)
文润观书
- 粉丝: 26
- 资源: 317
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)
评论0