file model handle path . and .. , opt follow lint

This commit is contained in:
csf 2022-10-19 23:29:45 +09:00
parent 62c53f0343
commit 04398ef54e
3 changed files with 87 additions and 80 deletions

View File

@ -229,13 +229,13 @@ class _FileManagerPageState extends State<FileManagerPage>
final entries = fd.entries; final entries = fd.entries;
final sortIndex = (SortBy style) { final sortIndex = (SortBy style) {
switch (style) { switch (style) {
case SortBy.Name: case SortBy.name:
return 0; return 0;
case SortBy.Type: case SortBy.type:
return 0; return 0;
case SortBy.Modified: case SortBy.modified:
return 1; return 1;
case SortBy.Size: case SortBy.size:
return 2; return 2;
} }
}(model.getSortStyle(isLocal)); }(model.getSortStyle(isLocal));
@ -265,7 +265,7 @@ class _FileManagerPageState extends State<FileManagerPage>
translate("Name"), translate("Name"),
).marginSymmetric(horizontal: 4), ).marginSymmetric(horizontal: 4),
onSort: (columnIndex, ascending) { onSort: (columnIndex, ascending) {
model.changeSortStyle(SortBy.Name, model.changeSortStyle(SortBy.name,
isLocal: isLocal, ascending: ascending); isLocal: isLocal, ascending: ascending);
}), }),
DataColumn( DataColumn(
@ -273,13 +273,13 @@ class _FileManagerPageState extends State<FileManagerPage>
translate("Modified"), translate("Modified"),
), ),
onSort: (columnIndex, ascending) { onSort: (columnIndex, ascending) {
model.changeSortStyle(SortBy.Modified, model.changeSortStyle(SortBy.modified,
isLocal: isLocal, ascending: ascending); isLocal: isLocal, ascending: ascending);
}), }),
DataColumn( DataColumn(
label: Text(translate("Size")), label: Text(translate("Size")),
onSort: (columnIndex, ascending) { onSort: (columnIndex, ascending) {
model.changeSortStyle(SortBy.Size, model.changeSortStyle(SortBy.size,
isLocal: isLocal, ascending: ascending); isLocal: isLocal, ascending: ascending);
}), }),
], ],

View File

