0

@required to a property gave such ERROR: The parameter 'lng' can't have a value of 'null' because of its type, but the implicit default value is 'null'. (Documentation)

but removing @, removes the error. how ? I mean, the value still can be null. What does it have to do with "@" symbol.

see pictures: enter image description here

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
Saad Mansoor
  • 199
  • 7
  • Can you include as code-snipppet & dart,flutter version – Md. Yeasin Sheikh Oct 27 '22 at 11:48
  • the @ means the word next to it is a notation, and I think you cannot use there. About the null warning, the compiler is basically saying that you defined an atributte as non nullable and you are not initializing it in the constructor. or you define lng as nullable and remove the required keyword or you can define it as non nullable and use the required keyword at the constructor. – Alberto Azinar Oct 27 '22 at 11:50

1 Answers1

0

You dont need to use @ anymore, just use required.

({ 
  required this.lat,
  required this.lng,
})

if you like to accept null data, use DataType? varName.

String? lat;
String? lng;

More about understanding-null-safety

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56