简体   繁体   English

如何从flutter中的firebase取回email的ID?

[英]How to retrieve the email ID from firebase in flutter?

My login page我的登录页面

class _MyLoginState extends State<MyLogin> {

  final FirebaseAuth _auth = FirebaseAuth.instance;

  //editing controller
  final TextEditingController emailController = TextEditingController();
  final TextEditingController passwordController = TextEditingController();
  int _success = 1 ;
  late String _userEmail = "";

  void _signIn() async {
    final User? user = (await _auth.signInWithEmailAndPassword(
        email: emailController.text, password: passwordController.text)
    ).user;

    if (user != null) {
      setState(() {
        _success = 2;
        _userEmail = user.email!;
      });
    }else {
      setState(() {
        _success = 3;
      });
    }
  }

My profile screen for a user我的用户个人资料屏幕

class _UserAccState extends State<UserAcc> {


  final _auth = FirebaseAuth.instance;
  late String userEmail;
  void getCurrentUserEmail() async {
    final user =
    _auth.currentUser().then((value) => userEmail = value.email);
  }

  late final TextEditingController emailController;

The code in UserAcc that i have posted, will it retrieve the email id from firebase?我发布的 UserAcc 中的代码是否会从 firebase 检索 email id? If not, tell me how to do it.如果没有,请告诉我该怎么做。 I'm a beginner at flutter. I'm very much confused.我是flutter的初学者。我很困惑。

This is very close to being correct, but to get the Email, you must use a function which actually returns a value (String in this case).这非常接近正确,但要获得 Email,您必须使用 function,它实际上返回一个值(在本例中为 String)。

Right now you are setting the 'user' variable to the email, but it has not been returned.现在您将“用户”变量设置为 email,但尚未返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM