getOptionsAsList method

Map<String, List<Map>> getOptionsAsList({
  1. required String byField,
})

Implementation

Map<String, List<Map>> getOptionsAsList({required String byField}) {
  Map<String, List<Map>> grouped = {};

  this.forEach((key, value) {
    String group = value[byField];
    value.remove(byField);
    value['strategy'] = key;

    if (!grouped.containsKey(group)) {
      grouped[group] = [];
    }

    grouped[group]!.add(value);
  });

  return grouped;
}