-2

i have an error when i write the code

heres the code i wrote


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,);
    }
  }
}

The error message that appear is on Build says The body might complete normally, causing 'null' to be returned, but the return type is a potentially non-nullable type. Then the Second error is in List says 'list' is deprecated and shouldnt be used

can someone help me to fix it thanks before

1 Answers1

0
List<Widget> widgetList = new List<Widget>();
widgetList.add(child);

needs to be

final widgetList = [child];
nvoigt
  • 75,013
  • 26
  • 93
  • 142