getAttribute method

dynamic getAttribute(
  1. String key
)
inherited

Get an attribute from the model.

Implementation

dynamic getAttribute(String key) {
  if (_attributes.containsKey(key)) {
    return _getAttributeValue(key, _attributes[key]);
  }

  // Prevent recursion when accessing appends
  if (_retrieving.contains(key)) {
    return null;
  }
  _retrieving.add(key);

  try {
    if (appends.containsKey(key)) {
      if (_computedCache.containsKey(key)) {
        return _computedCache[key];
      }
      final value = appends[key];
      if (value is Function) {
        final result = value();
        _computedCache[key] = result;
        return result;
      }
      return value;
    }
  } finally {
    _retrieving.remove(key);
  }

  return null;
}