Я создаю приложение файлового менеджера во Flutter.
Я хочу отобразить общее количество файлов документов (pdf, doc, docx, txt, xlsx и т. д.), доступных в хранилище устройства.
В настоящее время я сканирую каталоги вручную следующим образом:
Future getDocumentCount() async {
int count = 0;
final Directory root = Directory('/storage/emulated/0');
final extensions = [
'.pdf', '.doc', '.docx',
'.txt', '.xls', '.xlsx',
'.ppt', '.pptx'
];
await for (final entity
in root.list(recursive: true, followLinks: false)) {
if (entity is File) {
final path = entity.path.toLowerCase();
if (extensions.any((ext) => path.endsWith(ext))) {
count++;
}
}
}
return count;
}
Future fetchDocuments() async {
isDocLoading = true;
notifyListeners();
docsCount = await getDocumentCount();
isDocLoading = false;
notifyListeners();
}
Подробнее здесь: https://stackoverflow.com/questions/798 ... android-11