Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 我无法使用google_sign_登录在Flitter中登录我的google帐户_Flutter_Dart_Runtime Error_Google Signin - Fatal编程技术网

Flutter 我无法使用google_sign_登录在Flitter中登录我的google帐户

Flutter 我无法使用google_sign_登录在Flitter中登录我的google帐户,flutter,dart,runtime-error,google-signin,Flutter,Dart,Runtime Error,Google Signin,我在我的项目中使用了google\u-sign\u-in,包括.json文件,启用了firebase的google-sign-in方法,添加了sha1和sha256密钥,但我仍然无法登录我的帐户,有人能帮我吗,我是新手,不知道为什么会出现这种情况,错误是- Launching lib\main.dart on sdk gphone x86 arm in debug mode... Running Gradle task 'assembleDebug'... √ Built build\app\o

我在我的项目中使用了
google\u-sign\u-in
,包括
.json
文件,启用了firebase的google-sign-in方法,添加了
sha1
sha256
密钥,但我仍然无法登录我的帐户,有人能帮我吗,我是新手,不知道为什么会出现这种情况,错误是-

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();
  }
}
import'包装:flift/cupertino.dart';
进口“包装:颤振/材料.省道”;
导入“package:google_fonts/google_fonts.dart”;
导入“包:google_sign_in/google_sign_in.dart”;
最终谷歌签名谷歌签名=谷歌签名();
类Home扩展了StatefulWidget{
@凌驾
_HomeState createState()=>\u HomeState();
}
类(HomeState扩展状态){
bool-isAuth=false;
@凌驾
void initState(){
super.initState();
googleSignIn.onCurrentUserChanged.listen((帐户){
handleSignIn(账户);
},
onError:(错误){
打印(“登录时出错:$Error”);
});
googleSignIn.signalily(suppressErrors:false)。然后((帐户){
handleSignIn(账户);
}).catchError((错误){
打印(“登录时出错:$Error”);
});
}
handleSignIn(谷歌签名账户){
如果(帐户!=null){
打印(“登录用户:$account”);
设置状态(){
isAuth=true;
});
}
否则{
设置状态(){
isAuth=false;
});
}
}
登录(){
谷歌签名;
}
Widget buildAuthScreen(){
返回文本('Authenticated');
}
脚手架搭设安全网(){
返回脚手架(
背景颜色:Colors.black,
正文:安全区(
子:容器(
装饰:盒子装饰(
梯度:线性梯度(
开始:Alignment.topRight,
结束:对齐。左下角,
颜色:[
主题。背景。原色,
颜色。青色,不透明度(1.0),
颜色,橙色,
]
),
),
对齐:对齐.center,
子:列(
mainAxisAlignment:mainAxisAlignment.center,
crossAxisAlignment:crossAxisAlignment.center,
儿童:[
正文(
“Technua”,
样式:GoogleFonts.gochiHand(
字体大小:70.0,
颜色:颜色,白色,
),
),
手势检测器(
onTap:登录,
子:容器(
身高:60.0,
宽度:260.0,
装饰:盒子装饰(
图像:装饰图像(
图片:AssetImage('assets/images/google\u sign\u button.png'),
适合:BoxFit.cover,
)
),
),
),
],
),
),
),
);
}
@凌驾
小部件构建(构建上下文){
返回isAuth?buildAuthScreen():buildUnauthScreen();
}
}

您可以尝试以下步骤:

1-填写Google API控制台下OAuth同意屏幕上的所有字段

2-使用CTRL+F5而不是F5重新启动项目

这是一个相关的问题,也是对类似问题的高度投票