values method

List<String> values(
  1. String key, {
  2. @Deprecated('use mode with ParamsMode.raw instead') bool raw = false,
  3. ParamsMode mode = ParamsMode.standard,
})

Retrieves the values for a key, possibly multiple values.

Returns a list of values for the key. If there are no values an empty list is returned.

The values are processed according to the mode, which defaults to ParamsMode.standard. In the default mode, this method is like the [] operator except it supports zero or more values matching the same key.

Unlike the [] operator, this method allows different modes to be used. In particular, the ParamsMode.rawLines is useful for input that can contains multiple lines (e.g. from a textarea element).

If the deprecated raw parameter is set to true, it is the same as using the ParamsMode.raw mode. It is being replaced by the mode parameter which gives greater flexibility to this method. Do not use both raw and mode.

Implementation

List<String> values(String key,
    {@Deprecated('use mode with ParamsMode.raw instead') bool raw = false,
    ParamsMode mode = ParamsMode.standard}) {
  // When the deprecated "raw" parameter is removed, delete the next few lines
  // and just use the "mode".
  assert(
      !raw || raw && mode == ParamsMode.standard, 'do not mix raw with mode');
  final _realMode = raw ? ParamsMode.raw : mode;

  final values = _data[key];

  if (values == null) {
    // Return empty list
    return <String>[];
  } else if (_realMode == ParamsMode.raw) {
    // Don't need to apply _sanitize, since it won't change the values
    return values;
  } else {
    // Apply _sanitize to all the values and return a list
    return List<String>.from(
        values.map<String>((x) => _sanitize(x, _realMode)));
  }
}