fetchCows method Null safety

Future<List<Cow>?> fetchCows(
  1. {DateTime? targetAt}
)

소 목록을 가져옵니다. targetAt 값을 주게되면 해당 날짜에 발행된 리포트카드와 join시켜 소 상태(CowStatus)값(발행된 리포트 카드가 있으면)도 같이 가져옵니다. targetAt값이 없으면 모든 소 개체의 상태값은 null입니다.

Implementation

Future<List<Cow>?> fetchCows({
  DateTime? targetAt,
}) async {
  LogManager().addLog("fetchCows", screen: runtimeType.toString());
  try {
    final List<dynamic> body = await reqGET(
      path: '/api/cows',
      queryParameters: {
        "farm_id": farmState.currentFarm!.id,
        "target_at": DateFormat(StringConstants.timeYMDDashFormat).format(targetAt ?? DateTime.fromMillisecondsSinceEpoch(0)),
      },
    );
    final List<Cow> cows = body.map((element) => Cow.fromJson(element)).toList();
    cowState.cows = cows;
    return cows;
  } catch (e) {
    LogManager().addLog('fetchCows call failed: $e', screen: runtimeType.toString());
    return null;
  }
}