-2

enter image description here

I'm new to flutter and trying to use spread operator and Map into a List but I get null safety error , tried using (!) but no good.

  • we can't understand with this answer. – Francesco Bocci Feb 16 '22 at 15:58
  • 2
    can you please add your code to the question? – nagendra nag Feb 16 '22 at 15:59
  • body: Center( // ignore: prefer_const_literals_to_create_immutables child: Column( mainAxisAlignment: MainAxisAlignment.center, // ignore: prefer_const_literals_to_create_immutables children: [ Questions(questions[indexNum]['questionText']), ...(questions[indexNum]['answers'] as List).map((answer) { return Answers(_answerOfQuestion, answer); }).toList() ], ), ), – shaikh usama Feb 16 '22 at 16:08
  • The following _CastError was thrown building MyApp(dirty, state: _MyAppState#e3bfc): type 'Null' is not a subtype of type 'List' in type cast – shaikh usama Feb 16 '22 at 16:09
  • 1
    can you please add your complete code to the question? not in the comment – nagendra nag Feb 16 '22 at 16:18
  • 4
    Hi @shaikhusama! Can you please add your code and all the necessary information in the body of the question? you can do that by editing your own question, this will help other user to answer your question! if you need some help in check how to write a good question please check this link! https://stackoverflow.com/help/how-to-ask – CLucera Feb 16 '22 at 16:25

1 Answers1

0

Although I don't quite understand what you are talking about, I roughly understand where your code is wrong.

This is the example code:

change

_snapshot.data!.name

to

_snapshot.data?.name ?? "Unknown"
Dharman
  • 30,962
  • 25
  • 85
  • 135
My Car
  • 4,198
  • 5
  • 17
  • 50