operator [] method
Returns the DynamicValue for the given key or DynamicValue(null) if key is not in the map.
The key can be an index in a list or a string key in a map.
Implementation
DynamicValue operator [](dynamic key) {
if (key is int) {
// List index
if (value is List) {
final List list = value as List;
return (key < list.length && key >= 0)
? DynamicValue(list[key])
: _nullValue;
} else {
return _nullValue;
}
} else if (key is String) {
// Map key
if (value is Map) {
final Map map = value as Map;
return map.keys.contains(key) ? DynamicValue(map[key]) : _nullValue;
} else {
return _nullValue;
}
}
return _nullValue;
}