Flutter Google Sign In在Android上超级慢

368yc8dk  于 11个月前  发布在  Flutter
关注(0)|答案(1)|浏览(120)

我目前正在Android设备上测试我的Flutter应用程序。我已经使用Firebase添加了Google登录。在iOS上,一切都很好,Android模拟器也很好。
然而,在我的物理三星设备上,事情并不顺利。
我有这个当你按下谷歌登录按钮:

import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';

Future<User?> signInWithGoogle() async {
  // Trigger the authentication flow
  final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();

  // Obtain the auth details from the request
  final GoogleSignInAuthentication? googleAuth =
      await googleUser?.authentication;

  // Create a new credential
  final credential = GoogleAuthProvider.credential(. <--- This takes forever
    accessToken: googleAuth?.accessToken,
    idToken: googleAuth?.idToken,
  );

  // Once signed in, return the UserCredential
  final authResult =
      await FirebaseAuth.instance.signInWithCredential(credential);
  return authResult.user;
}

创建credential变量需要很长时间(分钟)。稍后在管道中,我将从Firebase数据库加载数据。
就这条线
final snapshot = await FirebaseDatabase.instance.ref().child(usersKey).get();
需要几分钟才能完成。我以前从未经历过这种情况。在我的设备上冲浪,无线网络工作得很好。
我尽可能地更新了我的Android设备,然后它就像预期的那样工作了。它可以是它不工作在旧的Android版本?似乎这个功能是几乎所有的应用程序都在使用,应该工作?

ecfsfe2w

ecfsfe2w1#

尝试指定特定范围。
但首先:

  • 一个人需要有OAuth同意屏幕(至少)所有非限制范围
  • googleapis依赖项添加到pubspec

我在玩瞄准镜组合:

GoogleSignInAccount? googleUser = await GoogleSignIn(
      scopes: [
        // people.PeopleServiceApi.userEmailsReadScope,
        people.PeopleServiceApi.userinfoEmailScope,
        // firebase.FirebaseDynamicLinksApi.firebaseScope
      ]).signIn();

还有这些进口:

import 'package:googleapis/people/v1.dart' as people;
import 'package:googleapis/firebasedynamiclinks/v1.dart' as firebase;

希望这有帮助!

相关问题