flatter firebase身份验证问题是一个侧面形式



我正在尝试构建一个在firebase上集成flutter的身份验证系统。我已经正确地集成了所有的firebase类exc。在我的注册页面中,我已经声明了firebase 的授权使用的字符串电子邮件

class _RegisterState extends State<Register> {
String = email;

我也建立了一个表单,但当我按下注册用户的确认按钮时,我遇到了这个问题。

Widget _buildSignIn(BuildContext context) {
return Form(
key: _formKey2,
child: Column(
children: <Widget>[
Stack(
alignment: Alignment.topCenter,
overflow: Overflow.visible,
children: <Widget>[
Card(
elevation: 2.0,
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
child: Container(
width: 300.0,
height: 230.0,
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.only(
top: 20.0, bottom: 20.0, left: 25.0, right: 25.0),
child: TextFormField(
onSaved: (value) {email = value;},
focusNode: myFocusNodeEmailLogin,
controller: loginEmailController,
keyboardType: TextInputType.emailAddress,
style: TextStyle(
fontFamily: "WorkSansSemiBold",
fontSize: 16.0,
color: Colors.black),
decoration: InputDecoration(
border: InputBorder.none,
icon: Icon(
FontAwesomeIcons.envelope,
color: Colors.black,
size: 22.0,
),
hintText: "Email unito",
hintStyle: TextStyle(
fontFamily: "WorkSansSemiBold", fontSize: 17.0),
),
),
),
],
),
),
),
Container(
margin: EdgeInsets.only(top: 210.0),
decoration: new BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5.0)),
boxShadow: <BoxShadow>[
BoxShadow(
color: Theme.Colors.u,
offset: Offset(1.0, 3.0),
),
],
),
child: MaterialButton(
highlightColor: Colors.transparent,
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 12.0, horizontal: 42.0),
child: Text(_isLoginForm ? 'Login' : 'Create account',
style: TextStyle(
color: Colors.white,
fontSize: 25.0,
fontFamily: "WorkSansBold"),
),
),
onPressed: () {

validateAndSubmit();
}
),
),
],
),
],
),
);
}

我认为表单上onSaved内部的问题是没有获得电子邮件值。

validateAndSubmit() function : 
void validateAndSubmit() async {
String userId = "";
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();
});
}

}

错误:

I/flutter(3037(:错误:"package:firebase_auth/src/fifirebase_auth.dart":断言失败:第174行pos 12:'电子邮件!=null":不为真。

这里没有保存表单状态,所以首先将表单状态保存为

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();
});
}

}

最新更新