read<T> static method

Future read<T>(
  1. String key, {
  2. Storable? model,
})

Read a value from the local storage

Implementation

static Future<dynamic> read<T>(String key, {Storable? model}) async {
  String? data = await StorageManager.storage.read(key: key);
  if (data == null) {
    return null;
  }

  if (model != null) {
    try {
      String? data = await StorageManager.storage.read(key: key);
      if (data == null) {
        return null;
      }

      model.fromStorage(jsonDecode(data));
      return model;
    } on Exception catch (e) {
      print(e.toString());
    }
  }

  if (T.toString() == "String") {
    return data.toString();
  }

  if (T.toString() == "int") {
    return int.parse(data.toString());
  }

  if (T.toString() == "double") {
    return double.parse(data);
  }

  if (_isInteger(data)) {
    return int.parse(data);
  }

  if (_isDouble(data)) {
    return double.parse(data);
  }

  return data;
}