so I am using shared preferences in a flutter app and I get this error : The argument type 'String?' can't be assigned to the parameter type 'String' and here is the code:
if (result != null) {
SharedPreferenceHelper().saveUserEmail(userDetails.email);
}
the error is userDetils.email can someone pls help A picture of what it shows
CodePudding user response:
Those are two different types. You need to coerce String? to String either by the null coercion operator: userDetails.email!
or by giving it a default value if it's null: userDetails.email ?? ''
CodePudding user response:
It is sound null safety problem String? means Whatever variable assigned to Stirng? type it can be null or null value is available ,so make sure to check it null or not by providing userDetils.email?? this means userDetils.email is null or not