[英]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.