Function with Document list as return value

Resolved

Is it possible to have a custom function that outputs a list of documents? Flutterflow limits the editing of functions to only within the method, thus, adding classes outside it is unattainable. Without the classes it give off the error: The class StatisticsAttendanceRecord doesn't have an unnamed constructor. Try using one of the named constructors defined in 'StatisticsAttendanceRecord'

here's my code with this error:

List<StatisticsAttendanceRecord> statisticsAttendance(
    List<VoterRecord> voterlist) {
  /// MODIFY CODE ONLY BELOW THIS LINE

  Map<String, StatisticsAttendanceRecord> statisticsMap = {};

  // Calculate initial values for statisticsMap
  for (var voter in voterlist) {
    String voterbarangay = voter.voterbarangay;
    String affiliation = voter.affiliation;
    bool hasVoted = voter.hasVoted;

    if (!statisticsMap.containsKey(voterbarangay)) {
      statisticsMap[voterbarangay] = StatisticsAttendanceRecord( //error here
        barangayname: voterbarangay,
        membercount: 0,
        membercheckins: 0,
        votercount: 0,
      );
    }

    statisticsMap[voterbarangay]!.votercount++;

    if (affiliation == "Hugpong") {
      statisticsMap[voterbarangay]!.membercount++;
      if (hasVoted) {
        statisticsMap[voterbarangay]!.membercheckins++;
      }
    }
  }

  List<StatisticsAttendanceRecord> result = statisticsMap.values.toList();
  return result;

  /// MODIFY CODE ONLY ABOVE THIS LINE
}

2
6 replies