英文:
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.
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:
'CLIENT ID IS HERE'),
// ... 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<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: 'Need help? ', children: [
TextSpan(
text: 'Call Us',
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("Call Us"),
content: const Text(
"We're here to help with any questions or concerns you may have. Do you want to proceed with the call?",
style: TextStyle(fontSize: 18),
),
actions: <Widget>[
TextButton(
onPressed: () async {
Navigator.of(ctx).pop();
//call
//when call permission is granted:
await FlutterPhoneDirectCaller
.callNumber('PHONE NUMBER GOES HERE');
//else not granted, just show phone number
if (await Permission
.phone.isDenied) {
makePhoneCall();
}
},
child: Text(
"Yes",
style: TextStyle(
fontSize: 16,
color: Theme.of(context)
.primaryColor),
),
),
TextButton(
onPressed: () =>
Navigator.of(ctx).pop(),
child: Text(
"No",
style: TextStyle(
fontSize: 17,
color: Theme.of(context)
.primaryColor),
),
),
],
));
})
])));
},
);
}
return const HomeScreen();
},
);
}
}
答案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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论