android - 在构建 Builder 时引发了以下 NoSuchMethodError:在 null 上调用了 getter 'email'。在火力基地
问题描述
在我的代码中,当我按下寄存器时它显示错误。当我删除导航器并打印它正在打印的内容时,在我的 firebase 身份验证中,我看到了我的电子邮件。 错误按摩
TextEditingController email = new TextEditingController();
TextEditingController pass = new TextEditingController();
// String email;
// String password;
press: () async {
// print(email);
// print(password);
// try {
// final newUser = await _auth.createUserWithEmailAndPassword(
// email: email.trim(), password: password.trim());
// if (newUser != null) {
// Navigator.pushNamed(context, ChatScreen.id);
// }
// } catch (e) {
// print(e);
// }
AuthResult user;
try {
user = (await mauth.createUserWithEmailAndPassword(
email: email.text.trim(),
password: pass.text.trim(),
));
print("ok");
} catch (e) {
print(e);
} finally {
if (user != null) {
Navigator.pushNamed(context, ChatScreen.id);
//print('sing up ');
}
}
},
解决方案
如果电子邮件为空,您可以添加默认电子邮件或空文本
TextField(
controller: email ?? '',
keyboardType: TextInputType.emailAddress,
textAlign: TextAlign.center,
decoration: kTextFieldDecoration.copyWith(
hintText: ' Enter your Email',
),
),