operator [] method
Retrieves a single sanitized value for the key.
Values are sanitized by trimming whitespace from both ends
of the string. The empty string is returned if there is no value
matching the key
or there is a value but it only contains
nothing except whitespace (includes the case when it is the empty string).
This operator must only be used for parameters which are single valued. If the key matches multiple values: in production mode, the empty string is returned; in checked mode, an assertion error is raised. Use the values method for keys with multiple values.
This operator never returns null.
It is not possible to distinguish between a value that does not exist and a value that is a blank or empty string. If that distinction is important, use the values method instead. The values method should be used if the raw values (i.e. without whitespace trimming) are required.
Implementation
String operator [](String key) {
final values = _data[key];
if (values == null) {
return ""; // no value for key
} else if (values.length == 1) {
return _sanitize(values[0]); // returns sanitized single value
} else {
assert(values.length == 1, 'multi-valued: do not use [] with "$key"');
return ""; // error value
}
}