getEntityFileOnDisc<D, T> method

Future<D?> getEntityFileOnDisc<D, T>(
  1. String urlColumnName,
  2. String key,
  3. dynamic value, {
  4. String? path,
})

It will take the url from T's table and get the file on path/fileName or the systePath/fileName
D is the type of the loaded data (Unit8List, String, integer, etc)

Implementation

Future<D?> getEntityFileOnDisc<D, T>(
    String urlColumnName, String key, dynamic value,
    {String? path}) async {
  var urls = await DataAccess.instance.getAColumnFrom<String, T>(
      urlColumnName,
      afterWhere: "$key='$value' LIMIT 1");
  if (urls.isEmpty) return null;

  if (D == Uint8List) {
    return path != null
        ? await DiscData.instance
            .readFileAsBytes(path: "$path$pathJoin${urls.first}") as D
        : await DiscData.instance.readFileAsBytes(fileName: urls.first) as D;
  } else {
    return path != null
        ? await DiscData.instance
            .readFileAsString(path: "$path$pathJoin${urls.first}") as D
        : await DiscData.instance.readFileAsString(fileName: urls.first) as D;
  }
}