使用signInWithEmailAndPassword时出现Flutter内部错误

问题描述 投票:0回答:1

我正在尝试使用 flutter 和 firebase 创建登录表单。我在使用

signInWithEmailAndPassword
函数时遇到以下错误:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [firebase_auth/internal-error] An internal error has occurred, print and inspect the error details for more information.

代码:

body: Column(children: [
          TextField(
            controller: _email,
            keyboardType: TextInputType.emailAddress,
            enableSuggestions: false,
            autocorrect: false,
            decoration: const InputDecoration(
              border: OutlineInputBorder(), hintText: "Email"),
          ),
          TextField(
            controller: _password,
            obscureText: true,
            enableSuggestions: false,
            autocorrect: false,
            decoration: const InputDecoration(
              border: OutlineInputBorder(), hintText: "Password"),
          ),
          TextButton(
            onPressed: () async {
              final email = _email.text;
              final password = _password.text;
              await Firebase.initializeApp(
                options: DefaultFirebaseOptions.currentPlatform,
              );
              final userCredential = 
                await FirebaseAuth.instance.createUserWithEmailAndPassword(
                  email: email, password: password
                );
              print(userCredential);
            },
            child: const Text("Register"),
          )
        ])

我尝试从 Google Cloud Console 取消限制我的 API 密钥,但这不起作用。我用的是IOS模拟器。我该如何解决这个问题?预先感谢。

flutter firebase dart google-cloud-console
1个回答
0
投票

尝试捕获您收到的错误并打印它!然后您可能会获得更多信息。也许您的输入不正确。

试试这个:

try {
  await FirebaseAuth.instance.signInWithEmailAndPassword(
    email: "[email protected]",
    password: "SuperSecretPassword!"
  );
} on FirebaseAuthException catch  (e) {
  print('Failed with error code: ${e.code}');
  print(e.message);
}

https://firebase.google.com/docs/auth/flutter/errors

© www.soinside.com 2019 - 2024. All rights reserved.