buildEntry method

String buildEntry(
  1. String template,
  2. String id,
  3. String text,
  4. String name,
  5. ItemType type, {
  6. required bool isRequired,
})

Implementation

String buildEntry(
    String template, String id, String text, String name, ItemType type,
    {required bool isRequired}) {
  final String prefix;
  switch (type) {
    case ItemType.appStore:
      prefix = '[App Store] ';
      break;
    case ItemType.googlePlay:
      prefix = '[Google Play] ';
      break;
    case ItemType.byDefault:
    // ignore: no_default_cases
    default:
      prefix = '';
      break;
  }

  final display = type == ItemType.byDefault ? "block" : "none";
  final itemNameSb = StringBuffer()
    ..write(prefix)
    ..write(name);
  if (isRequired) itemNameSb.write('*');

  return template
      .replaceAll("%id%", id)
      .replaceAll("%name%", itemNameSb.toString())
      .replaceAll("%text%", text)
      .replaceAll("%display%", display)
      .replaceAll("%type%", type.id)
      .replaceAll("%maxlength%", "${type.maxChars}")
      .replaceAll("%required%", isRequired ? 'required' : '');
}