findMonthPolygon method

List<Offset> findMonthPolygon(
  1. int year,
  2. int month
)

给定在制定月份的边缘 相关数据必须在给定的范围以内

Implementation

List<Offset> findMonthPolygon(int year, int month) {
  DateTime? startDate = findMinDate(year, month);
  DateTime? endDate = findMaxDate(year, month);
  if (endDate == null || startDate == null) {
    throw FlutterError('在给定的年月中无法找到对应数据');
  }

  CalendarNode startNode = _nodeMap[startDate]!;
  CalendarNode endNode = _nodeMap[endDate]!;

  List<Offset> offsetList = [];
  if (props.direction == Direction.vertical) {
    offsetList.add(startNode.rect.topLeft);
    offsetList.add(startNode.rect.topRight);
    if (startNode.column != _columnCount - 1) {
      Offset offset = startNode.rect.topRight;
      offset = offset.translate(_cellWidth * (_columnCount - startNode.column - 1), 0);
      offsetList.add(offset);
    }
    offsetList.add(Offset(offsetList.last.dx, endNode.rect.topRight.dy));
    offsetList.add(endNode.rect.topLeft);
    offsetList.add(endNode.rect.bottomLeft);
    if (endNode.column != 0) {
      Offset offset = endNode.rect.bottomLeft;
      offset = offset.translate(-_cellWidth * endNode.column, 0);
      offsetList.add(offset);
    }
    offsetList.add(Offset(offsetList.last.dx, startNode.rect.bottomLeft.dy));
  } else {
    offsetList.add(startNode.rect.topLeft);
    offsetList.add(startNode.rect.topRight);
    if (startNode.row != 0) {
      Offset offset = startNode.rect.topRight;
      offset = offset.translate(0, _cellHeight * startNode.row);
      offsetList.add(offset);
    }
    offsetList.add(Offset(endNode.rect.topRight.dx, offsetList.last.dy));
    offsetList.add(endNode.rect.bottomRight);
    if (endNode.row != _rowCount - 1) {
      offsetList.add(endNode.rect.bottomLeft);
      offsetList.add(Offset(offsetList.last.dx, endNode.rect.bottom + (_columnCount - endNode.column) * _cellHeight));
    }
    offsetList.add(Offset(startNode.rect.bottomLeft.dx, offsetList.last.dy));
  }
  return offsetList;
}