首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Firebase网络问题?

Firebase网络问题?
EN

Stack Overflow用户
提问于 2019-08-12 02:56:28
回答 1查看 460关注 0票数 0

因此,我目前正在设计一个应用程序,并首先制作一个登录页面,到目前为止,我已经开始登录/注册用户,但是,每次我尝试登录时,我都会收到一个网络错误,我不知道这是代码还是谷歌,因为我正在使用谷歌身份验证服务。

我已经按照教程在我的pubspec和build中设置了firebase,但它似乎仍然不起作用。

代码语言:javascript
复制
    import 'package:flutter/material.dart';
    import 'package:firebase_auth/firebase_auth.dart';

    class LoginPage extends StatefulWidget {

      @override
      State<StatefulWidget> createState() => new _LoginPageState();
    }

    enum FormType {
      login,
      register
    }

    class _LoginPageState extends State<LoginPage> {

      final formKey = new GlobalKey<FormState>();

      String _email;
      String _password;
      FormType _formType = FormType.login;
      String _authHint = '';

      bool validateAndSave() {
        final form = formKey.currentState;
        if(form.validate()){
          form.save();
          return true;
        } else {
          return false;
        }
      }

      void validateAndSumbit() async {
      if (validateAndSave()) {
        try {
          if(_formType == FormType.login) {
      FirebaseUser user = (await FirebaseAuth.instance.signInWithEmailAndPassword(email: _email, password: _password)) as FirebaseUser;
      print('Signed in: ${user.uid}');
        } else {
          FirebaseUser user = (await FirebaseAuth.instance.createUserWithEmailAndPassword(email: _email, password: _password)) as FirebaseUser;
          print('Registered user: ${user.uid}');
          }
        }
        catch (e) {
          print('Error: $e');
        }
      }
    }

      void moveToRegister() {
        formKey.currentState.reset();
        setState(() {
          _formType = FormType.register;
        });
      }

      void moveToLogin() {
        setState(() {
          _formType = FormType.login;
        });
      }

        @override
        Widget build(BuildContext context) {
          return new Scaffold(
            appBar: new AppBar(
              title:  new Text('Car Parking App'),
            ),
            body: new Container(
              padding: EdgeInsets.all(16.0),
              child: new Form(
                key: formKey,
                child: new Column(
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: buildInputs() + buildSubmitButtons(),
                ),
              ),
            )
          );
        }

        List<Widget> buildInputs() {
          return [
        new TextFormField(
          decoration: new InputDecoration(labelText: 'Email'),
          validator: (value) => value.isEmpty ? 'Email can\'t be empty' : null,
          onSaved: (value) => _email = value,
          ),
        new TextFormField(
          decoration: new InputDecoration(labelText: 'Password'),
          obscureText: true,
          validator: (value) => value.isEmpty ? 'Password can\'t be empty' : null,
          onSaved: (value) => _password = value,
          ),
          ];
        }

        List<Widget> buildSubmitButtons() {
          if (_formType == FormType.login) {
          return [
                  new RaisedButton(
            child: new Text('Login', style: new TextStyle(fontSize: 20.0)),
            onPressed: validateAndSumbit,
          ),
          new FlatButton(
            child: new Text('Create an Account', style: new TextStyle(fontSize: 20.0)),
            onPressed: moveToRegister,
          )
          ];
        } else {
                return [
                  new RaisedButton(
            child: new Text('Create an Account', style: new TextStyle(fontSize: 20.0)),
            onPressed: validateAndSumbit,
          ),
          new FlatButton(
            child: new Text('Already have an account? Login', style: new TextStyle(fontSize: 20.0)),
            onPressed: moveToLogin,
          )
          ];
        }
        }
    }

V/音频管理器(27253):playSoundEffect effectType: 0V/音频管理器(27253):querySoundEffectsEnabled...W/BiChannelGoogleApi(27253):com.google.firebase.auth.api.internal.zzak@744c74e : getGoogleApiForMethod()返回的Gms: FirebaseAuth W/DynamiteModule(27253):找不到com.google.firebase.auth的本地模块描述符类。I/FirebaseAuth(27253):FirebaseAuth:通过FirebaseOptions加载模块。I/FirebaseAuth(27253):flutter:正在准备创建到gms实现的服务连接I/flutter (27253):Error: PlatformException(ERROR_NETWORK_REQUEST_FAILED,发生网络错误(例如超时、连接中断或主机无法访问)。,FirebaseAuth)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-12 21:16:18

修复了这个问题,与网站API密钥相比,google-services文件中的API密钥不同,一旦我更改了它,它就工作得很好。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57452734

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档