Hello friends, As we were mention in our previous tutorial we are trying to solve some errors comes when we try to parse JSON. Today we are solving an error which many of us faces so many times while working with JSON data. The error is “The parameter ‘id’ can’t have a value of ‘null’ because of its type, but the implicit default value is ‘null’. Try adding either an explicit non-‘null’ default value or the ‘required‘ “. This error comes because dart has enabled null safety feature in its code. Now we can not initialize a variable without any value and call its value in method. We have to define required keyword with it to solve this error. So in this tutorial we would learn about Flutter Solve The parameter ‘id’ can’t have a value of ‘null’ because of its type Error.
Contents in this project Flutter Solve The parameter ‘id’ can’t have a value of ‘null’ because of its type Error :-
1. To solve this error all we have to do is use required keyword with it. See the code example below.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
class appData { String id; String name; appData({required this.id, required this.name}); factory appData.fromJson(Map<String, dynamic> json) { return appData( id: json['id'], name: json['title'], ); } } |
Hope you understand it. If you find any problem regarding to the code, then you can comment below.