【发布时间】:2020-08-10 02:07:48
【问题描述】:
我正在为安卓设备设计一个来自flutter的聊天应用程序,但是当我添加一个用于firebase身份验证的插件时,它给出了以下异常。我接受你的答复。提前谢谢!
Flutter: MissingPluginException(No implementation found for method createUserWithEmailAndPassword on channel plugins.flutter.io/firebase_auth)
这是注册屏幕中的代码
class _RegistrationScreenState extends State<RegistrationScreen> {
final _auth = FirebaseAuth.instance;
String email;
String password;
.
.
.
onPressed: () async{
try {
final newUser = await _auth.createUserWithEmailAndPassword(
email: email, password: password);
if(newUser!=null){
Navigator.pushNamed(context, ChatScreen.id);
}
}catch(e){
print(e);
}
},
这是聊天界面的代码
class _ChatScreenState extends State<ChatScreen> {
final _auth = FirebaseAuth.instance;
FirebaseUser loggedInUser;
@override
void initState(){
super.initState();
getCurrentUser();
}
void getCurrentUser() async{
try {
final user = await _auth.currentUser();
if (user != null) {
loggedInUser = user;
print(loggedInUser.email);
}
}catch(e){
print(e);
}
}
.
.
.
【问题讨论】:
-
您可以添加您创建 _auth 对象的位置和方式吗?
-
好的,我更新了代码,包括我创建 _auth 对象的地方
-
如果您添加插件但没有完全重启,那么您也可能会遇到同样的错误,所以请尝试完全重启您的应用。
-
@VirenVVarasadiya,当我完全重启时,它现在正在工作。谢谢。
标签: android-studio flutter firebase-authentication