我写代码时出错
这是我写的代码
class ProgressHUD extends StatelessWidget {
final Widget child;
final bool inAsyncCall;
final double opacity;
final Color color;
final Animation<Color> valueColor;
ProgressHUD({
required Key key,
required this.child,
required this.inAsyncCall,
this.opacity = 0.3,
this.color = Colors.grey,
required this.valueColor,
}) : super(key: key);
@override
Widget build(BuildContext context) {
List<Widget> widgetList = new List<Widget>();
widgetList.add(child);
if (inAsyncCall) {
final model = new Stack(
children: [
new Opacity(
opacity: opacity,
child: ModalBarrier(dismissible: false, color: color),
),
new Center(
child: new CircularProgressIndicator()
),
],
);
return Stack(children: widgetList,);
}
}
}
<块引用>
出现在 Build 上的错误消息说主体可能正常完成,导致返回“空”,但返回类型可能是不可为空的类型。 然后第二个错误在 List 中说“list”已被弃用,不应使用
有人可以帮我修复它吗 谢谢
答案 0 :(得分:0)
List<Widget> widgetList = new List<Widget>();
widgetList.add(child);
必须
final widgetList = [child];