toTree method

Implementation

List<FileSystemEntityChildren> toTree() {
  List<FileSystemEntityChildren> sles = [];

  local_sort();

  for (var i = 0; i < length; i++) {
    FileSystemEntity fileSystemEntity = this[i];
    if (fileSystemEntity is File) {
      sles.add(FileSystemEntityChildren(
        fileSystemEntity: fileSystemEntity,
        state_data: {},
        fileSystemEntityType: fileSystemEntity.statSync().type,
        children: [],
      ));
    } else if (fileSystemEntity is Directory) {
      sles.add(FileSystemEntityChildren(
        fileSystemEntity: fileSystemEntity,
        state_data: {},
        fileSystemEntityType: fileSystemEntity.statSync().type,
        children: fileSystemEntity
            .listSync()
            .clone<FileSystemEntity>()
            .local_sort()
            .toTree(),
      ));
    } else {
      sles.add(FileSystemEntityChildren(
        fileSystemEntity: fileSystemEntity,
        state_data: {},
        fileSystemEntityType: fileSystemEntity.statSync().type,
        children: [],
      ));
    }
  }
  return sles;
}