我有一個signUpUser Future在Auth class某種程度上驗證用戶詳細資訊onSubmit的函式,該函式驗證電子郵件和密碼,但當用戶不輸入 ausername或時仍然提交bio。我收到:[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'Null' is not a subtype of type 'Map<String, dynamic>' in type cast但用戶仍處于登錄狀態。
Future<String> signupUser({
required String email,
required String password,
required String username,
required String bio,
required Uint8List file,
}) async {
String res = 'Some error occurred';
try {
if (email.isNotEmpty ||
password.isNotEmpty ||
username.isNotEmpty ||
bio.isNotEmpty ||
file != null) {
//register user
UserCredential cred = await _auth.createUserWithEmailAndPassword(
email: email, password: password);
print(cred.user!.uid);
String imageUrl = await StorageMethods()
.uploadImageToStorage('profileImages', file, false);
// add user to database
model.User user = model.User(
email: email,
username: username,
uid: cred.user!.uid,
imageUrl: imageUrl,
bio: bio,
followers: [],
following: [],
);
await _firestore
.collection('users')
.doc(cred.user!.uid)
.set(user.toJson());
res = 'success';
} else if (email.isEmpty && password.isEmpty) {
res = 'Please enter email and password';
} else if (email.isEmpty || password.isEmpty) {
res = 'Please enter email and password';
} else if (username.isEmpty) {
res = 'Please enter username';
} else if (bio.isEmpty) {
res = 'Please enter bio';
}
} on FirebaseAuthException catch (err) {
//print(err);
if (err.code == 'invalid-email') {
res = 'The email address is badly formatted';
} else if (err.code == 'weak-password') {
res = 'The password must be longer than 6 characters';
} else if (err.code == 'email-already-in-use') {
res = 'The email address already exists';
} else {
res = 'Please enter all fields';
}
} catch (err) {
res = err.toString();
print(res);
}
return res;
}
我正在使用 TextEditingController 來保存文本。如果我必須添加更多代碼,請告訴我?
uj5u.com熱心網友回復:
你會想要改變你的'||' '&&' 的子句。您目前已將其寫入允許用戶嘗試和注冊,只要他們輸入其中任何一個欄位。通過放置一個“&&”,它將要求在嘗試注冊之前輸入所有這些欄位。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/514390.html
