I had been working after a long time with flutter and this new null safety is just breaking my code.
I had created a data model class to store values as an object as follows:
class MyClass{
int x;
String y;
MyClass({this.x, this.y});
.. .. ..rest of the code
}
Now in a provider I am having a list of MyClass objects to store data from the db. Over here I am using the firstWhere() to search for the required object by id.
MyClass getObj(int id){
return list.firstWhere((obj) => obj.id == id, orElse: ()=>null);
}
But this keeps giving the error:
type ‘Null’ cant be assigned as it isn’t a subtype of MyClass
I tried firstWhereOrNull and also other solutions but to no avail.