Flutter 使用Flatter从firestore获取数据时出错

Flutter 使用Flatter从firestore获取数据时出错,flutter,dart,google-cloud-firestore,widget,Flutter,Dart,Google Cloud Firestore,Widget,已经尝试了几乎所有的解决方案从堆栈溢出 我能够在firestore中写入数据,但在实现fetch功能后,我无法获取我上传的数据 我希望做的是: 我已经在firestore中上传了表单用户输入数据,并希望从firestore中获取这些数据 如果需要,您可以找到指向整个代码的链接 这里是错误: Closure call with mismatched arguments: function 'data' Receiver: Closure: () => Map<String, dynam

已经尝试了几乎所有的解决方案从堆栈溢出 我能够在firestore中写入数据,但在实现fetch功能后,我无法获取我上传的数据

我希望做的是: 我已经在firestore中上传了表单用户输入数据,并希望从firestore中获取这些数据

如果需要,您可以找到指向整个代码的链接

这里是错误:

Closure call with mismatched arguments: function 'data'
Receiver: Closure: () => Map<String, dynamic> from Function 'data':.
Tried calling: data
Found: data() => Map<String, dynamic>
Future getData() async {
    List itemsList = [];
    final CollectionReference profileList =
        FirebaseFirestore.instance.collection('Ride Now Details');
    try {
      await profileList.get().then((querySnapshot) {
        querySnapshot.docs.forEach((element) {
          itemsList.add(element.data);
        });
      });
      return itemsList;
    } catch (e) {
      print(e.toString());
      return null;
    }
  }
下面是获取数据的方法:

Closure call with mismatched arguments: function 'data'
Receiver: Closure: () => Map<String, dynamic> from Function 'data':.
Tried calling: data
Found: data() => Map<String, dynamic>
Future getData() async {
    List itemsList = [];
    final CollectionReference profileList =
        FirebaseFirestore.instance.collection('Ride Now Details');
    try {
      await profileList.get().then((querySnapshot) {
        querySnapshot.docs.forEach((element) {
          itemsList.add(element.data);
        });
      });
      return itemsList;
    } catch (e) {
      print(e.toString());
      return null;
    }
  }

如果您有更好的方法获取数据,请帮助我解决此问题,并帮助我解决此错误。

数据
是一种方法,而不是属性。所以你必须像调用方法一样调用它

itemsList.add(element.data());

从中可以看到,它返回一个
Map
,其中包含中的字段和值。

您是否可以在上述代码中突出显示相同的内容,因为我执行的是get操作,而不是add操作,而且对它来说也是新手。对不起,我不明白您在问什么。如果你有一个新问题,请单独发布。为了得到想要的结果,我到底应该修改什么?就是这样。仔细看我提供的代码行。我将data()作为带括号的方法调用。