我正在使用 firebase auth 实现 Google 登录,并将相应的用户信息存储在 Cloud Firestore 和共享首选项中。在我的手机上运行该应用程序并点击登录/注册按钮时,会出现带有可用帐户的弹出窗口。但是当我选择所需的Google帐户时,弹出窗口消失并出现错误,如下:
[firebase_auth/network-request-failed] 发生网络错误(例如超时、连接中断或主机无法访问)。
此外,Cloud Firestore 控制台和 Firebase Auth 的“用户”部分中都不会存储任何帐户和用户详细信息。但详细信息存储在共享首选项中,并且当我重新运行应用程序时能够直接导航到主页。我的代码是:
class Login extends StatefulWidget {
static final String id = 'login_screen';
const Login({Key? key}) : super(key: key);
@override
State<Login> createState() => _LoginState();
}
class _LoginState extends State<Login> {
final GoogleSignIn googleSignIn = new GoogleSignIn();
final FirebaseAuth firebaseAuth = FirebaseAuth.instance;
late SharedPreferences preferences;
bool loading = false;
bool isLoggedIn = false;
User? user;
@override
void initState() {
super.initState();
isSignedIn();
}
void isSignedIn() async { …Run Code Online (Sandbox Code Playgroud) firebase firebase-authentication flutter google-cloud-firestore