flutter 常见报蓝集合
程序员文章站
2022-03-11 09:50:11
...
1.This function has a return type of ‘Widget’, but doesn’t end with a return statement.
当widget里有判断返回对应的内容时,没有以return语句结尾
更改:
Widget itemWidget(int type) {
if (type == 0) {
return Container(
margin: EdgeInsets.only(right: px(0)),
child: Text("空闲中",
style: TextStyle(
color: XColor.logisCon,
fontSize: px(12),
fontWeight: FontWeight.bold)));
} else if (type == 1) {
return Container(
margin: EdgeInsets.only(right: px(0)),
child: Text("操作中",
style: TextStyle(
color: XColor.red_F5222D,
fontSize: px(12),
fontWeight: FontWeight.bold)));
}
return Container(); //您需要从此处返回任何小部件,您也可以使用CircularProgressIndicator()
}
2.Avoid using braces in interpolation when not needed
模版字符串,变量包裹问题:当后面没有紧跟的字母时,避免使用花括号
更改:
log("stock_list:${list.length}");
log("stock_list:$list"); //在标识符后面没有紧跟的字母时,避免使用花括号
log("model=$model,type= $type");
3.This method overrides a method annotated as ‘@mustCallSuper’ in ‘AutomaticKeepAliveClientMixin’, but doesn’t invoke the overridden method.**
当为了实现页面keepalive,使用了AutomaticKeepAliveClientMixin方法
子类必须实现[wantKeepAlive],并且它们的[build]方法必须调用super.build(返回值始终返回null,应将其忽略)
@override
Widget build(BuildContext context) {
super.build(context); //调用super.build(返回值始终返回null,应将其忽略)
return onBuild(context);
}
推荐阅读