Browse Source

fix(report): 修正报告预览加载失败

gavin.chen 1 năm trước cách đây
mục cha
commit
4f670b7bf6
1 tập tin đã thay đổi với 16 bổ sung2 xóa
  1. 16 2
      lib/pdf_objects/report/pdf_rttable.dart

+ 16 - 2
lib/pdf_objects/report/pdf_rttable.dart

@@ -109,22 +109,36 @@ class PdfRTTable extends PdfElement {
     int column = pos.column ?? 0;
     int columnSpan = pos.columnSpan ?? 1;
     for (int i = column; i < column + columnSpan; i++) {
-      width += _rtTableInfo.columnDefinitions![i].width!;
+      width += _getWidthFromColumnDefinitions(i);
     }
     return width;
   }
 
+  double _getWidthFromColumnDefinitions(int columnIndex) {
+    if (columnIndex >= _rtTableInfo.columnDefinitions!.length) {
+      return _rtTableInfo.columnDefinitions!.last.width!;
+    }
+    return _rtTableInfo.columnDefinitions![columnIndex].width!;
+  }
+
   /// 获取单元格高度
   double _getCellHeight(CellPostion pos) {
     double height = 0;
     int row = pos.row ?? 0;
     int rowSpan = pos.rowSpan ?? 1;
     for (int i = row; i < row + rowSpan; i++) {
-      height += _rtTableInfo.rowDefinitions![i].height!;
+      height += _getHeightFromRowDefinitions(i);
     }
     return height;
   }
 
+  double _getHeightFromRowDefinitions(int rowIndex) {
+    if (rowIndex >= _rtTableInfo.rowDefinitions!.length) {
+      return _rtTableInfo.rowDefinitions!.last.height!;
+    }
+    return _rtTableInfo.rowDefinitions![rowIndex].height!;
+  }
+
   /// 合并单元格
   BaseGrid _mergeGrids(BaseGrid baseGrid, List<BaseGrid> gridsToMerge) {
     int row = baseGrid.row;