【发布时间】:2021-09-08 03:38:22
【问题描述】:
没有为“FirebaseAuth”类型定义吸气剂“onAuthStateChanged”。 尝试导入定义“onAuthStateChanged”的库,将名称更正为现有 getter 的名称,或定义名为“onAuthStateChanged”的 getter 或字段 谢谢 代码在下面..
import 'package:brew_crew/model/user.dart';
import 'package:firebase_auth/firebase_auth.dart';
class AuthService{
final FirebaseAuth _auth = FirebaseAuth.instance;
// Create user object based on FirebaseUser
CurrentUser? _customModelForFirebaseUser(User user) {
return user != null ? CurrentUser (uid: user.uid) : null;
}
// auth changed user stream
Stream<CurrentUser > get user {
return _auth.onAuthStateChanged // here is the problem
.map(_customModelForFirebaseUser);
}
//sin in anon
Future signInAnon() async{
try {
UserCredential result = await _auth.signInAnonymously();
User? user = result.user;
return _customModelForFirebaseUser(user!);
}catch (e) {
print(e.toString());
return null;
}
}
//sign in with E-mail and password
//Register with E-mail and passqord
//Sign out
}
【问题讨论】: