Implementation
Future<void> loadMoreGraphData({
required String action,
}) async {
if (action == "start") {
List<CowData>? cowData = await ApiService().fetchCowData(queryParameters: {
"cow_ids": '["${report.cow?.id}"]',
"start_at": DateFormat(StringConstants.timeYMDDashFormat).format(currentStartAt.subtract(Duration(days: _selectedGraphViewType.subDays + 1))),
"end_at": DateFormat(StringConstants.timeYMDDashFormat).format(currentStartAt.subtract(Duration(days: 1))),
"hour_unit": _selectedGraphViewType.hourUnit.toString(),
});
currentStartAt = currentStartAt.subtract(Duration(days: _selectedGraphViewType.subDays + 1));
List<BarDataDay> moreBarItemsDay = Helper().convertCowDataToGraphData(
cowData: cowData,
targetDateTime: selectedDateTime,
continuedDays: report.continuedDays == null ? 0 : report.continuedDays!,
graphViewType: _selectedGraphViewType,
actionType: selectedAction,
);
barItemsDay?.insertAll(0, moreBarItemsDay);
} else if (action == "end") {
List<CowData>? cowData = await ApiService().fetchCowData(queryParameters: {
"cow_ids": '["${report.cow?.id}"]',
"start_at": DateFormat(StringConstants.timeYMDDashFormat).format(currentEndAt.add(Duration(days: 1))),
"end_at": DateFormat(StringConstants.timeYMDDashFormat).format(currentEndAt.add(Duration(days: _selectedGraphViewType.subDays + 1))),
"hour_unit": _selectedGraphViewType.hourUnit.toString(),
});
currentEndAt = currentEndAt.add(Duration(days: _selectedGraphViewType.subDays + 1));
List<BarDataDay> moreBarItemsDay = Helper().convertCowDataToGraphData(
cowData: cowData,
targetDateTime: selectedDateTime,
continuedDays: report.continuedDays == null ? 0 : report.continuedDays!,
graphViewType: _selectedGraphViewType,
actionType: selectedAction,
);
barItemsDay?.addAll(moreBarItemsDay);
}
}