簡體   English   中英

無法從 Flutter 注冊 FireBase 用戶

[英]Cant register FireBase user from Flutter

我無法從我用 Flutter 編寫的應用程序注冊用戶。我也無法獲取錯誤消息的某種形式。 我可以調試並看到我的 createUser function 被調用並且 arguments 看起來不錯。 在我調用“FirebaseAuth.instance.createUserWithEmailAndPassword”后沒有任何反應。 沒有異常,FireBase 模擬器控制台中沒有打印任何內容。 我在這里錯過了什么? 這是我得到的:

Emulator:
Running on 127.0.0.1:9099

主要.dart:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform,);

  try {
    await FirebaseAuth.instance.useAuthEmulator('localhost', 9099);
  } catch (e) {
    // ignore: avoid_print
    print(e);
  }

  runApp(
    MaterialApp(
      title: "Foo",
      home: buildContent(),
    ),
  );
}

報名function:

void createUser() async {
    print("createUser()");
    try {
      final credential = await FirebaseAuth.instance.createUserWithEmailAndPassword(
        email: nameController.text,
        password: passwordController.text,
      );
      //final credential = await FirebaseAuth.instance.createUserWithEmailAndPassword(email: nameController.text, password: passwordController.text);
    } on FirebaseAuthException catch (e) {
      if (e.code == 'weak-password') {
        print('The password provided is too weak.');
      } else if (e.code == 'email-already-in-use') {
        print('The account already exists for that email.');
      }
    } catch (e) {
      print(e);
    }
  }

編輯:當我調用“createUserWithEmailAndPassword”時,我不斷收到此消息

W/System (26859):忽略 header X-Firebase-Locale,因為它的值為 null。

在您的createUser() Function 中,我認為您正在向 firebase 發送空值

像這樣請求參數並重試

void createUser(String name, String Password) async {
    print("createUser()");
    try {
      final credential = await FirebaseAuth.instance.createUserWithEmailAndPassword(
        email: name,
        password: password,
      );
print("User Created Success);
      //final credential = await FirebaseAuth.instance.createUserWithEmailAndPassword(email: nameController.text, password: passwordController.text);
    } on FirebaseAuthException catch (e) {
      if (e.code == 'weak-password') {
        print('The password provided is too weak.');
      } else if (e.code == 'email-already-in-use') {
        print('The account already exists for that email.');
      }
    } catch (e) {
      print(e);
    }
  }

因此,在經過一些嘗試和錯誤之后,我最終添加了:

android:usesCleartextTraffic="true"

清單文件:...\my_project\android\app\src\main\AndroidManifest.xml

我不確定我是否喜歡“修復”,因為我認為請求是未加密發送的。 谷歌搜索給了我這個描述:

Android 6.0 introduced the useCleartextTraffic attribute under application element in android manifest. The default value in Android P is “false”. Setting this to true indicates that the app intends to use clear network traffic

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM