Flutter 侧面表单中的flatterfirebase身份验证问题
您好,我正在尝试在firebase上构建一个带有Flitter集成的身份验证系统。我已经正确地集成了所有firebase类exc。在我的注册页面中,我声明了firebase的授权人使用的字符串emailFlutter 侧面表单中的flatterfirebase身份验证问题,flutter,Flutter,您好,我正在尝试在firebase上构建一个带有Flitter集成的身份验证系统。我已经正确地集成了所有firebase类exc。在我的注册页面中,我声明了firebase的授权人使用的字符串email class _RegisterState extends State<Register> { String = email; 错误: I/flutter ( 3037): Error: 'package:firebase_auth/src/firebase
class _RegisterState extends State<Register> {
String = email;
错误:
I/flutter ( 3037): Error: 'package:firebase_auth/src/firebase_auth.dart': Failed assertion: line 174
pos 12: 'email != null': is not true.
这里您还没有保存表单状态,所以首先将表单状态保存为
void validateAndSubmit() async {
String userId = "";
_formKey2.currentState.save();
try {
if (_isLoginForm) {
userId = await widget.auth.signIn(email, _password);
print('Signed in: $userId');
} else {
userId = await widget.auth.signUp(email, _password);
//widget.auth.sendEmailVerification();
//_showVerifyEmailSentDialog();
print('Signed up user: $userId');
}
setState(() {
_isLoading = false;
});
if (userId.length > 0 && userId != null && _isLoginForm) {
widget.loginCallback();
}
}catch (e) {
print('Error: $e');
setState(() {
_isLoading = false;
_errorMessage = e.message;
_formKey2.currentState.reset();
});
}
}
请添加
validateAndSubmit
函数。刚刚添加了@HemanthRaj
I/flutter ( 3037): Error: 'package:firebase_auth/src/firebase_auth.dart': Failed assertion: line 174
pos 12: 'email != null': is not true.
void validateAndSubmit() async {
String userId = "";
_formKey2.currentState.save();
try {
if (_isLoginForm) {
userId = await widget.auth.signIn(email, _password);
print('Signed in: $userId');
} else {
userId = await widget.auth.signUp(email, _password);
//widget.auth.sendEmailVerification();
//_showVerifyEmailSentDialog();
print('Signed up user: $userId');
}
setState(() {
_isLoading = false;
});
if (userId.length > 0 && userId != null && _isLoginForm) {
widget.loginCallback();
}
}catch (e) {
print('Error: $e');
setState(() {
_isLoading = false;
_errorMessage = e.message;
_formKey2.currentState.reset();
});
}
}