fetchReports method Null safety

Future<List<Report>> fetchReports(
  1. {required ReportGroup reportGroup,
  2. Cow? cow}
)

리포트 그룹에 따라 리포트 카드 리스트를 가져옵니다.

Implementation

Future<List<Report>> fetchReports({
  /// 가져올 리포트 그룹입니다.
  required ReportGroup reportGroup,

  /// 이 파라메터를 주게되면 해당 소의 리포트 카드만 가져오게 됩니다. 이력정보 화면에서 이 파라메터를 줍니다.
  Cow? cow,
}) async {
  LogManager().addLog("fetchReports", screen: runtimeType.toString());
  try {
    final List<dynamic> body = await reqGET(
      path: '/api/reports',
      queryParameters: {
        "farm_id": farmState.currentFarm!.id,
        "report_group": reportGroup.code,
        "cow_group_id": cowGroupState.currentCowGroup != null ? cowGroupState.currentCowGroup!.id.toString() : '',
        "cow_id": cow != null ? cow.id.toString() : '',
      },
    );
    final List<Report> reports = body.map((element) => Report.fromJson(element)).toList();
    return reports;
  } catch (e) {
    LogManager().addLog("fetchReports call failed: $e", screen: runtimeType.toString());
    return [];
  }
}