getAttribute<T> method

T getAttribute<T>(
  1. String key
)

Implementation

T getAttribute<T>(String key) {
  final rawAttribute = attributes[key];

  switch (T.toString()) {
    case 'bool':
      return rawAttribute ?? false;
    case 'String':
      return rawAttribute ?? '';
    case 'int':
      return rawAttribute ?? 0;
    case 'double':
      return rawAttribute ?? 0.0;
    case 'List<bool>':
      return (rawAttribute as List).cast<bool>() as T;
    case 'List<String>':
      return (rawAttribute as List).cast<String>() as T;
    case 'List<int>':
      return (rawAttribute as List).cast<int>() as T;
    case 'List<double>':
      return (rawAttribute as List).cast<double>() as T;
  }

  return rawAttribute;
}