We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Section 12 Code Shown by Instructor will not work when Null Safety is enabled.
This section requires updating. Students not familiar with Null Safety will be in a bad place of frustration.
The text was updated successfully, but these errors were encountered:
The parameter 'cardChild' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
Sorry, something went wrong.
How to use widgets and objects inside a class without instantiating it such that by default value of that widget is not null
Hey, even I was struggling with the same problem, and I somehow managed to solve it: Actually you have to just add a ?. Here is how:
?
class BaseCard extends StatelessWidget { BaseCard( {required Color color, Widget? cardChild} ){ this.color = color; this.cardChild = cardChild; } late Color color; late Widget? cardChild;
notice there is a ? after Widget in
BaseCard( {required Color color, Widget? cardChild} )
, this says that cardChild is nullable (* you have to put ? after Widget during initialising also late Widget? cardChild;) i hope it was help full
late Widget? cardChild;
No branches or pull requests
Section 12 Code Shown by Instructor will not work when Null Safety is enabled.
This section requires updating. Students not familiar with Null Safety will be in a bad place of frustration.
The text was updated successfully, but these errors were encountered: