Skip to content
New issue

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. #20

Open
longtimedeveloper opened this issue Apr 22, 2021 · 3 comments

Comments

@longtimedeveloper
Copy link

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.

@Lakhankumawat
Copy link

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

  • Yeah Yeah i searched a lot on this topic and landed outside somewhere where i don't know what exactly null safety is and how to use it.
  • Actually in her code it didn't show that error but in recent versions it's a problem , they should update the section.

@Lakhankumawat
Copy link

How to use widgets and objects inside a class without instantiating it such that by default value of that widget is not null

@vinayak5002
Copy link

vinayak5002 commented Aug 20, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants