Flutter body background

Viewed 35
class Background extends StatelessWidget {
  final Widget child;
  const Background({
    Key key,
    @required this.child,
  }) : super(key: key);

I get this errors. Can someone help?

  • The parameter 'key' can't have a value of 'null' because of its type, but the implicit default value is 'null'. Try adding either an explicit non-'null' default value or the 'required' modifier.

  • With null safety, use the 'required' keyword, not the '@required' annotation. Try removing the '@'.

1 Answers

You are using named constructor and parameters are optional by default, You can include required before Key or make it nullable.

On null-safety @required has been changed to required

class Background extends StatelessWidget {
  final Widget child;
  const Background({
    Key? key,
    required this.child,
  }) : super(key: key);
}

More about using-constructors and StatelessWidget.

And understanding-null-safety

Related