[英]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.