我正在关注本https://medium.com/@c_innovative/simple-firebase-login-flow-in-flutter-6f44c2b5c58a教程,但在登录时遇到了一些麻烦。我已经将我的应用程序连接到Firebase,并在Firebase控制台上启用了电子邮件和密码身份验证!
我尝试将key参数输入到TextFormfield中,但到目前为止我无法这样做。
class LoginPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _LoginPageState();
}
}
class _LoginPageState extends State<LoginPage> {
final _formKey = GlobalKey<FormState>();
String _email;
String _password;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Login Page Flutter Firebase"),
),
body: Container(
padding: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
Spacer(flex: 5),
Text(
"Login Information",
style: new TextStyle(fontSize: 30.0),
),
Spacer(
flex: 5,
),
TextFormField(
key: _formKey,
onSaved: (value) => _email = value,
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(labelText: "Email Address"),
),
TextFormField(
onSaved: (value) => _password = value,
obscureText: true,
decoration: InputDecoration(labelText: "Password"),
),
Spacer(flex: 3),
RaisedButton(
child: Text("Login"),
onPressed: () async {
//Getting the error here
final form = _formKey.currentState;
form.save();
if (form.validate()) {
print('$_email $_password');
var result = await
Provider.of<AuthService(context).loginUser(email: _email, password:_password);
if (result == null) {
print("result is null");
}
}
}),
Spacer(
flex: 20,
)
],
),
));
}
}
[VERBOSE-2:ui_dart_state.cc(148)]未处理的异常:NoSuchMethodError:方法“保存”在null上被调用。 接收者:null 尝试调用:save()
此错误消息是我得到的。我以某种方式知道我必须初始化接收器对象(?),但是我对如何初始化感到困惑。感谢您的帮助!