【问题标题】:I/flutter (21647): NoSuchMethodError: Class 'User' has no instance getter 'password'I/flutter (21647): NoSuchMethodError: Class 'User' has no instance getter 'password'
【发布时间】:2021-03-02 07:05:24
【问题描述】:
//register.dart

    
    RaisedButton(onPressed:(){
  FirebaseAuth.instance.createUserWithEmailAndPassword(
      email: email, password: password
  ).then((signedInUser){
   UserManagement().storeNewUser(signedInUser.user, context);
  }).catchError((e){
    print(e);
  });
    } ,
    child: Text('Register'),
    ),



//usermanagement.dart

class UserManagement{
  storeNewUser(user , context){
    Firestore.instance.collection('/users').add({
      'email' : user.email,
      'password' : user.password,
    }).then((value) {
    Navigator.of(context).pop();
    Navigator.of(context).pushReplacementNamed('/menupage');
    }).catchError((e){
      print(e);
    });
  }
}

当我使用 signedInUser.user 时出现错误

I/flutter (21647): NoSuchMethodError: Class 'User' has no instance getter 'password'

I/flutter (21647):接收器:“用户”实例

I/flutter (21647):尝试调用:密码

当我使用 signedInUser 时出现以下错误

I/flutter (21647): NoSuchMethodError: Class 'UserCredential' 没有实例 getter 'email'。

I/flutter (21647):接收方:“UserCredential”实例

I/flutter (21647):尝试调用:电子邮件

有人请帮我解决这个问题

【问题讨论】:

    标签: firebase flutter dart google-cloud-firestore firebase-authentication


    【解决方案1】:

    //我刚刚删除了usermanagement.dart中的**'password' : user.password**这一行

    class UserManagement{
      storeNewUser(user , context){
        Firestore.instance.collection('/users').add({
          'email' : user.email,
        }).then((value) {
        Navigator.of(context).pop();
        Navigator.of(context).pushReplacementNamed('/menupage');
        }).catchError((e){
          print(e);
        });
      }
    }
    

    我刚刚删除了 'password' 行:user.password

    并在 register.dart 中使用了signedInUser.user 而不是只使用了signedInUser。

    【讨论】:

      【解决方案2】:

      错误信息:

      NoSuchMethodError: 类 'User' 没有实例 getter 'password'

      告诉你User 类没有名为密码的属性。实际上,Firebase Auth 并没有办法在创建帐户后获取用户的密码。这将是一个安全问题,并且没有“修复”或解决方法。

      作为最佳实践,您也不应该在数据库中存储密码,这是另一个安全问题。如果您确实必须存储密码,您应该在用户输入密码后仍然在内存中时执行此操作。但是您确实应该设计您的应用程序,而无需知道用户的密码。 Firebase 身份验证会为您安全地处理这一切,因此您不会意外犯安全错误。

      【讨论】:

      • 我真的很抱歉,但我是 firebase 的新手,所以你能告诉我我应该做什么,因为我现在真的很困惑。我可以在 firebase 的身份验证面板中看到我的用户但没有任何内容上传到数据库。
      • 我在答案中给出了我的建议。如果您有新问题,请单独发布。
      • 非常感谢!我刚刚使用了你推荐的东西,它对我有用。
      • 如果您觉得这个答案有帮助,习惯上使用答案左侧的按钮来支持并接受它是正确的。
      猜你喜欢
      • 2020-01-18
      • 1970-01-01
      • 1970-01-01
      • 2022-11-15
      • 2019-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多