checkFilesExist method
Future<List<String> >
checkFilesExist({
- required List<
String> filePaths, - String assetPath = 'assets',
- FileExistenceFilter filter = FileExistenceFilter.both,
Checks for existence of files in local storage
Implementation
Future<List<String>> checkFilesExist({
required List<String> filePaths,
String assetPath = 'assets',
FileExistenceFilter filter = FileExistenceFilter.both,
}) async {
final dir = await getApplicationDocumentsDirectory();
final basePath = dir.path;
final results = await Future.wait(
filePaths.map((path) async {
final fullPath = p.join(basePath, assetPath, path);
final exists = await File(fullPath).exists();
return (path, exists);
}),
);
switch (filter) {
case FileExistenceFilter.onlyExisting:
return results.where((e) => e.$2).map((e) => e.$1).toList();
case FileExistenceFilter.onlyNonExisting:
return results.where((e) => !e.$2).map((e) => e.$1).toList();
case FileExistenceFilter.both:
return filePaths;
}
}