1、其他常用符号与关键字
1.1:级联操作符:..
那Paint对象的设置来看:
---->[情景1:曾经的写法]----
var paint = Paint();
paint.strokeCap = StrokeCap.round;
paint.style = PaintingStyle.stroke; //画线条
paint.color = Color(0xffBBC3C5); //画笔颜色
paint.isAntiAlias = true; //抗锯齿
paint.filterQuality = FilterQuality.high; //抗锯齿
---->[情景2:级联的写法]----
paint
..strokeCap = StrokeCap.round
..style = PaintingStyle.stroke //画线条
..color = Color(0xffBBC3C5) //画笔颜色
..isAntiAlias = true //抗锯齿
..filterQuality = FilterQuality.high;
很简洁,很高大上有木有,
1.2: 条件调用符:?.
---->[情景1:普通调用]----
void main() {
var a = -5;
print(a.abs());//5
}
---->[情景2:普通调用前置空,会崩掉]----
var a = 5;
a=null;
print(a.abs());//NoSuchMethodError: The method 'abs' was called on null.
---->[情景3:?.调用不会崩掉,只返回null]----
var a = 5;
a = null;
print(a?.abs()); //null
1.3:类型判断关键字、is 、 is!和as
var b=10;
print(b is String);//false
print(b is num);//true
print(b is! double);//true
String c="12315";
print((c as Comparable).compareTo("a"));//-1 强制类型转换
print((c as num).abs());//类型转换异常
// type 'String' is not a subtype of type 'num' in type cast
2.库的使用和可见性
2.1:库的基本使用
import 'dart:math';//导入math内置库
import 'package:flutter/material.dart';//根据文件系统路径到包
2.2:类库中的命名冲突: as 关键字的使用
当sin函数处于连个包中,并且两个包都被导入,该怎么办
---->[utils/color_utils.dart]----
sin(double d){
}
---->[main.dart:5]----
import 'package:toly/utils/color_utils.dart';
import 'dart:math';
void main() {