![](/img/trans.png)
[英]The getter 'displayName' isn't defined for the type 'List<UserModal>'. But I have defined it. Is there something I am doing wrong?
[英]Getter isn't defined for the class. What am i doing wrong here?
我正在跟踪一个使用Flutter构建我的第一个登录系统的教程。 我偶然发现无法解决的吸气剂错误。
在我重构代码以将auth部件移入其自己的文件之前,一切工作正常。
这是有问题的代码:
abstract class BaseAuth {
Future<String> signInWithEmailAndPassword(String email, String password);
}
class Auth implements BaseAuth {
Future<String> signInWithEmailAndPassword(String email, String password) async {
FirebaseUser user = (await
FirebaseAuth.instance.signInWithEmailAndPassword(
email: email,
password: password
)).user;
return user.uid;
}
}
这是我尝试使用的方法:
class LoginPage extends StatefulWidget {
LoginPage({this.auth});
final BaseAuth auth;
@override
State<StatefulWidget> createState() => _LoginPageState();
}
enum FormType {
login,
register
}
...
class _LoginPageState extends State<StatefulWidget> {
final formKey = GlobalKey<FormState>();
String _email;
String _password;
FormType _formType = FormType.login;
void validateAndSubmit() async {
if (validateAndSave()) {
try {
if (_formType == FormType.login) {
String userID = await widget.auth.singInWithEmailAndPassword(_email,_password);
print('Signed in as $userID');
} ...
} catch(e) {
print('Error: $e');
}
}
}
...
}
这是我收到的错误消息:“未为类StatefulWidget定义getter'auth'。
该代码在本教程中工作正常。
我一直在寻找我们的代码库之间的差异,但是对我来说似乎没有什么不合适。 也许有人可以帮助改进者?
class _LoginPageState extends State<StatefulWidget> {
应该
class _LoginPageState extends State<LoginPage> {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.