read<T> method

T? read<T>(
  1. String key, {
  2. dynamic defaultValue,
})

Read data from the Backpack with a key.

Implementation

T? read<T>(String key, {dynamic defaultValue}) {
  if (!_values.containsKey(key)) {
    if (defaultValue != null) return defaultValue;
    return null;
  }
  dynamic value = _values[key];
  if (T.toString() != 'dynamic' && (value is String)) {
    dynamic nyJson = _NyJson.tryDecode(value);
    if (nyJson != null) {
      T model = dataToModel<T>(data: nyJson);
      _values[key] = model;
      return model;
    }
  }

  return value;
}