Android 使用google进行Flatter Firebase错误签名
我按下谷歌登录按钮时出错, 发生异常。 PlatformException(PlatformException(登录失败,com.google.android.gms.common.api.ApiException:7:,null)) 我已尝试此步骤> 而且已经试着改变我的等级等等 这是我的身份验证码Android 使用google进行Flatter Firebase错误签名,android,firebase,flutter,dart,firebase-authentication,Android,Firebase,Flutter,Dart,Firebase Authentication,我按下谷歌登录按钮时出错, 发生异常。 PlatformException(PlatformException(登录失败,com.google.android.gms.common.api.ApiException:7:,null)) 我已尝试此步骤> 而且已经试着改变我的等级等等 这是我的身份验证码 import 'package:firebase_auth/firebase_auth.dart'; import 'package:google_sign_in/google_sign_in.d
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:rxdart/rxdart.dart';
class AuthService {
final GoogleSignIn _googleSignIn = GoogleSignIn();
final FirebaseAuth _auth = FirebaseAuth.instance;
final Firestore _db = Firestore.instance;
Observable<FirebaseUser> user; // firebase user
Observable<Map<String, dynamic>> profile; // custom user data in Firestore
AuthService() {
user = Observable(_auth.onAuthStateChanged);
profile = user.switchMap((FirebaseUser u) {
if (u != null) {
return _db
.collection('users')
.document(u.uid)
.snapshots()
.map((snap) => snap.data);
} else {
return Observable.just({});
}
});
}
Future<FirebaseUser> googleSignIn() async {
GoogleSignInAccount googleUser = await _googleSignIn.signIn();
GoogleSignInAuthentication googleAuth = await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
final AuthResult authResult = await _auth.signInWithCredential(credential);
FirebaseUser user = authResult.user;
print("signed in " + user.displayName);
return user;
}
void signOut() {
_auth.signOut();
}
}
final AuthService authService = AuthService();
import'package:firebase_auth/firebase_auth.dart';
导入“包:google_sign_in/google_sign_in.dart”;
导入“包:cloud_firestore/cloud_firestore.dart”;
导入“包:rxdart/rxdart.dart”;
类身份验证服务{
最终GoogleSignIn _GoogleSignIn=GoogleSignIn();
final FirebaseAuth _auth=FirebaseAuth.instance;
final Firestore _db=Firestore.instance;
可观察用户;//firebase用户
可观察的配置文件;//Firestore中的自定义用户数据
AuthService(){
用户=可观察(_auth.onAuthStateChanged);
profile=user.switchMap((FirebaseUser u){
如果(u!=null){
返回_db
.collection('用户')
.文件(u.uid)
.快照()
.map((快照)=>快照数据);
}否则{
返回可观察的。just({});
}
});
}
Future googleSignIn()异步{
GoogleSignInAccount googleUser=wait_googleSignIn.signIn();
GoogleSignInAuthentication googleAuth=等待googleUser.authentication;
final AuthCredential credential=GoogleAuthProvider.getCredential(
accessToken:googleAuth.accessToken,
idToken:googleAuth.idToken,
);
final AuthResult AuthResult=wait _auth.signin with credential(凭证);
FirebaseUser=authResult.user;
打印(“登录”+user.displayName);
返回用户;
}
无效签出(){
_auth.signOut();
}
}
final AuthService AuthService=AuthService();
这是我的登录按钮代码
Widget button() {
return RaisedButton(
elevation: 0,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30.0)),
onPressed: () => authService.googleSignIn().whenComplete(() {
Navigator.of(context).pushNamed(HOME_PAGE);
}),
textColor: Colors.white,
padding: EdgeInsets.all(0.0),
child: Container(
alignment: Alignment.center,
width: _large ? _width / 4 : (_medium ? _width / 3.75 : _width / 3.5),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20.0)),
gradient: LinearGradient(
colors: <Color>[Colors.orange[200], Colors.pinkAccent],
),
),
padding: const EdgeInsets.all(12.0),
child: Text('SIGN IN',
style: TextStyle(fontSize: _large ? 14 : (_medium ? 12 : 10))),
),
);
}
Widget按钮(){
返回上升按钮(
海拔:0,
形状:RoundedRectangleBorder(borderRadius:borderRadius.circular(30.0)),
按下时:()=>authService.googleSignIn()。完成时(){
Navigator.of(context.pushNamed)(主页);
}),
textColor:Colors.white,
填充:所有边缘设置(0.0),
子:容器(
对齐:对齐.center,
宽度:_大?_宽/4:(_中?_宽/3.75:_宽/3.5),
装饰:盒子装饰(
borderRadius:borderRadius.all(半径圆形(20.0)),
梯度:线性梯度(
颜色:[colors.orange[200],colors.pinkAccent],
),
),
填充:常数边集全部(12.0),
子项:文本('登录',
样式:TextStyle(fontSize:_大号?14:(_中号?12:10)),
),
);
}
我希望登录后可以进入主页,但它会返回错误消息
发生异常。
PlatformException(PlatformException(登录失败,com.google.android.gms.common.api.ApiException:7:,null))此问题通常在设备出现网络连接问题时出现
- 快乐学习强>