来自函数‘数据’:。”,typescript,flutter,function,dart,cloud"/>

首页 > 解决方案 > 从云函数“Closure: () => Map”调用数据时出现问题来自函数‘数据’:。”

问题描述

我正在尝试从云函数中检索数据“classCode”,但每次我得到运行时错误,即 Closure: () => Map<String, dynamic> from Function 'data':。 下面是我的代码:

  Future checkDetails({
    @required String classCode,
    @required String email,
    @required String password,
    @required UserType userType,
  }) async {
    await sharedPreferencesHelper.clearAllData();
    //Check if the School code is present and return "School not Present" if not
    //Then check if the user credentials are in the database or not
    //if not then return "Student Not Found" else return "Logging in"

    //Api Call to check details
    bool isClassPresent = false;
    bool isUserAvailable = false;
    String loginType = userType == UserType.STUDENT
        ? "Student"
        : userType == UserType.TEACHER ? "Parent-Teacher" : "Parent-Teacher";

    DocumentReference _classLoginRef =
        classRef.collection(classCode.toUpperCase().trim()).doc('Login');
  await _classLoginRef
        .get().then((onValue) {
      isClassPresent = onValue.exists;
      print("Inside Then :" + onValue.data.toString());
    });

    if (!isClassPresent) {
      print('Class Not Found');
      return ReturnType.CLASSCODEERROR;
    } else {
      print('Class Found');
    }

    CollectionReference _userRef = _classLoginRef.collection(loginType);

注意:我使用的是 Typescript,我是 Flutter 的初学者。

标签: typescriptflutterfunctiondartcloud

解决方案


您会像下面这样更改并重试吗?

...
print("Inside Then :" + onValue.data.toString());
...

...
print("Inside Then :" + onValue.data().toString());
...

推荐阅读