readData method

Future<ISerializable?> readData(
  1. String key,
  2. ISerializable? serializableObject
)

Implementation

Future<ISerializable?> readData(
  String key,
  ISerializable? serializableObject,
) async {
  try {
    if (cachedLoadedData.isEmpty) {
      final fl = await file;
      if (await fl.exists()) {
        final content = await fl.readAsString();
        if (content.isNotEmpty) {
          cachedLoadedData = Map<String, String>.from(jsonDecode(content));
        }
      }
    }

    if (serializableObject != null && cachedLoadedData[key] != null) {
      return serializableObject.fromJson(
        jsonDecode(cachedLoadedData[key]!) as Map<String, dynamic>,
      );
    }
    return null;
  } catch (_) {
    return null;
  }
}