parseDescription method
Implementation
List<InlineSpan> parseDescription(String text, BuildContext context) {
List<TextSpan> children = [];
final TextStyle regularTextStyle = Theme.of(context).textTheme.bodyMedium!;
final TextStyle boldTextStyle =
regularTextStyle.copyWith(fontWeight: FontWeight.bold);
final RegExp exp = RegExp('[**][wW]*[**]');
final List<Match> matches = exp.allMatches(text).toList();
int cursorPosition = 0;
for (int i = 0; i < matches.length - 1; i += 2) {
final Match left = matches[i];
final Match right = matches[i + 1];
final List<TextSpan> textBefore = findURLs(
text.substring(cursorPosition, left.start),
context,
regularTextStyle,
);
children = [...children, ...textBefore];
children.add(
TextSpan(
text: text.substring(left.end, right.start),
style: boldTextStyle,
),
);
cursorPosition = right.end;
}
final List<TextSpan> textAfter = findURLs(
text.substring(cursorPosition, text.length),
context,
regularTextStyle,
);
return [...children, ...textAfter];
}