I'm new to dart and flutter and I got this error:
error: The argument type 'String?' can't be assigned to the parameter type 'String'.
This error occurred when I tried to get fields of a user object from firebase and pass it to the User constructer. I tried the answer from another post, which is to do a null check on the returned user object and uid, but even inside the if statement dart still gives me this error.
Here is the function that the error occurred:
Future<UserSchema> signInWithEmailAndPassword(
String email, String password) async {
var authResult = await FirebaseAuth.instance
.signInWithEmailAndPassword(email: email, password: password);
return UserSchema(authResult.user.uid, authResult.user.email,
authResult.user.displayName, authResult.user.password);
}
And this is the User class:
class UserSchema {
String uid;
String email;
String displayName;
String phoneNumber;
String password;
String city;
String province;
String postCode;
bool hasTransit;
String streetAddress;
UserSchema(this.uid, this.email,this.displayName,this.password,
{this.phoneNumber = '0000000000',
this.postCode = '000000',
this.streetAddress = '000 0000 0000',
this.city = '00',
this.province = '00',
this.hasTransit = false});
Map<String, dynamic> toJson() => {
'uid': uid.trim(),
'displayName': displayName.trim(),
'email': email.trim(),
'phoneNumber': phoneNumber.trim(),
'accountCreated':
DateFormat('dd/MM/yyyy').format(Timestamp.now().toDate()),
'shippingAddress': {
'streetAddress': streetAddress.trim(),
'city': city.trim(),
'PostCode': postCode.trim(),
'province': province.trim(),
},
'hasTransit': hasTransit,
};
I would really appreciate a more detailed answer, thank you.