1、Avoid empty catch blocks.
如果try catch 中的catch没有任何实现则需要把catch的e异常改为_即可消除警告
try {
...
} catch (e) {}
更改为:
try {
...
} catch (_) {}
2、Prefer const with constant constructors.
意思是需要加上const常量修饰符
EdgeInsets.all(0),
更改为:
const EdgeInsets.all(0),
3、Prefer using if null operators.
发生在使用三目运算符当中
widget.btnHeight == null
? ScreenUtil.getInstance().getHeight(48.0)
: widget.btnHeight,
更改为:
widget.btnHeight ?? ScreenUtil.getInstance().getHeight(48.0),
4、The '!' will have no effect because the receiver can't be null.
在定义空安全之后的使用中
double? _twidth = (widget.textWidth ?? ScreenUtil.getInstance().getWidth(280.0));
double _spadding = (_swidth - _twidth!) / 2;
更改为:
double? _twidth = (widget.textWidth ?? ScreenUtil.getInstance().getWidth(280.0));
double _spadding = (_swidth - _twidth) / 2;
5、Don't access members with this
unless avoiding shadowing.
引用了this关键字
this.widget.clickOnTap
更改为:
widget.clickOnTap
6、SizedBox for whitespace.
使用Container布局
Container()
更改为:
SizedBox()
6、Unnecessary new keyword.
创建布局控件时使用new关键字
new Text()
更改为:
Text()
7、Avoid using braces in interpolation when not needed.
日志输出的时候对于单独的变量使用了大括号
print("scanEndHandler-->${isScanning}");
更改为:
print("scanEndHandler-->$isScanning");
8、Use key in widget constructors.
定义的StatefulWidget 中没有添加构造方法
const GuidePage({Key? key}) : super(key: key);
9、The method doesn't override an inherited method.
定义方法之前添加了@override
@override
Widget A(){
}
更改为
Widget A(){
}
删除@override