clearRow method

bool clearRow(
  1. int rowIndex
)

returns true if the contents are successfully cleared else false.

If the row is having any spanned-cells then it will not be cleared and hence returns false.

Implementation

bool clearRow(int rowIndex) {
  if (rowIndex < 0) {
    return false;
  }

  /// lets assume that this row is already cleared and is not inside spanList
  /// If this row exists then we check for the span condition
  bool isNotInside = true;

  if (_sheetData[rowIndex] != null && _sheetData[rowIndex]!.isNotEmpty) {
    /// lets start iterating the spanList and check that if the row is inside the spanList or not
    /// we will expect that value of isNotInside should not be changed to false
    /// If it changes to false then we can't clear this row as it is inside the spanned Cells
    for (int i = 0; i < _spanList.length; i++) {
      _Span? spanObj = _spanList[i];
      if (spanObj == null) {
        continue;
      }
      if (rowIndex >= spanObj.rowSpanStart &&
          rowIndex <= spanObj.rowSpanEnd) {
        isNotInside = false;
        break;
      }
    }

    /// As the row is not inside any SpanList so we can easily clear its content.
    if (isNotInside) {
      _sheetData[rowIndex]!.keys.toList().forEach((key) {
        /// Main concern here is to [clear the contents] and [not remove] the entire row or the cell block
        _sheetData[rowIndex]![key] = Data.newData(this, rowIndex, key);
      });
    }
  }
  //_countRowsAndColumns();
  return isNotInside;
}