apply method

SpanBuilder apply(
  1. InlineSpan span,
  2. {String whereText,
  3. int from,
  4. int to,
  5. dynamic onTap(
      ),
    1. RecognizerBuilder recognizerBuilder}
    )

    Implementation

    SpanBuilder apply(InlineSpan span,
        {String whereText,
        int from,
        int to,
        Function() onTap,
        RecognizerBuilder recognizerBuilder}) {
      /// turn any [onTap] into [RecognizerBuilder]
      if (onTap != null && recognizerBuilder == null) {
        recognizerBuilder = () => TapGestureRecognizer()..onTap = onTap;
      }
    
      /// convert [TextSpan] into [_ManagedTextSpan] with a [RecoginzerBuilder]
      if (span is TextSpan) {
        /// ignore: avoid_as
        span = (span as TextSpan).managed(recognizerBuilder);
      }
    
      /// if [whereText] is not provided then we try to figure it out:
      /// 1. from [from, to] range (if both params are passed)
      /// 2. from passed [TextSpan]
      /// 3. from lousy [from, to] range
      if (whereText == null) {
        if (from != null && to != null) {
          whereText = sourceText.substring(from, to);
        } else if (span is TextSpan) {
          whereText = span.text;
        } else {
          if (from == null && to == null) {
            return this;
          }
          whereText = sourceText.substring(from ?? 0, to ?? sourceText.length);
        }
      }
    
      /// if we pass whereText + from, we will try to do the search starting from that point
      /// therefor we need offset
      final offset = from ?? 0;
    
      final _sourceText =
          sourceText.substring(from ?? 0, to ?? sourceText.length);
    
      if (whereText != null) {
        from = _sourceText.indexOf(whereText);
        if (from == -1) {
          return this;
        }
        to = from + whereText.length;
      }
    
      /// finally we appen calculated SpanPosition
      return add(SpanEntity(start: offset + from, end: offset + to, span: span));
    }