gpt4 book ai didi

firebase - 方法 'sendEmailVerification' 没有为类型 'UserCredential' 定义。 Firebase flutter

转载 作者:行者123 更新时间:2023-12-03 03:14:01 30 4
gpt4 key购买 nike

我正在关注 this blog post在用户注册后向他们发送电子邮件验证,这是我在执行 sendEmailVerification()

时遇到的问题

The method 'sendEmailVerification' isn't defined for the type 'UserCredential'.Try correcting the name to the name of an existing method, or defining a method named 'sendEmailVerification

但是这篇博文的问题是,一些被使用的东西被弃用了,我设法解决了除了这个以外的大部分问题。

这是我的代码:-(您可以看到包名称的导入语句)

    import 'dart:async';

import 'package:firebase_auth/firebase_auth.dart' as auth;
import 'package:cloud_firestore/cloud_firestore.dart';

class Auth {
final auth.FirebaseAuth _firebaseAuth = auth.FirebaseAuth.instance;

Future<String> signUp(String email, String password) async {
try {
final user = await _firebaseAuth
.createUserWithEmailAndPassword(email: email, password: password);
try {
await user.sendEmailVerification(); // <== The error happens here
return user;
} catch (e) {
print('Code was not sent!');
}
} catch (e) {
print('An error occurred');
}
}
}

你能帮我解决这个问题吗?谢谢!

最佳答案

尝试以下操作:

await user.user.sendEmailVerification();

因为 createUserWithEmailAndPassword() 返回 UserCredential 的一个实例,并且因为类 UserCredential有一个名为 user 的属性,它返回 User 的实例。

因此您可以使用属性user 来调用方法sendEmailVerification()它在 User 类中。

关于firebase - 方法 'sendEmailVerification' 没有为类型 'UserCredential' 定义。 Firebase flutter ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64290926/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com