setMultiValue method

void setMultiValue(
  1. K key,
  2. String value, {
  3. bool ignoreCase = false,
})

Sets the value for key. If the value already exists, ensures that is a List<String>.

Implementation

void setMultiValue(K key, String value, {bool ignoreCase = false}) {
  var keyMatch =
      (ignoreCase ? matchKeyIgnoreCase(key) : matchKey(key)) ?? key;

  var prev = this[keyMatch];

  if (prev == null) {
    this[keyMatch] = value;
  } else if (prev is String) {
    this[keyMatch] = [prev, value];
  } else if (prev is List<String>) {
    this[keyMatch] = [...prev, value];
  } else if (prev is List) {
    this[keyMatch] = <String>[
      ...prev.where((e) => e != null).map((e) => e!.toString()),
      value
    ];
  }
}