removeRegion method

AttributedText removeRegion({
  1. required int startOffset,
  2. required int endOffset,
})

Copies this AttributedText and removes a region of text and attributions from startOffset, inclusive, to endOffset, exclusive.

Implementation

AttributedText removeRegion({
  required int startOffset,
  required int endOffset,
}) {
  _log.fine('Removing text region from $startOffset to $endOffset');
  _log.fine('initial attributions:');
  _log.fine(spans.toString());
  final reducedText = (startOffset > 0 ? text.substring(0, startOffset) : '') +
      (endOffset < text.length ? text.substring(endOffset) : '');

  AttributedSpans contractedAttributions = spans.copy()
    ..contractAttributions(
      startOffset: startOffset,
      count: endOffset - startOffset,
    );
  _log.fine('reduced text length: ${reducedText.length}');
  _log.fine('remaining attributions:');
  _log.fine(contractedAttributions.toString());

  return AttributedText(
    reducedText,
    contractedAttributions,
  );
}