updateAlternativeInputs method

List<PairwiseAlternativeInput> updateAlternativeInputs(
  1. List<PairwiseAlternativeInput> currentAlternativeInputs, {
  2. required String? criteriaId,
  3. required String? alternativeId,
  4. required int scale,
  5. required bool isLeftMoreImportant,
})

UPDATE ALTERNATIVE VALUE

Implementation

List<PairwiseAlternativeInput> updateAlternativeInputs(
  List<PairwiseAlternativeInput> currentAlternativeInputs, {
  required String? criteriaId,
  required String? alternativeId,
  required int scale,
  required bool isLeftMoreImportant,
}) {
  return currentAlternativeInputs.map((e) {
    if (e.criteria.id == criteriaId) {
      final updatedAlternatives = e.alternative.map((alt) {
        if (alt.id == alternativeId) {
          return alt.copyWith(
            preferenceValue: scale,
            isLeftMoreImportant: isLeftMoreImportant,
          );
        }
        return alt;
      }).toList();

      return e.copyWith(alternative: updatedAlternatives);
    }
    return e;
  }).toList();
}