getAttributionSpansInRange method

Set<AttributionSpan> getAttributionSpansInRange({
  1. required AttributionFilter attributionFilter,
  2. required int start,
  3. required int end,
  4. bool resizeSpansToFitInRange = false,
})

Returns spans for each attribution that (at least partially) appear between start and end, inclusive, as selected by attributionFilter.

By default, the returned spans represent the full, contiguous span of each attribution. This means that if a portion of an attribution appears between start and end, the entire attribution span is returned, including the area that sits before start, or after end.

To obtain attribution spans that are cut down and limited to the given start/end range, pass true for resizeSpansToFitInRange. This setting only effects the returned spans, it does not alter the attributions within this AttributedSpans.

Implementation

Set<AttributionSpan> getAttributionSpansInRange({
  required AttributionFilter attributionFilter,
  required int start,
  required int end,
  bool resizeSpansToFitInRange = false,
}) {
  final matchingAttributionSpans = <AttributionSpan>{};

  // For every unit in the given range...
  for (int i = start; i <= end; ++i) {
    final attributionsAtOffset = getAllAttributionsAt(i);
    // For every attribution overlaps this unit...
    for (final attribution in attributionsAtOffset) {
      // If the caller wants this attribution...
      if (attributionFilter(attribution)) {
        // Calculate the span for this attribution.
        AttributionSpan span = expandAttributionToSpan(
          attribution: attribution,
          offset: i,
        );

        // If desired, resize the span to fit within the range.
        if (resizeSpansToFitInRange) {
          span = span.constrain(start: start, end: end);
        }

        // Add the span to the set. Duplicate are automatically ignored.
        matchingAttributionSpans.add(span);
      }
    }
  }

  return matchingAttributionSpans;
}