I am having this error and i dont know how to resolved it pls help me out:
The method 'where' was called on null.
Receiver: null
Tried calling: where(Closure: (UserModel) => bool)
This is where the error is coming from:
The List is of type the UserModel class which is writen below
List<UserModel> userList;
final List<UserModel> suggestionList = query.isEmpty
?[]
: userList.where((UserModel user) {
String _getUsername = user.username.toLowerCase();
String _query = query.toLowerCase();
String _getName = user.name.toLowerCase();
bool matchesUsername = _getUsername.contains(_query);
bool matchesName = _getName.contains(_query);
return (matchesUsername || matchesName);
}).toList();
This is the class which the userList
is calling from:
This is the Model class that is begin called.
class UserModel {
String uid;
String name;
String email;
String username;
String status;
int state;
String profilePhoto;
UserModel({
this.uid,
this.name,
this.email,
this.username,
this.status,
this.state,
this.profilePhoto,
});
Map toMap(UserModel user) {
var data = Map<String, dynamic>();
data['uid'] = user.uid;
data['name'] = user.name;
data['email'] = user.email;
data['username'] = user.username;
data["status"] = user.status;
data["state"] = user.state;
data["profile_photo"] = user.profilePhoto;
return data;
}
UserModel.fromMap(Map<String, dynamic> mapData) {
this.uid = mapData['uid'];
this.name = mapData['name'];
this.email = mapData['email'];
this.username = mapData['username'];
this.status = mapData['status'];
this.state = mapData['state'];
this.profilePhoto = mapData['profile_photo'];
}
}
question from:
https://stackoverflow.com/questions/65843105/the-method-where-was-called-on-null-receiver-null-tried-calling-whereclosu 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…