“Flutter Sign In Screen, Sign in with Google shows ‘An unknown error occurred'”

huangapple go评论80阅读模式
英文:

Flutter Sign In Screen, Sign in with Google shows "An unknown error occurred"

问题

以下是您提供的代码部分的翻译:

在升级到Flutter 3.10后,我使用Flutter登录屏幕构建了我的Android应用程序。当我点击“使用Google账户登录”按钮时,会弹出一个对话框,让我选择我的Google账户。选择后,登录屏幕显示出现了未知错误。我甚至已经升级了包,但没有任何变化。

这是main.dart的一部分:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

  /// 该应用程序使用电子邮件和Google提供程序进行登录。
  FirebaseUIAuth.configureProviders([
    EmailAuthProvider(),
    GoogleProvider(
        clientId:
            '在此处添加客户端ID'),
    // ... 如果需要,可以在这里添加其他提供程序
  ]);

  /// 这可以防止应用程序旋转到横向模式。
  SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
      .then((_) {
    runApp(EasyDynamicThemeWidget(child: const MyApp()));
  });
}

这是我的auth_gate.dart的一部分:

class _AuthGateState extends State<AuthGate> {
  @override
  Widget build(BuildContext context) {
    return StreamBuilder<User?>(
      stream: FirebaseAuth.instance.authStateChanges(),
      builder: (context, snapshot) {
        if (!snapshot.hasData) {
          return SignInScreen(
            headerBuilder: (context, constraints, _) {
              return Image.asset("assets/qaizenlogo.png");
            },
            footerBuilder: (context, action) {
              return Padding(
                  padding: const EdgeInsets.only(top: 40.0),
                  child: Text.rich(TextSpan(text: '需要帮助?', children: [
                    TextSpan(
                        text: '联系我们',
                        style: const TextStyle(
                          //color: Theme.of(context).primaryColor,
                          color: Colors.deepPurple,
                          fontSize: 16,
                          decoration: TextDecoration.underline,
                          fontStyle: FontStyle.italic,
                          fontWeight: FontWeight.bold,
                        ),
                        recognizer: TapGestureRecognizer()
                          ..onTap = () {
                            showDialog(
                                context: context,
                                builder: (ctx) => AlertDialog(
                                      icon: const Icon(
                                        Icons.phone_outlined,
                                        color: Colors.blue,
                                      ),
                                      title: const Text("联系我们"),
                                      content: const Text(
                                        "我们在这里帮助您解决任何问题或疑虑。您想继续拨打电话吗?",
                                        style: TextStyle(fontSize: 18),
                                      ),
                                      actions: <Widget>[
                                        TextButton(
                                          onPressed: () async {
                                            Navigator.of(ctx).pop();
                                            //拨打电话
                                            //当授予通话权限时:
                                            await FlutterPhoneDirectCaller
                                                .callNumber('在此处添加电话号码');
                                            //否则未授予权限,只显示电话号码
                                            if (await Permission
                                                .phone.isDenied) {
                                              makePhoneCall();
                                            }
                                          },
                                          child: Text(
                                            "是",
                                            style: TextStyle(
                                                fontSize: 16,
                                                color: Theme.of(context)
                                                    .primaryColor),
                                          ),
                                        ),
                                        TextButton(
                                          onPressed: () =>
                                              Navigator.of(ctx).pop(),
                                          child: Text(
                                            "否",
                                            style: TextStyle(
                                                fontSize: 17,
                                                color: Theme.of(context)
                                                    .primaryColor),
                                          ),
                                        ),
                                      ],
                                    ));
                          })
                  ])));
            },
          );
        }
        return const HomeScreen();
      },
    );
  }
}

希望这些翻译对您有帮助。

英文:

After upgrading to Flutter 3.10, I built my android app using Flutter Sign In Screen. When I click the "Sign in with Google" button, a dialog is displayed for me to select my Google account. After selection, The sign in screen shows that an unknown error occurred. I have even upgraded the packages, but no change.“Flutter Sign In Screen, Sign in with Google shows ‘An unknown error occurred'”

Here is a section of main.dart:

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
/// The app uses Email and GoogleProvider to sign in.
FirebaseUIAuth.configureProviders([
EmailAuthProvider(),
GoogleProvider(
clientId:
&#39;CLIENT ID IS HERE&#39;),
// ... other providers can be added here if necessary
]);
/// This prevents the app from rotating to landscape mode.
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
.then((_) {
runApp(EasyDynamicThemeWidget(child: const MyApp()));
});
}

This is a section of my auth_gate.dart:

class _AuthGateState extends State&lt;AuthGate&gt; {
@override
Widget build(BuildContext context) {
return StreamBuilder&lt;User?&gt;(
stream: FirebaseAuth.instance.authStateChanges(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return SignInScreen(
headerBuilder: (context, constraints, _) {
return Image.asset(&quot;assets/qaizenlogo.png&quot;);
},
footerBuilder: (context, action) {
return Padding(
padding: const EdgeInsets.only(top: 40.0),
child: Text.rich(TextSpan(text: &#39;Need help? &#39;, children: [
TextSpan(
text: &#39;Call Us&#39;,
style: const TextStyle(
//color: Theme.of(context).primaryColor,
color: Colors.deepPurple,
fontSize: 16,
decoration: TextDecoration.underline,
fontStyle: FontStyle.italic,
fontWeight: FontWeight.bold,
),
recognizer: TapGestureRecognizer()
..onTap = () {
showDialog(
context: context,
builder: (ctx) =&gt; AlertDialog(
icon: const Icon(
Icons.phone_outlined,
color: Colors.blue,
),
title: const Text(&quot;Call Us&quot;),
content: const Text(
&quot;We&#39;re here to help with any questions or concerns you may have. Do you want to proceed with the call?&quot;,
style: TextStyle(fontSize: 18),
),
actions: &lt;Widget&gt;[
TextButton(
onPressed: () async {
Navigator.of(ctx).pop();
//call
//when call permission is granted:
await FlutterPhoneDirectCaller
.callNumber(&#39;PHONE NUMBER GOES HERE&#39;);
//else not granted, just show phone number
if (await Permission
.phone.isDenied) {
makePhoneCall();
}
},
child: Text(
&quot;Yes&quot;,
style: TextStyle(
fontSize: 16,
color: Theme.of(context)
.primaryColor),
),
),
TextButton(
onPressed: () =&gt;
Navigator.of(ctx).pop(),
child: Text(
&quot;No&quot;,
style: TextStyle(
fontSize: 17,
color: Theme.of(context)
.primaryColor),
),
),
],
));
})
])));
},
);
}
return const HomeScreen();
},
);
}
}

“Flutter Sign In Screen, Sign in with Google shows ‘An unknown error occurred'”

答案1

得分: 0

我找到了我的应用无法使用Google登录的原因。我没有将Google Play的应用签名密钥证书添加到Firebase中。

Google Play控制台 > [我的应用] > 设置 > 应用完整性 > 应用签名

英文:

I found what was the cause of my app not signing in with Google. I did not add Google Play's App signing key certificate to Firebase.

Google Play Console > [MyApp] > Setup > App integrity > App signing

huangapple
  • 本文由 发表于 2023年5月24日 21:17:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76323979.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定