getter 'emailVerified' 被调用为 null。接收者:空

The getter 'emailVerified' was called on null. Receiver: null

为什么我会收到此错误:我在其他 类 中以完全相同的方式使用它,并且它在那种情况下有效,它会给出此错误:


======== Exception caught by widgets library =======================================================
The following NoSuchMethodError was thrown building Wrapper(dirty, dependencies: [_InheritedProviderScope<Userr>]):
The getter 'emailVerified' was called on null.
Receiver: null
Tried calling: emailVerified

The relevant error-causing widget was: 
  Wrapper file:///Users/name/StudioProjects/project/lib/main.dart:47:36
When the exception was thrown, this was the stack: 
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
#1      Wrapper.build (package:projectandroidstudiodenya/wrapper.dart:23:42)
#2      StatelessElement.build (package:flutter/src/widgets/framework.dart:4661:28)
#3      ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4587:15)
#4      Element.rebuild (package:flutter/src/widgets/framework.dart:4281:5)
...
====================================================================================================


This is my Wrapper class```
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:projectandroidstudiodenya/authenticate/resetpassword.dart';
import 'package:projectandroidstudiodenya/seitenleiste/homepage.dart';
import 'package:provider/provider.dart';
import 'authenticate/authenticate.dart';
import 'models/user.dart';



class Wrapper extends StatelessWidget {
  static const route='/Wrapper';


  @override
  Widget build(BuildContext context) {
    //Auth.auth().currentUser.isEmailVerified;
    //final user = Provider.of<UserCredential>(context);

    final user = Provider.of<Userr>(context);

    if(FirebaseAuth.instance.currentUser.emailVerified){
      return Homepage();
    }else if( FirebaseAuth.instance.currentUser != null) {
      return Authenticate();
    }else if(FirebaseAuth.instance.currentUser ==null){
      return Resedpasswort();
    }
    //return Home or Authenticate widget
  }
}

我尝试了 FirebaseAuth.instance.currentUser.emailVerified!=null 和 ==null。 同样的错误 请帮忙,而且 user.emailverfiyed 不工作。我认为我需要以这种方式使用它。所以正如我在其他 类 中所说的那样有效。

这里的问题是 currentUser 是 null 而不是 emailVerified

试试这个:

class Wrapper extends StatelessWidget {
  static const route='/Wrapper';


  @override
  Widget build(BuildContext context) {
    //Auth.auth().currentUser.isEmailVerified;
    //final user = Provider.of<UserCredential>(context);

    final user = Provider.of<User>(context);

    if( FirebaseAuth.instance.currentUser == null) {
      return Authenticate();
    else if(FirebaseAuth.instance.currentUser.emailVerified){
      return Homepage();
    }
    else if(FirebaseAuth.instance.currentUser != null){
      return ResetPassword();
    }
    else 
    //return Home or Authenticate widget
  }
}