dart - Firebase 身份验证无法在我的颤振应用中使用谷歌登录
问题描述
我在我的 Flutter 应用程序中使用了 firebase-auth 和 google-signin,当点击“使用 Google 登录”按钮时,会打开一个 google 弹出窗口,以便我可以选择我想要使用的 google 帐户,当我点击在我的帐户上,弹出关闭,我在我的控制台中有这个:
D/ViewRootImpl@8929a4d[SignInHubActivity](25903): MSG_WINDOW_FOCUS_CHANGED 1
V/InputMethodManager(25903): Starting input: tba=android.view.inputmethod.EditorInfo@c535c6f nm : com.youpa.youpa ic=null
D/InputMethodManager(25903): startInputInner - Id : 0
I/InputMethodManager(25903): startInputInner - mService.startInputOrWindowGainedFocus
D/InputTransport(25903): Input channel constructed: fd=101
D/ViewRootImpl@8929a4d[SignInHubActivity](25903): MSG_WINDOW_FOCUS_CHANGED 0
I/flutter (25903): Error : ** firebase_error.sign_in_failed not found
D/ViewRootImpl@b0e6bd3[MainActivity](25903): MSG_WINDOW_FOCUS_CHANGED 1
V/InputMethodManager(25903): Starting input: tba=android.view.inputmethod.EditorInfo@2825d7c nm : com.youpa.youpa ic=null
D/InputMethodManager(25903): startInputInner - Id : 0
I/InputMethodManager(25903): startInputInner - mService.startInputOrWindowGainedFocus
D/InputTransport(25903): Input channel constructed: fd=110
D/InputTransport(25903): Input channel destroyed: fd=101
D/OpenGLRenderer(25903): eglDestroySurface = 0xbbbe7e60, 0xc1571800
D/ViewRootImpl@8929a4d[SignInHubActivity](25903): Relayout returned: old=[0,0][720,1280] new=[0,0][720,1280] result=0x5 surface={valid=false 0} changed=true
D/ViewRootImpl@8929a4d[SignInHubActivity](25903): dispatchDetachedFromWindow
D/InputEventReceiver(25903): channel '5a554e2 com.youpa.youpa/com.google.android.gms.auth.api.signin.internal.SignInHubActivity (client)' ~ Disposing input event receiver.
D/InputEventReceiver(25903): channel '5a554e2 com.youpa.youpa/com.google.android.gms.auth.api.signin.internal.SignInHubActivity (client)' ~NativeInputEventReceiver.
D/InputTransport(25903): Input channel destroyed: fd=97
而且我没有登录。但是,我的带有电子邮件的 firbase 身份验证系统运行良好。在这里,您有我的 Google 登录按钮的 onPressed :
onPressed: () {
Auth()
.handleSignInWithGoogle()
.then((FirebaseUser user) {
}).catchError((e) {
print("Error : " +
internationalization
.text("firebase_error." + e.code));
});
},
在这里,您有我的身份验证服务的某些部分:
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:youpa/Model/user.model.dart';
import 'package:firebase_core/firebase_core.dart';
import 'options.services.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'dart:io';
class Auth {
final GoogleSignIn googleSignIn = GoogleSignIn(
scopes: [
'email',
'https://www.googleapis.com/auth/contacts.readonly',
'profile'
],
);
final FirebaseAuth firebaseAuth = FirebaseAuth.instance;
SharedPreferences prefs;
final FirebaseAuth auth = FirebaseAuth.instance;
Future<FirebaseUser> handleSignInWithGoogle() async {
final GoogleSignInAccount googleUser = await googleSignIn.signIn();
final GoogleSignInAuthentication googleAuth = await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
FirebaseUser user = await auth.signInWithCredential(credential);
assert(user.email != null);
assert(user.displayName != null);
assert(!user.isAnonymous);
assert(await user.getIdToken() != null);
final FirebaseUser currentUser = await auth.currentUser();
assert(user.uid == currentUser.uid);
print(user);
print(currentUser);
return user;
}
}
你知道错误在哪里吗?提前致谢。杰里米。
解决方案
推荐阅读
- python - 如何在 ubuntu 14 中安装 aws-sam-cli?
- python - Base64.encode 字符串在 python 中不起作用,键入错误:内存视图:需要类似字节的对象
- typescript - Typescript 2.8+:如何捕获动作创建者并将其映射到动作处理程序?
- java - multipart/form-data 端点是否在服务器上创建临时文件
- node.js - Firebase数据库如何防止并发读取?
- hyperledger-fabric - 通道上没有锚节点可以吗?
- python - 如何取消暂存/恢复未应用的迁移?
- asp.net - 如何根据 HeaderName 将“Textmode”动态设置为 gridview 列
- batch-file - BATCH 无法加入变量
- c++ - std::_USE 未定义