我是 flutter 的新手,正在学习关于 yt 的教程。 问题是,在我单击登录按钮后,系统提示我使用 google 登录,但登录后它不会路由到主页并停留在登录页面上。
这是我得到的错误:
W/tions.notes_ap(31551): Accessing hidden method Ldalvik/system/CloseGuard;->close()V (greylist,core-platform-api, linking, allowed)
W/ActivityThread(31551): handleWindowVisibility: no activity for token android.os.BinderProxy@a7ff7e3
W/tions.notes_ap(31551): Accessing hidden method Ldalvik/system/CloseGuard;->warnIfOpen()V (greylist,core-platform-api, linking, allowed)
W/tions.notes_ap(31551): Accessing hidden method Lsun/misc/Unsafe;->compareAndSwapObject(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z (greylist, linking, allowed)
W/tions.notes_ap(31551): Accessing hidden method Lsun/misc/Unsafe;->compareAndSwapObject(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z (greylist, linking, allowed)
W/System (31551): Ignoring header X-Firebase-Locale because its value was null.
W/System (31551): Ignoring header X-Firebase-Locale because its value was null.
D/FirebaseAuth(31551): Notifying id token listeners about user ( A786R9LAtCasjljXQm6RbApJD2R2 ).
W/DynamiteModule(31551): Local module descriptor class for providerinstaller not found.
I/DynamiteModule(31551): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller(31551): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
W/tions.notes_ap(31551): Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
W/tions.notes_ap(31551): Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
W/tions.notes_ap(31551): Accessing hidden method Lsun/misc/Unsafe;->putObject(Ljava/lang/Object;JLjava/lang/Object;)V (greylist, linking, allowed)
W/tions.notes_ap(31551): Accessing hidden method Lsun/misc/Unsafe;->putLong(Ljava/lang/Object;JJ)V (greylist, linking, allowed)
W/tions.notes_ap(31551): Accessing hidden method Lsun/misc/Unsafe;->getInt(Ljava/lang/Object;J)I (greylist, linking, allowed)
W/tions.notes_ap(31551): Accessing hidden method Lsun/misc/Unsafe;->putObject(Ljava/lang/Object;JLjava/lang/Object;)V (greylist, linking, allowed)
W/tions.notes_ap(31551): Accessing hidden method Lsun/misc/Unsafe;->getObject(Ljava/lang/Object;J)Ljava/lang/Object; (greylist, linking, allowed)
W/tions.notes_ap(31551): Accessing hidden method Lsun/misc/Unsafe;->putInt(Ljava/lang/Object;JI)V (greylist, linking, allowed)
W/tions.notes_ap(31551): Accessing hidden method Lsun/misc/Unsafe;->getLong(Ljava/lang/Object;J)J (greylist,core-platform-api, linking, allowed)
W/Firestore(31551): (23.0.2) [Firestore]: Listen for Query(target=Query(users/A786R9LAtCasjljXQm6RbApJD2R2 order by __name__);limitType=LIMIT_TO_FIRST) failed: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}
E/flutter (31551): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: [cloud_firestore/permission-denied] The caller does not have permission to execute the specified operation.
E/flutter (31551): #0 MethodChannelDocumentReference.get (package:cloud_firestore_platform_interface/src/method_channel/method_channel_document_reference.dart:80:7)
E/flutter (31551): <asynchronous suspension>
E/flutter (31551): #1 _JsonDocumentReference.get (package:cloud_firestore/src/document_reference.dart:143:7)
E/flutter (31551): <asynchronous suspension>
E/flutter (31551):
W/Firestore(31551): (23.0.2) [WatchStream]: (b04eca) Stream closed with status: Status{code=CANCELLED, description=Disconnecting idle stream. Timed out waiting for new targets., cause=null}.
这些是我对 pubspec.yaml 的依赖:
dependencies:
flutter:
sdk: flutter
flutter_svg: ^0.22.0
animated_text_kit: ^4.2.1
firebase: ^9.0.1
firebase_core: ^1.3.0
firebase_auth: ^2.0.0
cloud_firestore: ^2.3.0
google_sign_in: ^5.0.4
intl: ^0.17.0
这是点击登录按钮时执行的代码:
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:notes_app/Pages/home.dart';
GoogleSignIn googleSignIn = GoogleSignIn();
final FirebaseAuth auth = FirebaseAuth.instance;
CollectionReference users = FirebaseFirestore.instance.collection('users');
void signInWithGoogle(BuildContext context) async {
try {
final GoogleSignInAccount? googleSignInAccount = await googleSignIn.signIn();
if (googleSignInAccount != null) {
final GoogleSignInAuthentication googleSignInAuthentication =
await googleSignInAccount.authentication;
final 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,
};
users.doc(user!.uid).get().then((doc) {
if (doc.exists) {
// old user
doc.reference.update(userData);
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) => HomePage(),
),
);
} else {
// new user
users.doc(user.uid).set(userData);
Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) => HomePage(),
),
);
}
});
}
} catch (PlatformException) {
print(PlatformException);
print("Sign in not successful !");
}
}
答案 0 :(得分:0)
根据您的错误,您的 firebase 数据库规则似乎已过期,读取、写入:true;
转到您的 firebase 数据库并单击规则并编辑您的规则。
在数据库 firebase 中设置规则