setMultiValue method
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
];
}
}