Flutter Demo App with Null Safety

929 views
Skip to first unread message

Paul Snyder

unread,
Apr 20, 2021, 10:05:17 PM4/20/21
to Flutter Development (flutter-dev)
Out of curiosity I ran the Flutter demo app after 2.12. I am pretty sure it built without errors the first time I tried since the app worked fine on the emulator. However when I tried to build a day later I get -
lib/main.dart:36:19: Error: The parameter 'key' can't have a value of 'null' because of its type 'Key', but the implicit default value is 'null'. and a similar error with this.title. Making key nullable and this.title required solves the problem but 1) am I the only one getting this error, and 2) is there any risk of a Null value in the Demo or is the error message an error? Thanks
 -
Try adding either an explicit non-'null' default value or the 'required' modifier.
  MyHomePage({Key key, this.title}) : super(key: key);

Brett Morgan

unread,
Apr 20, 2021, 10:25:50 PM4/20/21
to Paul Snyder, Flutter Development (flutter-dev)
Hey Paul.

If you look at where you call MyHomePage, I'm guessing you aren't specifying the key. It's optional in the StatelessWidget constructor for a reason =)

If you modify your code as follows you should be fine:

MyHomePage({Key? key, this.title}) : super(key: key);

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/d18c22e6-06c4-4b0f-b922-1eb1c77549bdn%40googlegroups.com.

Paul Snyder

unread,
Apr 21, 2021, 12:07:39 PM4/21/21
to Flutter Development (flutter-dev)
Thanks - adding required before this.title was also necessary to get rid of the NS error
Reply all
Reply to author
Forward
0 new messages