简体   繁体   English

不匹配 arguments 的闭包调用:function '[]' (Flutter/Dart)

[英]Closure call with mismatched arguments: function '[]' (Flutter/Dart)

Im quite new to flutter and I'm having an issue trying to create an application that has two users, namely Patients and Physiotherapists.我对 flutter 很陌生,我在尝试创建一个有两个用户(即患者和物理治疗师)的应用程序时遇到了问题。 Depending on the type of user, it will navigate to the PatientHome() or PhysioHome().根据用户的类型,它将导航到 PatientHome() 或 PhysioHome()。

I have tried creating a new field userType for every user in firestore, but I'm having trouble pulling the userType data and creating a logic that helps me navigate to either screens: Particularly, this widget Wrapper() is supposed to help me check if the userType is Patient or Physiotherapist and navigate accordingly.我已经尝试为 firestore 中的每个用户创建一个新字段 userType,但我无法提取 userType 数据并创建一个帮助我导航到任一屏幕的逻辑:特别是,这个小部件 Wrapper() 应该帮助我检查是否userType 是 Patient 或 Physiotherapy 并进行相应导航。

However, it's returning me a "flutter: NoSuchMethodError: Closure call with mismatched arguments: function '[]' Receiver: Closure: () => Map<String, dynamic>? from Function 'data':. Tried calling: " error. However, it's returning me a "flutter: NoSuchMethodError: Closure call with mismatched arguments: function '[]' Receiver: Closure: () => Map<String, dynamic>? from Function 'data':. Tried calling: " error.

My wrapper class is as follows:我的包装 class 如下:

class Wrapper extends StatelessWidget {

  Future<String?> getUserType(String uid) async {

    try {
      DocumentSnapshot _docSnapShot = await FirebaseFirestore.instance.collection('users').doc(uid).get();
      var userType = (_docSnapShot.data as dynamic)['userType'];
      return userType;
    } catch (e) {
      print(e);
    }
  }

  @override
  Widget build(BuildContext context) {
    final inputuser = Provider.of<CustomUser?>(context);

    //return either Home or Authenticate widget
    if ( inputuser == null) {
      return Authenticate();
    } else if (getUserType(inputuser.uid) == "Patient") {
      return PatientHome();
    } else {
      return PhysioHome();
    }
  }

Thank you in advance for your help!预先感谢您的帮助!

Im quite new to flutter and I'm having an issue trying to create an application that has two users, namely Patients and Physiotherapists.我对 flutter 很陌生,我在尝试创建一个有两个用户(即患者和物理治疗师)的应用程序时遇到了问题。 Depending on the type of user, it will navigate to the PatientHome() or PhysioHome().根据用户的类型,它将导航到 PatientHome() 或 PhysioHome()。

I have tried creating a new field userType for every user in firestore, but I'm having trouble pulling the userType data and creating a logic that helps me navigate to either screens: Particularly, this widget Wrapper() is supposed to help me check if the userType is Patient or Physiotherapist and navigate accordingly.我已经尝试为 firestore 中的每个用户创建一个新字段 userType,但我无法提取 userType 数据并创建一个帮助我导航到任一屏幕的逻辑:特别是,这个小部件 Wrapper() 应该帮助我检查是否userType 是 Patient 或 Physiotherapy 并进行相应导航。

However, it's returning me a "flutter: NoSuchMethodError: Closure call with mismatched arguments: function '[]' Receiver: Closure: () => Map<String, dynamic>? from Function 'data':. Tried calling: " error. However, it's returning me a "flutter: NoSuchMethodError: Closure call with mismatched arguments: function '[]' Receiver: Closure: () => Map<String, dynamic>? from Function 'data':. Tried calling: " error.

My wrapper class is as follows:我的包装 class 如下:

class Wrapper extends StatelessWidget {

  Future<String?> getUserType(String uid) async {

    try {
      DocumentSnapshot _docSnapShot = await FirebaseFirestore.instance.collection('users').doc(uid).get();
      var userType = (_docSnapShot.data as dynamic)['userType'];
      return userType;
    } catch (e) {
      print(e);
    }
  }

  @override
  Widget build(BuildContext context) {
    final inputuser = Provider.of<CustomUser?>(context);

    //return either Home or Authenticate widget
    if ( inputuser == null) {
      return Authenticate();
    } else if (getUserType(inputuser.uid) == "Patient") {
      return PatientHome();
    } else {
      return PhysioHome();
    }
  }

Thank you in advance for your help!预先感谢您的帮助!

暂无
暂无

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

相关问题 闭包调用与不匹配的 arguments:flutter 中的 function '[]' - Closure call with mismatched arguments: function '[]' in flutter Flutter:闭包调用不匹配 arguments:function - Flutter : Closure call with mismatched arguments: function 参数不匹配的闭包调用:函数“[]” - Closure call with mismatched arguments: function '[]' 参数不匹配的关闭调用:函数“[]”错误显示在颤振中 - Closure call with mismatched arguments: function '[]' error is being shown in flutter Flutter 错误 - “参数不匹配的闭包调用:函数 &#39;[]&#39; 接收器:闭包:() =&gt; Map<String, dynamic> 来自函数‘数据’:” - Flutter Error - "Closure call with mismatched arguments: function '[]' Receiver: Closure: () => Map<String, dynamic> from Function 'data':" NoSuchMethodError: 关闭调用不匹配 arguments: function 'LoginScreen.build.<anonymous closure> ' flutter</anonymous> - NoSuchMethodError: Closure call with mismatched arguments: function 'LoginScreen.build.<anonymous closure>' flutter 参数不匹配的关闭调用:函数“LoginScreen.build”。<anonymous closure> &#39; - Closure call with mismatched arguments: function 'LoginScreen.build.<anonymous closure>' 参数不匹配的关闭调用:函数“LoginScreen.build”。<anonymous closure> - Closure call with mismatched arguments: function 'LoginScreen.build.<anonymous closure> 参数不匹配的关闭调用:函数&#39;_MyAppState.build。<anonymous closure> &#39; - Closure call with mismatched arguments: function '_MyAppState.build.<anonymous closure>' 不匹配的关闭调用 arguments: function '_TasksListState.build.<anonymous closure> .<anonymous closure> ' 接收器:闭包:(bool) => Null</anonymous></anonymous> - Closure call with mismatched arguments: function '_TasksListState.build.<anonymous closure>.<anonymous closure>' Receiver: Closure: (bool) => Null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM