repeatText method

String? repeatText(
  1. String typeKey
)

A repeat caption: mainheader, add, add-empty, del, done, done-empty or delheader, with JavaRosa's English defaults.

Implementation

String? repeatText(String typeKey) {
  final g = element;
  if (g is! GroupDef || !g.isRepeat) throw StateError('not a repeat');
  final title = longText;
  final count = numRepetitions;
  String? caption;
  switch (typeKey) {
    case 'mainheader':
      caption = g.mainHeader;
      if (caption == null) return title;
    case 'add':
      caption = g.addCaption;
      if (caption == null) return 'Add another $title';
    case 'add-empty':
      caption = g.addEmptyCaption ?? g.addCaption;
      if (caption == null) return 'None - Add $title';
    case 'del':
      caption = g.delCaption;
      if (caption == null) return 'Delete $title';
    case 'done':
      caption = g.doneCaption;
      if (caption == null) return 'Done';
    case 'done-empty':
      caption = g.doneEmptyCaption ?? g.doneCaption;
      if (caption == null) return 'Skip';
    case 'delheader':
      caption = g.delHeader;
      if (caption == null) return 'Delete which $title?';
  }
  // JavaRosa fails on an unknown key; so does fillTemplateString(null).
  return form.fillTemplateString(caption!, index.reference!, {
    'name': title,
    'n': count,
  });
}