gpt4 book ai didi

flutter - 我无法使用 google_sign_in 在 Flutter 中登录我的 Google 帐户

转载 作者:行者123 更新时间:2023-12-03 02:59:05 33 4
gpt4 key购买 nike

我用了google_sign_in在我的项目中,包括 .json文件,从 firebase 启用 google 登录方法,添加 sha1sha256 key ,我仍然无法登录我的帐户,谁能帮助我,我是新手,不知道为什么会出现,错误是 -

Launching lib\main.dart on sdk gphone x86 arm in debug mode...
Running Gradle task 'assembleDebug'...
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Installing build\app\outputs\flutter-apk\app.apk...
Waiting for sdk gphone x86 arm to report its views...
Debug service listening on ws://127.0.0.1:65344/pDLKVFAejJU=/ws
Syncing files to device sdk gphone x86 arm...
I/flutter (13131): Error in signing in : PlatformException(sign_in_required, com.google.android.gms.common.api.ApiException: 4: 4: , null, null)
这是我的代码 -
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:google_sign_in/google_sign_in.dart';

final GoogleSignIn googleSignIn = GoogleSignIn();

class Home extends StatefulWidget {
@override
_HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
bool isAuth = false;

@override
void initState(){
super.initState();
googleSignIn.onCurrentUserChanged.listen((account) {
handleSignIn(account);
},
onError: (error) {
print("Error in signing in : $error");
});
googleSignIn.signInSilently(suppressErrors: false).then((account){
handleSignIn(account);
}).catchError((error){
print("Error in signing in : $error");
});
}

handleSignIn(GoogleSignInAccount account) {
if (account != null) {
print('The signed in user : $account');
setState(() {
isAuth = true;
});
}
else {
setState(() {
isAuth = false;
});
}
}

login() {
googleSignIn.signIn();
}

Widget buildAuthScreen(){
return Text('Authenticated');
}

Scaffold buildUnauthScreen() {
return Scaffold(
backgroundColor: Colors.black,
body: SafeArea(
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomLeft,
colors: [
Theme.of(context).primaryColor,
Colors.teal.withOpacity(1.0),
Colors.orange,
]
),
),
alignment: Alignment.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
'Technua',
style: GoogleFonts.gochiHand(
fontSize: 70.0,
color: Colors.white,
),
),
GestureDetector(
onTap: login,
child: Container(
height: 60.0,
width: 260.0,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/google_signin_button.png'),
fit: BoxFit.cover,
)
),
),
),
],
),
),
),
);
}

@override
Widget build(BuildContext context) {
return isAuth ? buildAuthScreen() : buildUnauthScreen();
}
}

最佳答案

您可以尝试以下步骤:
1 - 填写 Google API 控制台下 OAuth 同意屏幕上的所有字段。
2 - 使用 CTRL+F5 而不是 F5 重新启动您的项目。
这是 Github 上的相关问题,以及高票数 solution在一个类似的问题上。

关于flutter - 我无法使用 google_sign_in 在 Flutter 中登录我的 Google 帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64440128/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com