marcus04102000
marcus04102000

Reputation: 31

The parameter 'image' can't have a value of 'null' because of its type, but the implicit default value is 'null'

I don't understand the issue with the following Code and would love to hear some ideas on how to solve my problem

Code:

class SplashContent extends StatelessWidget {
  const SplashContent({
    Key? key,
    this.text,
    this.image,

  }) : super(key: key);
  final String text, image;

Upvotes: 1

Views: 992

Answers (1)

Md. Yeasin Sheikh
Md. Yeasin Sheikh

Reputation: 63569

While we are using {} on constructor, and it is known as named paramter/Constructor. By default, all parameters are optional here(named constructor). While we have final String text, image; and did not assign any value, it is showing the errors because of null-safety.

We need to add required before this.image, like required this.image,..

If you wish to accept null value, make those nullable like String? file. And be sure while using nullable value. Also, you can provide default value on constructor.

Upvotes: 3

Related Questions