sortBySize property

Future<List<FileSystemEntity>> get sortBySize

Implementation

Future<List<FileSystemEntity>> get sortBySize async {
  final List<File> files = [];
  final List<Directory> dirs = [];

  for (final entity in this) {
    if (entity is Directory) {
      dirs.add(entity);
    } else if (entity is File) {
      files.add(entity);
    }
  }

  dirs.sort((a, b) => a.path.toLowerCase().compareTo(b.path.toLowerCase()));
  files.sort((a, b) => b.lengthSync().compareTo(a.lengthSync()));
  this.clear();
  this.addAll([...dirs, ...files]);

  return this;
}