children_ method

Future<List<FileSystemEntity>> children_()

Lists all the FileSystemEntitys present in the Directory.

Implementation

Future<List<FileSystemEntity>> children_() async {
  final completer = Completer();
  final contents = <FileSystemEntity>[];
  try {
    Directory(clean(path)).list(recursive: false, followLinks: false).listen(
      (event) {
        switch (FS.typeSync_(event.path)) {
          case FileSystemEntityType.directory:
            contents.add(
              Directory(
                event.path.substring(
                  event.path.startsWith(kWin32LocalPathPrefix)
                      ? kWin32LocalPathPrefix.length
                      : 0,
                ),
              ),
            );
            break;
          case FileSystemEntityType.file:
            contents.add(
              File(
                event.path.substring(
                  event.path.startsWith(kWin32LocalPathPrefix)
                      ? kWin32LocalPathPrefix.length
                      : 0,
                ),
              ),
            );
            break;
          default:
            break;
        }
      },
      onError: (error) {
        // For debugging. In case any future error is reported by the users.
        print(error.toString());
      },
      onDone: completer.complete,
    );
    await completer.future;
    return contents;
  } catch (exception, stacktrace) {
    print(exception.toString());
    print(stacktrace.toString());
    return [];
  }
}