list_ method

Future<List<File>> list_({
  1. bool predicate(
    1. File
    )?,
})

Recursively lists all the Files present in the Directory.

Implementation

Future<List<File>> list_({bool Function(File)? predicate}) async {
  final completer = Completer();
  final files = <File>[];
  try {
    Directory(addPrefix(path))
        .list(recursive: true, followLinks: false)
        .listen(
      (event) {
        if (event is File) {
          final file = File(removePrefix(event.path));
          if (predicate?.call(file) ?? true) {
            files.add(file);
          }
        }
      },
      onError: (error) {
        // For debugging. In case any future error is reported by the users.
        print(error.toString());
      },
      onDone: completer.complete,
    );
    await completer.future;
    return files;
  } catch (exception, stacktrace) {
    print(exception.toString());
    print(stacktrace.toString());
    return [];
  }
}