[英]FLutter FirebaseAuth Email verification
right now i try to code an own android App.现在我尝试编写自己的 android 应用程序。 therefore i wanted to create an e-mail and password based sign-in/ sign Up which also includes an E-mail Verification service.
因此我想创建一个基于电子邮件和密码的登录/注册,其中还包括一个电子邮件验证服务。 the problem is that, everytime i launch it in the Emulator, and try to register, it will just occure an nosuchmethod error that tells me that either the getter email or the getter sendEmailVerification() is called on null.
问题是,每次我在模拟器中启动它并尝试注册时,它都会发生一个 nosuchmethod 错误,告诉我在 null 上调用了 getter email 或 getter sendEmailVerification()。
pls have a look at my verification-code and tell me what i did wrong.请看看我的验证码并告诉我我做错了什么。
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'home.dart';
class Verification extends StatefulWidget {
@override
_VerificationState createState() => _VerificationState();
}
class _VerificationState extends State<Verification> {
final auth = FirebaseAuth.instance;
User user;
Timer timer;
String email = FirebaseAuth.instance.currentUser.email.toString();
Future<void> verificateEmail() async{
User user = auth.currentUser;
if (user != null) {
await user.sendEmailVerification();}
timer = Timer.periodic(Duration(seconds: 2), (timer) {checkEmailVerified(); });
}
@override
void dispose() {
timer.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text("draicksmail sent to ${user.email}"),
),
);
}
Future<void> checkEmailVerified() async{
user = auth.currentUser;
await user.reload();
if (user.emailVerified){
timer.cancel();
Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (context)=> Home()));
}
}
}
So this error is caused because auth.currentUser
returns null
.所以这个错误是因为
auth.currentUser
返回null
引起的。 Therefore trying to execute a method on null
throws an error because nothing exists on null
.因此,尝试在
null
上执行方法会引发错误,因为null
上不存在任何内容。
Have you added the following to your main()
method?您是否在
main()
方法中添加了以下内容?
await Firebase.initializeApp();
runApp(Home());
Checkout the following guide for more detailshttps://firebase.google.com/docs/flutter/setup?platform=android查看以下指南了解更多详细信息https://firebase.google.com/docs/flutter/setup?platform=android
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.