错误:无法将参数类型“Context”分配给参数类型“BuildContext”?

时间:2021-05-20 07:22:50

标签: flutter dart

    error: The argument type 'Context' can't be assigned to the parameter type 'BuildContext'? 

我试图将用户的登录 ID 从 loginWithEmailAndPasswords() 方法传递给 homecontroller 方法(下面的方法) 如何在没有构建上下文的情况下传递数据?我想将用户 ID 传递给第二个主控制器页面(我已经将第二个主控制器页面导入到第一页),image for my error

import '../../../homecontroller.dart';
    class service{
     Future loginWithEmailAndPasswords(String email, String password) async {
                try {
                  UserCredential register = await _firebaseAuth.signInWithEmailAndPassword(
                    Context context, email: email, password: password);
                  User registredUser = register.user;
            
                  if (await FirebaseFirestore.instance.collection('agent').doc(registredUser.uid) != null) {
                    Navigator.push(
                        context,
                        MaterialPageRoute(
                            builder: (context) =>
                                homecontroller(controllUserType: registredUser.uid)));
                  }
                  return registredUser.uid;
                } catch (e) {
                  print(e.toString());
                  return null;
                }
              }
        }


 

这是我的家庭控制器类,该类位于 第二页,我在第一页上导入

        class homecontroller extends StatelessWidget {
          final String controllUserType;
          const homecontroller({Key key,@required this.controllUserType}):super(key: key);
          @override
          Widget build(BuildContext context) {
            final Authservice auth=Provider.of(context).auth;
            return StreamBuilder(
                stream:auth.authStateChanges,
                  builder: (context,AsyncSnapshot<String>snapshot){
                  if(snapshot.connectionState==ConnectionState.active){
                    final bool SignedIn=snapshot.hasData;
                    return SignedIn?HomePage(UserType:controllUserType):Adresspage();
                  }else{
                    return CircularProgressIndicator();
                  }
        
                  },
            );
          }
        }

我已经在 loginWithEmailAndPasswords 方法(上述方法)中接受了 BuildContext 作为参数,并且我从您调用 loginWithEmailAndPasswords 的地方传递了“上下文”。我在下面的方法上传递了上下文,但仍然出现错误,错误:无法将参数类型“上下文”分配给参数类型“BuildContext”?

这是我将 Context 传递给 loginWithEmailAndPasswords 方法(以上方法)的方法

switch (authFormType) {
          case AuthFormType.SignIn:
         if(   await auth.loginWithEmailAndPasswords(_email, _password , context)!=null)
            {

              Navigator.of(context).pushReplacementNamed('/home');
              // Navigator.push(context,
              //     MaterialPageRoute(
              //         builder: (context)=>homecontroller(controllUserType:_dropDownValue)
              //     )
              // );
            }else{
           setState(() {
             _warrning = 'wrong email and password combinations';
           });
         }}

0 个答案:

没有答案