Reputation: 31
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
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