【问题标题】:Firebase Authentication UserCredentialFirebase 身份验证用户凭据
【发布时间】:2021-12-19 05:08:03
【问题描述】:

UserCredential 不断显示消息:

未定义的类“UserCredential”。 尝试将名称更改为现有类的名称,或创建一个名为 'UserCredential'.dartundefined_class 的类

我导入:

import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_auth/firebase_auth.dart' ;
dependencies:
  flutter:
    sdk: flutter
  firebase_core: "^0.7.0"
  firebase_database: "^6.0.0"
  firebase_auth: ^3.1.5
  fluttertoast: ^8.0.8

这是main中的代码:

  await Firebase.initializeApp();
  try {
    UserCredential userCredential = await FirebaseAuth.instance.createUserWithEmailAndPassword(
    email: "barry.allen@example.com",
    password: "SuperSecretPassword!"
  );
} 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);
}

【问题讨论】:

  • 你在pubspec.yaml中做了Pub Get吗?
  • 是的,同样的问题
  • 真的很奇怪...是运行时错误还是被语法标记了?
  • 由语法标记
  • Crazy... 你确定import 'package:firebase_auth/firebase_auth.dart' ; 这一行在顶部的同一个文件中吗?

标签: flutter dart firebase-authentication


【解决方案1】:

问题: 在您的 dependencies: 中,您正在导入旧版本的 firebase_core,它仅适用于旧版本的 firebase_auth(非空安全)

  firebase_core: "^0.7.0"
  firebase_auth: "^0.20.1"

解决办法: 您需要更改为最新版本,如下所示:

  firebase_core: "^1.7.0"   //** CHANGE THIS LINE
  firebase_auth: "^3.1.3"

别忘了做pub get

更多详情here

【讨论】:

  • 基本上,您需要使用两个旧版本或两个新版本,但不能混合使用。希望它有效;0)
  • 它不起作用:(
  • Grrrr.... 其余的对我来说看起来不错。你能在你使用UserCredential的地方显示你所有的代码吗
  • 我认为您不能在致电runApp 之前尝试创建用户。 link你能把你的验证码移到Mudrek类的build里面吗?
  • 还是同样的问题
猜你喜欢
  • 2021-05-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多