【问题标题】:the Default 'List' constructor isn't available when null safety enabled [duplicate]启用空安全时,默认“列表”构造函数不可用[重复]
【发布时间】:2021-09-21 06:45:21
【问题描述】:

我写代码的时候出错了

这是我写的代码


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 上出现的错误消息说主体可能正常完成,导致返回“null”,但返回类型可能是不可为空的类型。 然后第二个错误在 List 中说 'list' 已弃用,不应使用

有人可以帮我解决它吗谢谢

【问题讨论】:

    标签: visual-studio flutter dart


    【解决方案1】:
    List<Widget> widgetList = new List<Widget>();
    widgetList.add(child);
    

    需要

    final widgetList = [child];
    

    【讨论】:

      猜你喜欢
      • 2021-11-27
      • 1970-01-01
      • 2021-06-30
      • 2020-12-06
      • 2015-07-10
      • 2019-01-27
      • 2021-10-21
      相关资源
      最近更新 更多