getTextSpan method

TextSpan getTextSpan({
  1. required RegExpMatch regex,
  2. required MarkerText marker,
  3. int? index,
})

Implementation

TextSpan getTextSpan(
    {required RegExpMatch regex, required MarkerText marker, int? index}) {
  return TextSpan(
      text: regex.group(0)!.replaceAll(marker.marker, ''),
      style: marker.style,
      recognizer: _typeWithTap.contains(marker.type)
          ? (TapGestureRecognizer()
            ..onTap = () async {
              final onError = marker.onError;

              switch (marker.type) {
                case MarkerType.function:
                  try {
                    await marker.functions![index!]();
                  } catch (msg) {
                    if (onError != null) {
                      onError(index ?? 0, msg);
                    }
                  }
                  break;

                case MarkerType.sameFunction:
                  try {
                    await marker.functions![0]();
                  } catch (msg) {
                    if (onError != null) {
                      onError(0, msg);
                    }
                  }
                  break;

                case MarkerType.url:
                  try {
                    if (await canLaunch(marker.urls![index!])) {
                      launch(marker.urls![index]);
                    } else {
                      throw 'cant launch';
                    }
                  } catch (msg) {
                    if (onError != null) {
                      onError(index ?? 0, msg);
                    }
                  }
                  break;

                default:
                  break;
              }
            })
          : null);
}