search method
Stream<FileSystemEntity>
search(
- dynamic keyword, {
- FileFilter? searchFilter,
- FlutterFileUtilsSorting? sortedBy,
Returns a list of found items of Directory or File type or empty list.
You may supply Regular Expression
e.g: "*.png", instead of string.
filesOnly
if set totrue
return only filesdirsOnly
if set totrue
return only directories- You can set both to
true
- sortedBy: FlutterFileUtilsSorting
- bool reverse: in case parameter sortedBy is used
- Example:
List<String> imagesPaths = await FileManager.search("myFile.png").toList();
Implementation
Stream<FileSystemEntity> search(
var keyword, {
FileFilter? searchFilter,
FlutterFileUtilsSorting? sortedBy,
}) async* {
try {
if (keyword.length == 0 || keyword == null) {
throw FileManagerError("search keyword == null");
}
if (searchFilter != null) {
print("Using default filter");
yield* root.list(recursive: true, followLinks: true).where((test) {
if (searchFilter.isValid(test.absolute.path, root.absolute.path)) {
return getBaseName(test.path, extension: true).contains(keyword);
}
return false;
});
} else if (filter != null) {
print("Using default filter");
yield* root.list(recursive: true, followLinks: true).where((test) {
if (filter!.isValid(test.absolute.path, root.absolute.path)) {
return getBaseName(test.path, extension: true).contains(keyword);
}
return false;
});
} else {
yield* root.list(recursive: true, followLinks: true).where((test) =>
getBaseName(test.path, extension: true).contains(keyword));
}
} on FileSystemException catch (e) {
throw FileManagerError(permissionMessage + ' ' + e.toString());
} catch (e) {
throw FileManagerError(e.toString());
}
}