The code should be working on flutter2, with android and ios(if possible)
Asked
Active
Viewed 476 times
1 Answers
1
Searching for files
- Do you want to simplify your life? Use this package:
import 'package:glob/glob.dart';
Stream<File> search(Directory dir) {
return Glob("**.mp3")
.list(root: dir.path)
.where((entity) => entity is File)
.cast<File>();
}
- Do you want to avoid adding a new dependency in your project? Manipulate the
Directory
itself:
Stream<File> search(Directory dir) {
return dir
.list(recursive: true)
.where((entity) => entity is File && entity.path.endsWith(".mp3"))
.cast<File>();
}
Defining the search scope
You'll also need a Directory
where you'll search for MP3 files.
Is it the root directory (i.e. search ALL the files in the device)? Use this answer.
Is it another directory? Pick one from this package.
Usage
final Directory dir = /* the directory you obtained in the last section */;
await search(dir).forEach((file) => print(file));

enzo
- 9,861
- 3
- 15
- 38
-
The method 'list' isn't defined for the type 'Glob'. Try correcting the name to the name of an existing method, or defining a method named 'list'. – Wali Khan Jul 31 '21 at 13:20
-
Try adding `import 'package:glob/list_local_fs.dart';` at the top of your file. – enzo Jul 31 '21 at 14:51
-
No permissions found in manifest for: []22 when i ask for permissions – Wali Khan Aug 01 '21 at 23:31
-
FileSystemException: Directory listing failed, path = './' (OS Error: Permission denied, errno = 13) – Wali Khan Aug 02 '21 at 00:18