I'm trying to retrive User data from sharedPreferances with code:
User? get user {
String? u = sharedPreferences.getString("user");
if (u == null) {
return null;
} else {
return User.fromJson(jsonDecode(u));
}
}
but I'm getting error "The return type of getter 'user' is 'User?' which isn't a subtype of the type 'User' of its setter 'user'."
I want to be able to return null but compiler just doesn not allow me because of null safety.
Can someone tell me what I'm missing here?:/