【发布时间】:2022-07-28 19:34:34
【问题描述】:
所以我一直在开发这个 Flutter 应用程序,它只需要使用电子邮件和密码通过 FirebaseAuth.instance.signInWithEmailAndPassword() 登录到 Firebase 身份验证。每当我这样做时,它都会引发此错误:
Android Studio 错误:
[VERBOSE-2:dart_vm_initializer.cc(41)] 未处理异常:[firebase_auth/network-request-failed] 发生网络错误(例如超时、连接中断或无法访问主机)。
XCode 错误:
2022-05-28 22:31:47.393894+0400 Runner[53493:5966626] [connection] nw_socket_handle_socket_event [C1.1:2] Socket SO_ERROR [61: Connection refused]
这是我的 Dart 部分代码(不确定是否需要更多):
try {
final credential = FirebaseAuth.instance.signInWithEmailAndPassword(
email: emailController.text, //emailController is a text field controller
password: passwordController.text //passwordController is a text field controller
);
}
on FirebaseAuthException catch (e) {
if (e.code == 'user-not-found') {
print('No user found for that email.');
} else if (e.code == 'wrong-password') {
print('Wrong password provided for that user.');
} else if (e.code.isEmpty){
print('worked!');
} else{
print(e.code);
}
}
}
我的 XCode 应用委托:
import Flutter
import FirebaseCore
import Firebase
import FirebaseAuth
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure()
FirebaseApp.initialize()
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
Google 服务信息文件包含在项目中。
如果还有什么遗漏的,请告诉我。感谢大家的帮助!
【问题讨论】:
-
你得到答案了吗?
-
遗憾的是没有。我已经尝试了所有方法,现在我只是求助于本地服务器数据库。
标签: swift flutter firebase dart firebase-authentication