replaceVariables static method

String replaceVariables(
  1. String text, {
  2. List<RichTextPlaceholder> placeholders = const [],
  3. String placeholderMarker = "\\\$",
})

substitutes the variables occuring in text with their respective values stored in placeholders

Implementation

static String replaceVariables(
  String text, {
  List<RichTextPlaceholder> placeholders = const [],
  String placeholderMarker = "\\\$",
}) {
  for (RichTextPlaceholder placeholder in placeholders) {
    String search =
        "$placeholderMarker${placeholder.symbol}$placeholderMarker";

    text = text.replaceAll(
      RegExp(search),
      "${placeholder.value}",
    );
  }

  return text;
}