在我使用device_info_plus软件包并尝试获取设备信息后,应用程序将无法导航。在谷歌认证期间,我试图获取手机的android id,并将其与谷歌id一起存储在cloud firestore中。我试图限制用户从同一帐户的任何其他设备登录。
D/InputTransport(10544): Input channel destroyed: 'a8ed6c ', fd=98
W/.medical_tayar(10544): Accessing hidden method Lsun/misc/Unsafe;->compareAndSwapObject(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z (greylist, linking, allowed)
W/System (10544): Ignoring header X-Firebase-Locale because its value was null.
I/System.out(10544): (HTTPLog)-Static: isSBSettingEnabled false
I/System.out(10544): (HTTPLog)-Static: isSBSettingEnabled false
D/ViewRootImpl@7d3edce[MainActivity](10544): ViewPostIme pointer 0
D/ViewRootImpl@7d3edce[MainActivity](10544): ViewPostIme pointer 1
I/System.out(10544): (HTTPLog)-Static: isSBSettingEnabled false
I/System.out(10544): (HTTPLog)-Static: isSBSettingEnabled false
I/System.out(10544): (HTTPLog)-Static: isSBSettingEnabled false
I/System.out(10544): (HTTPLog)-Static: isSBSettingEnabled false
I/System.out(10544): (HTTPLog)-Static: isSBSettingEnabled false
I/System.out(10544): (HTTPLog)-Static: isSBSettingEnabled false
我插入的代码是:
GoogleSignIn googleSignIn = GoogleSignIn(
scopes: [
'https://www.googleapis.com/auth/gmail.readonly',
'https://www.googleapis.com/auth/gmail.send',
],
);
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
final FirebaseAuth auth = FirebaseAuth.instance;
CollectionReference users = FirebaseFirestore.instance.collection('users');
Future<void> signInWithGoogle(BuildContext context) async{
try {
final GoogleSignInAccount? googleSignInAccount = await googleSignIn.signIn();
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
if(googleSignInAccount!= null){
GoogleSignInAuthentication googleSignInAuthentication = await
googleSignInAccount.authentication;
//credential gives everything needed about user
AuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleSignInAuthentication.accessToken,
idToken: googleSignInAuthentication.idToken,
);
final UserCredential authResult = await
auth.signInWithCredential(credential);
final User? user = authResult.user;
var userData = {
'name': googleSignInAccount.displayName,
'provider': 'google',
'photoUrl': googleSignInAccount.photoUrl,
'email': googleSignInAccount.email,
'android': androidInfo.model,
};
users.doc(user!.uid).get().then((doc) {
if(doc.exists){
//old user logged in
doc.reference.update(userData);
Navigator.pushReplacementNamed(context, Collections.collection);
}
else{
//new user logged in
users.doc(user.uid).set(userData);
Navigator.pushReplacementNamed(context, Collections.collection);
}
}
);
}
}
catch(PlatformException){
print(PlatformException);
}
}
有人能帮忙吗?
暂无答案!
目前还没有任何答案,快来回答吧!