askTheme static method

Future<int> askTheme(
  1. String prompt,
  2. List<String> themes,
  3. List<String> descriptions, {
  4. int initialIndex = 0,
  5. String? fromStep,
})

Theme/option selector with an appended "Back" item that throws BackNavigation when chosen.

Implementation

static Future<int> askTheme(
  String prompt,
  List<String> themes,
  List<String> descriptions, {
  int initialIndex = 0,
  String? fromStep,
}) async {
  final List<String> options = <String>[
    for (int i = 0; i < themes.length; i++)
      if (i < descriptions.length)
        '${themes[i]} - ${descriptions[i]}'
      else
        themes[i],
    backOptionLabel,
  ];

  final int chosen = await UserPrompt.showMenu(
    prompt,
    options,
    defaultIndex: initialIndex,
  );

  if (chosen == options.length - 1) {
    throw BackNavigation(fromStep: fromStep);
  }
  return chosen;
}