@ -4,15 +4,18 @@ import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_hbb/common.dart'; import 'package:flutter_hbb/common.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:path/path.dart' as Path; import 'package:path/path.dart' as path;
import 'model.dart'; import 'model.dart';
import 'platform_model.dart'; import 'platform_model.dart';
enum SortBy { Name, Type, Modified, Size } enum SortBy { name, type, modified, size }
class FileModel extends ChangeNotifier { class FileModel extends ChangeNotifier {
var _isLocal = false; /// mobile, current selected page show on mobile screen
var _isSelectedLocal = false;
/// mobile, select mode state
var _selectMode = false; var _selectMode = false;
final _localOption = DirectoryOption(); final _localOption = DirectoryOption();
@ -30,7 +33,7 @@ class FileModel extends ChangeNotifier {
RxList<JobProgress> get jobTable => _jobTable; RxList<JobProgress> get jobTable => _jobTable;
bool get isLocal => _isLocal; bool get isLocal => _isSelectedLocal;
bool get selectMode => _selectMode; bool get selectMode => _selectMode;
@ -38,17 +41,17 @@ class FileModel extends ChangeNotifier {
JobState get jobState => _jobProgress.state; JobState get jobState => _jobProgress.state;
SortBy _sortStyle = SortBy.Name; SortBy _sortStyle = SortBy.name;
SortBy get sortStyle => _sortStyle; SortBy get sortStyle => _sortStyle;
SortBy _localSortStyle = SortBy.Name; SortBy _localSortStyle = SortBy.name;
bool _localSortAscending = true; bool _localSortAscending = true;
bool _remoteSortAscending = true; bool _remoteSortAscending = true;
SortBy _remoteSortStyle = SortBy.Name; SortBy _remoteSortStyle = SortBy.name;
bool get localSortAscending => _localSortAscending; bool get localSortAscending => _localSortAscending;
@ -64,7 +67,8 @@ class FileModel extends ChangeNotifier {
FileDirectory get currentRemoteDir => _currentRemoteDir; FileDirectory get currentRemoteDir => _currentRemoteDir;
FileDirectory get currentDir => _isLocal ? currentLocalDir : currentRemoteDir; FileDirectory get currentDir =>
_isSelectedLocal ? currentLocalDir : currentRemoteDir;
FileDirectory getCurrentDir(bool isLocal) { FileDirectory getCurrentDir(bool isLocal) {
return isLocal ? currentLocalDir : currentRemoteDir; return isLocal ? currentLocalDir : currentRemoteDir;
@ -75,7 +79,7 @@ class FileModel extends ChangeNotifier {
final currentHome = getCurrentHome(isLocal); final currentHome = getCurrentHome(isLocal);
if (currentDir.path.startsWith(currentHome)) { if (currentDir.path.startsWith(currentHome)) {
var path = currentDir.path.replaceFirst(currentHome, ""); var path = currentDir.path.replaceFirst(currentHome, "");
if (path.length == 0) return ""; if (path.isEmpty) return "";
if (path[0] == "/" || path[0] == "\\") { if (path[0] == "/" || path[0] == "\\") {
// remove more '/' or '\' // remove more '/' or '\'
path = path.replaceFirst(path[0], ""); path = path.replaceFirst(path[0], "");
@ -86,7 +90,8 @@ class FileModel extends ChangeNotifier {
} }
} }
String get currentHome => _isLocal ? _localOption.home : _remoteOption.home; String get currentHome =>
_isSelectedLocal ? _localOption.home : _remoteOption.home;
String getCurrentHome(bool isLocal) { String getCurrentHome(bool isLocal) {
return isLocal ? _localOption.home : _remoteOption.home; return isLocal ? _localOption.home : _remoteOption.home;
@ -99,7 +104,7 @@ class FileModel extends ChangeNotifier {
String get currentShortPath { String get currentShortPath {
if (currentDir.path.startsWith(currentHome)) { if (currentDir.path.startsWith(currentHome)) {
var path = currentDir.path.replaceFirst(currentHome, ""); var path = currentDir.path.replaceFirst(currentHome, "");
if (path.length == 0) return ""; if (path.isEmpty) return "";
if (path[0] == "/" || path[0] == "\\") { if (path[0] == "/" || path[0] == "\\") {
// remove more '/' or '\' // remove more '/' or '\'
path = path.replaceFirst(path[0], ""); path = path.replaceFirst(path[0], "");
@ -114,7 +119,7 @@ class FileModel extends ChangeNotifier {
final dir = isLocal ? currentLocalDir : currentRemoteDir; final dir = isLocal ? currentLocalDir : currentRemoteDir;
if (dir.path.startsWith(currentHome)) { if (dir.path.startsWith(currentHome)) {
var path = dir.path.replaceFirst(currentHome, ""); var path = dir.path.replaceFirst(currentHome, "");
if (path.length == 0) return ""; if (path.isEmpty) return "";
if (path[0] == "/" || path[0] == "\\") { if (path[0] == "/" || path[0] == "\\") {
// remove more '/' or '\' // remove more '/' or '\'
path = path.replaceFirst(path[0], ""); path = path.replaceFirst(path[0], "");
@ -126,14 +131,14 @@ class FileModel extends ChangeNotifier {
} }
bool get currentShowHidden => bool get currentShowHidden =>
_isLocal ? _localOption.showHidden : _remoteOption.showHidden; _isSelectedLocal ? _localOption.showHidden : _remoteOption.showHidden;
bool getCurrentShowHidden(bool isLocal) { bool getCurrentShowHidden(bool isLocal) {
return isLocal ? _localOption.showHidden : _remoteOption.showHidden; return isLocal ? _localOption.showHidden : _remoteOption.showHidden;
} }
bool get currentIsWindows => bool get currentIsWindows =>
_isLocal ? _localOption.isWindows : _remoteOption.isWindows; _isSelectedLocal ? _localOption.isWindows : _remoteOption.isWindows;
bool getCurrentIsWindows(bool isLocal) { bool getCurrentIsWindows(bool isLocal) {
return isLocal ? _localOption.isWindows : _remoteOption.isWindows; return isLocal ? _localOption.isWindows : _remoteOption.isWindows;
@ -156,12 +161,12 @@ class FileModel extends ChangeNotifier {
} }
togglePage() { togglePage() {
_isLocal = !_isLocal; _isSelectedLocal = !_isSelectedLocal;
notifyListeners(); notifyListeners();
} }
toggleShowHidden({bool? showHidden, bool? local}) { toggleShowHidden({bool? showHidden, bool? local}) {
final isLocal = local ?? _isLocal; final isLocal = local ?? _isSelectedLocal;
if (isLocal) { if (isLocal) {
_localOption.showHidden = showHidden ?? !_localOption.showHidden; _localOption.showHidden = showHidden ?? !_localOption.showHidden;
} else { } else {
@ -187,7 +192,7 @@ class FileModel extends ChangeNotifier {
job.fileNum = int.parse(evt['file_num']); job.fileNum = int.parse(evt['file_num']);
job.speed = double.parse(evt['speed']); job.speed = double.parse(evt['speed']);
job.finishedSize = int.parse(evt['finished_size']); job.finishedSize = int.parse(evt['finished_size']);
debugPrint("update job ${id} with ${evt}"); debugPrint("update job $id with $evt");
} }
} }
notifyListeners(); notifyListeners();
@ -197,7 +202,7 @@ class FileModel extends ChangeNotifier {
} }
receiveFileDir(Map<String, dynamic> evt) { receiveFileDir(Map<String, dynamic> evt) {
debugPrint("recv file dir:${evt}"); debugPrint("recv file dir:$evt");
if (evt['is_local'] == "false") { if (evt['is_local'] == "false") {
// init remote home, the connection will automatic read remote home when established, // init remote home, the connection will automatic read remote home when established,
try { try {
@ -209,9 +214,9 @@ class FileModel extends ChangeNotifier {
final job = jobTable[jobIndex]; final job = jobTable[jobIndex];
var totalSize = 0; var totalSize = 0;
var fileCount = fd.entries.length; var fileCount = fd.entries.length;
fd.entries.forEach((element) { for (var element in fd.entries) {
totalSize += element.size; totalSize += element.size;
}); }
job.totalSize = totalSize; job.totalSize = totalSize;
job.fileCount = fileCount; job.fileCount = fileCount;
debugPrint("update receive details:${fd.path}"); debugPrint("update receive details:${fd.path}");
@ -343,7 +348,7 @@ class FileModel extends ChangeNotifier {
jobReset(); jobReset();
// save config // save config
Map<String, String> msgMap = Map(); Map<String, String> msgMap = {};
msgMap["local_dir"] = _currentLocalDir.path; msgMap["local_dir"] = _currentLocalDir.path;
msgMap["local_show_hidden"] = _localOption.showHidden ? "Y" : ""; msgMap["local_show_hidden"] = _localOption.showHidden ? "Y" : "";
@ -361,7 +366,7 @@ class FileModel extends ChangeNotifier {
Future refresh({bool? isLocal}) async { Future refresh({bool? isLocal}) async {
if (isDesktop) { if (isDesktop) {
isLocal = isLocal ?? _isLocal; isLocal = isLocal ?? _isSelectedLocal;
isLocal isLocal
? await openDirectory(currentLocalDir.path, isLocal: isLocal) ? await openDirectory(currentLocalDir.path, isLocal: isLocal)
: await openDirectory(currentRemoteDir.path, isLocal: isLocal); : await openDirectory(currentRemoteDir.path, isLocal: isLocal);
@ -371,7 +376,15 @@ class FileModel extends ChangeNotifier {
} }
openDirectory(String path, {bool? isLocal, bool isBack = false}) async { openDirectory(String path, {bool? isLocal, bool isBack = false}) async {
isLocal = isLocal ?? _isLocal; isLocal = isLocal ?? _isSelectedLocal;
if (path == ".") {
refresh(isLocal: isLocal);
return;
}
if (path == "..") {
goToParentDirectory(isLocal: isLocal);
return;
}
if (!isBack) { if (!isBack) {
pushHistory(isLocal); pushHistory(isLocal);
} }
@ -385,7 +398,7 @@ class FileModel extends ChangeNotifier {
: _remoteOption.isWindows && path.length > 1 && path[0] == '/') { : _remoteOption.isWindows && path.length > 1 && path[0] == '/') {
path = path.substring(1); path = path.substring(1);
if (path[path.length - 1] != '\\') { if (path[path.length - 1] != '\\') {
path = path + "\\"; path = "$path\\";
} }
} }
try { try {
@ -416,12 +429,12 @@ class FileModel extends ChangeNotifier {
} }
goHome({bool? isLocal}) { goHome({bool? isLocal}) {
isLocal = isLocal ?? _isLocal; isLocal = isLocal ?? _isSelectedLocal;
openDirectory(getCurrentHome(isLocal), isLocal: isLocal); openDirectory(getCurrentHome(isLocal), isLocal: isLocal);
} }
goBack({bool? isLocal}) { goBack({bool? isLocal}) {
isLocal = isLocal ?? _isLocal; isLocal = isLocal ?? _isSelectedLocal;
final history = isLocal ? localHistory : remoteHistory; final history = isLocal ? localHistory : remoteHistory;
if (history.isEmpty) return; if (history.isEmpty) return;
final path = history.removeAt(history.length - 1); final path = history.removeAt(history.length - 1);
@ -435,7 +448,7 @@ class FileModel extends ChangeNotifier {
} }
goToParentDirectory({bool? isLocal}) { goToParentDirectory({bool? isLocal}) {
isLocal = isLocal ?? _isLocal; isLocal = isLocal ?? _isSelectedLocal;
final isWindows = final isWindows =
isLocal ? _localOption.isWindows : _remoteOption.isWindows; isLocal ? _localOption.isWindows : _remoteOption.isWindows;
final currDir = isLocal ? currentLocalDir : currentRemoteDir; final currDir = isLocal ? currentLocalDir : currentRemoteDir;
@ -457,7 +470,7 @@ class FileModel extends ChangeNotifier {
isRemote ? _localOption.isWindows : _remoteOption.isWindows; isRemote ? _localOption.isWindows : _remoteOption.isWindows;
final showHidden = final showHidden =
isRemote ? _localOption.showHidden : _remoteOption.showHidden; isRemote ? _localOption.showHidden : _remoteOption.showHidden;
items.items.forEach((from) async { for (var from in items.items) {
final jobId = ++_jobId; final jobId = ++_jobId;
_jobTable.add(JobProgress() _jobTable.add(JobProgress()
..jobName = from.path ..jobName = from.path
@ -473,9 +486,9 @@ class FileModel extends ChangeNotifier {
fileNum: 0, fileNum: 0,
includeHidden: showHidden, includeHidden: showHidden,
isRemote: isRemote); isRemote: isRemote);
print( debugPrint(
"path:${from.path}, toPath:${toPath}, to:${PathUtil.join(toPath, from.name, isWindows)}"); "path:${from.path}, toPath:$toPath, to:${PathUtil.join(toPath, from.name, isWindows)}");
}); }
} else { } else {
if (items.isLocal == null) { if (items.isLocal == null) {
debugPrint("Failed to sendFiles ,wrong path state"); debugPrint("Failed to sendFiles ,wrong path state");
@ -505,7 +518,7 @@ class FileModel extends ChangeNotifier {
bool removeCheckboxRemember = false; bool removeCheckboxRemember = false;
removeAction(SelectedItems items, {bool? isLocal}) async { removeAction(SelectedItems items, {bool? isLocal}) async {
isLocal = isLocal ?? _isLocal; isLocal = isLocal ?? _isSelectedLocal;
removeCheckboxRemember = false; removeCheckboxRemember = false;
if (items.isLocal == null) { if (items.isLocal == null) {
debugPrint("Failed to removeFile, wrong path state"); debugPrint("Failed to removeFile, wrong path state");
@ -520,7 +533,7 @@ class FileModel extends ChangeNotifier {
late final List<Entry> entries; late final List<Entry> entries;
if (item.isFile) { if (item.isFile) {
title = translate("Are you sure you want to delete this file?"); title = translate("Are you sure you want to delete this file?");
content = "${item.name}"; content = item.name;
entries = [item]; entries = [item];
} else if (item.isDirectory) { } else if (item.isDirectory) {
title = translate("Not an empty directory"); title = translate("Not an empty directory");
@ -553,7 +566,7 @@ class FileModel extends ChangeNotifier {
? "${translate("Are you sure you want to delete the file of this directory?")}\n" ? "${translate("Are you sure you want to delete the file of this directory?")}\n"
: ""; : "";
final count = entries.length > 1 ? "${i + 1}/${entries.length}" : ""; final count = entries.length > 1 ? "${i + 1}/${entries.length}" : "";
content = dirShow + "$count \n${entries[i].path}"; content = "$dirShow$count \n${entries[i].path}";
final confirm = final confirm =
await showRemoveDialog(title, content, item.isDirectory); await showRemoveDialog(title, content, item.isDirectory);
try { try {
@ -580,7 +593,7 @@ class FileModel extends ChangeNotifier {
break; break;
} }
} catch (e) { } catch (e) {
print("remove error: ${e}"); print("remove error: $e");
} }
} }
}); });
@ -779,14 +792,14 @@ class FileModel extends ChangeNotifier {
job.fileCount = num_entries; job.fileCount = num_entries;
job.totalSize = total_size.toInt(); job.totalSize = total_size.toInt();
} }
debugPrint("update folder files: ${info}"); debugPrint("update folder files: $info");
notifyListeners(); notifyListeners();
} }
bool get remoteSortAscending => _remoteSortAscending; bool get remoteSortAscending => _remoteSortAscending;
void loadLastJob(Map<String, dynamic> evt) { void loadLastJob(Map<String, dynamic> evt) {
debugPrint("load last job: ${evt}"); debugPrint("load last job: $evt");
Map<String, dynamic> jobDetail = json.decode(evt['value']); Map<String, dynamic> jobDetail = json.decode(evt['value']);
// int id = int.parse(jobDetail['id']); // int id = int.parse(jobDetail['id']);
String remote = jobDetail['remote']; String remote = jobDetail['remote'];
@ -824,7 +837,7 @@ class FileModel extends ChangeNotifier {
id: '${parent.target?.id}', actId: job.id, isRemote: job.isRemote); id: '${parent.target?.id}', actId: job.id, isRemote: job.isRemote);
job.state = JobState.inProgress; job.state = JobState.inProgress;
} else { } else {
debugPrint("jobId ${jobId} is not exists"); debugPrint("jobId $jobId is not exists");
} }
notifyListeners(); notifyListeners();
} }
@ -833,7 +846,7 @@ class FileModel extends ChangeNotifier {
class JobResultListener<T> { class JobResultListener<T> {
Completer<T>? _completer; Completer<T>? _completer;
Timer? _timer; Timer? _timer;
int _timeoutSecond = 5; final int _timeoutSecond = 5;
bool get isListening => _completer != null; bool get isListening => _completer != null;
@ -871,20 +884,14 @@ class JobResultListener<T> {
} }
class FileFetcher { class FileFetcher {
// Map<String,Completer<FileDirectory>> localTasks = Map(); // now we only use read local dir sync // Map<String,Completer<FileDirectory>> localTasks = {}; // now we only use read local dir sync
Map<String, Completer<FileDirectory>> remoteTasks = Map(); Map<String, Completer<FileDirectory>> remoteTasks = {};
Map<int, Completer<FileDirectory>> readRecursiveTasks = Map(); Map<int, Completer<FileDirectory>> readRecursiveTasks = {};
String? _id; String? id;
String? get id => _id;
set id(String? id) {
_id = id;
}
// if id == null, means to fetch global FFI // if id == null, means to fetch global FFI
FFI get _ffi => ffi(_id ?? ""); FFI get _ffi => ffi(id ?? "");
Future<FileDirectory> registerReadTask(bool isLocal, String path) { Future<FileDirectory> registerReadTask(bool isLocal, String path) {
// final jobs = isLocal?localJobs:remoteJobs; // maybe we will use read local dir async later // final jobs = isLocal?localJobs:remoteJobs; // maybe we will use read local dir async later
@ -921,7 +928,7 @@ class FileFetcher {
tryCompleteTask(String? msg, String? isLocalStr) { tryCompleteTask(String? msg, String? isLocalStr) {
if (msg == null || isLocalStr == null) return; if (msg == null || isLocalStr == null) return;
late final tasks; late final Map<Object, Completer<FileDirectory>> tasks;
try { try {
final fd = FileDirectory.fromJson(jsonDecode(msg)); final fd = FileDirectory.fromJson(jsonDecode(msg));
if (fd.id > 0) { if (fd.id > 0) {
@ -988,15 +995,15 @@ class FileDirectory {
id = json['id']; id = json['id'];
path = json['path']; path = json['path'];
json['entries'].forEach((v) { json['entries'].forEach((v) {
entries.add(new Entry.fromJson(v)); entries.add(Entry.fromJson(v));
}); });
} }
// generate full path for every entry , init sort style if need. // generate full path for every entry , init sort style if need.
format(bool isWindows, {SortBy? sort}) { format(bool isWindows, {SortBy? sort}) {
entries.forEach((entry) { for (var entry in entries) {
entry.path = PathUtil.join(path, entry.name, isWindows); entry.path = PathUtil.join(path, entry.name, isWindows);
}); }
if (sort != null) { if (sort != null) {
changeSortStyle(sort); changeSortStyle(sort);
} }
@ -1094,8 +1101,8 @@ class _PathStat {
} }
class PathUtil { class PathUtil {
static final windowsContext = Path.Context(style: Path.Style.windows); static final windowsContext = path.Context(style: path.Style.windows);
static final posixContext = Path.Context(style: Path.Style.posix); static final posixContext = path.Context(style: path.Style.posix);
static String join(String path1, String path2, bool isWindows) { static String join(String path1, String path2, bool isWindows) {
final pathUtil = isWindows ? windowsContext : posixContext; final pathUtil = isWindows ? windowsContext : posixContext;
@ -1155,7 +1162,7 @@ class SelectedItems {
remove(Entry e) { remove(Entry e) {
_items.remove(e); _items.remove(e);
if (_items.length == 0) { if (_items.isEmpty) {
_isLocal = null; _isLocal = null;
} }
} }
@ -1181,7 +1188,7 @@ class SelectedItems {
// edited from [https://github.com/DevsOnFlutter/file_manager/blob/c1bf7f0225b15bcb86eba602c60acd5c4da90dd8/lib/file_manager.dart#L22] // edited from [https://github.com/DevsOnFlutter/file_manager/blob/c1bf7f0225b15bcb86eba602c60acd5c4da90dd8/lib/file_manager.dart#L22]
List<Entry> _sortList(List<Entry> list, SortBy sortType, bool ascending) { List<Entry> _sortList(List<Entry> list, SortBy sortType, bool ascending) {
if (sortType == SortBy.Name) { if (sortType == SortBy.name) {
// making list of only folders. // making list of only folders.
final dirs = list final dirs = list
.where((element) => element.isDirectory || element.isDrive) .where((element) => element.isDirectory || element.isDrive)
@ -1198,22 +1205,22 @@ List<Entry> _sortList(List<Entry> list, SortBy sortType, bool ascending) {
return ascending return ascending
? [...dirs, ...files] ? [...dirs, ...files]
: [...dirs.reversed.toList(), ...files.reversed.toList()]; : [...dirs.reversed.toList(), ...files.reversed.toList()];
} else if (sortType == SortBy.Modified) { } else if (sortType == SortBy.modified) {
// making the list of Path & DateTime // making the list of Path & DateTime
List<_PathStat> _pathStat = []; List<_PathStat> pathStat = [];
for (Entry e in list) { for (Entry e in list) {
_pathStat.add(_PathStat(e.name, e.lastModified())); pathStat.add(_PathStat(e.name, e.lastModified()));
} }
// sort _pathStat according to date // sort _pathStat according to date
_pathStat.sort((b, a) => a.dateTime.compareTo(b.dateTime)); pathStat.sort((b, a) => a.dateTime.compareTo(b.dateTime));
// sorting [list] according to [_pathStat] // sorting [list] according to [_pathStat]
list.sort((a, b) => _pathStat list.sort((a, b) => pathStat
.indexWhere((element) => element.path == a.name) .indexWhere((element) => element.path == a.name)
.compareTo(_pathStat.indexWhere((element) => element.path == b.name))); .compareTo(pathStat.indexWhere((element) => element.path == b.name)));
return ascending ? list : list.reversed.toList(); return ascending ? list : list.reversed.toList();
} else if (sortType == SortBy.Type) { } else if (sortType == SortBy.type) {
// making list of only folders. // making list of only folders.
final dirs = list.where((element) => element.isDirectory).toList(); final dirs = list.where((element) => element.isDirectory).toList();
@ -1232,11 +1239,11 @@ List<Entry> _sortList(List<Entry> list, SortBy sortType, bool ascending) {
return ascending return ascending
? [...dirs, ...files] ? [...dirs, ...files]
: [...dirs.reversed.toList(), ...files.reversed.toList()]; : [...dirs.reversed.toList(), ...files.reversed.toList()];
} else if (sortType == SortBy.Size) { } else if (sortType == SortBy.size) {
// create list of path and size // create list of path and size
Map<String, int> _sizeMap = {}; Map<String, int> sizeMap = {};
for (Entry e in list) { for (Entry e in list) {
_sizeMap[e.name] = e.size; sizeMap[e.name] = e.size;
} }
// making list of only folders. // making list of only folders.
@ -1248,14 +1255,13 @@ List<Entry> _sortList(List<Entry> list, SortBy sortType, bool ascending) {
final files = list.where((element) => element.isFile).toList(); final files = list.where((element) => element.isFile).toList();
// creating sorted list of [_sizeMapList] by size. // creating sorted list of [_sizeMapList] by size.
final List<MapEntry<String, int>> _sizeMapList = _sizeMap.entries.toList(); final List<MapEntry<String, int>> sizeMapList = sizeMap.entries.toList();
_sizeMapList.sort((b, a) => a.value.compareTo(b.value)); sizeMapList.sort((b, a) => a.value.compareTo(b.value));
// sort [list] according to [_sizeMapList] // sort [list] according to [_sizeMapList]
files.sort((a, b) => _sizeMapList files.sort((a, b) => sizeMapList
.indexWhere((element) => element.key == a.name) .indexWhere((element) => element.key == a.name)
.compareTo( .compareTo(sizeMapList.indexWhere((element) => element.key == b.name)));
_sizeMapList.indexWhere((element) => element.key == b.name)));
return ascending return ascending
? [...dirs, ...files] ? [...dirs, ...files]
: [...dirs.reversed.toList(), ...files.reversed.toList()]; : [...dirs.reversed.toList(), ...files.reversed.toList()];

View File

@ -97,6 +97,7 @@ dependencies:
# ref: 62f09545149f320616467c306c8c5f71714a18e6 # ref: 62f09545149f320616467c306c8c5f71714a18e6
uni_links: ^0.5.1 uni_links: ^0.5.1
uni_links_desktop: ^0.1.3 uni_links_desktop: ^0.1.3
path: ^1.8.2
dev_dependencies: dev_dependencies:
icons_launcher: ^2.0.4 icons_launcher: ^2.0.4