我第一次遇到Firebase错误,并且不确定为什么它一直显示错误。
错误:
import 'package:firebase_auth/firebase_auth.dart';
class AuthService {
final FirebaseAuth _auth = FirebaseAuth.instance;
// Create user object based on FirebaseUser
CustomUsers _customModelForFirebaseUser(user) {
return user != null ? CustomUsers(uid: user.uid) : null;
}
// auth changed user stream
Stream<CustomUsers> get user {
return _auth.authStateChanges().map(_customModelForFirebaseUser);
}
//Signin Anon
Future signInAnon() async {
try {
UserCredential userCredential = await _auth.signInAnonymously();
CustomUsers user = userCredential.user;
print(_customModelForFirebaseUser(user));
} catch (e) {
print(e.toString());
return null;
}
}
最佳答案
程序包具有相同的类名,这会导致打包冲突。尝试像这样隐藏其中之一
import 'package:firebase_auth/firebase_auth.dart' hide UserCredential;
有关更多说明,请查看此webiste dart-flutter-how-to-solve-naming-conflict-or-ambiguous关于firebase - Firebase中的UserCredential,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/64346553/