From 7a3da4c553fdc62b2156f14616aa50a6a75de656 Mon Sep 17 00:00:00 2001 From: ilgnefz Date: Sun, 2 Apr 2023 17:53:20 +0800 Subject: [PATCH] :sparkles: Added the ability to automatically sort names --- lib/pages/home/content_bar.dart | 5 +++++ lib/provider/rename.dart | 13 +++++++++++++ lib/widgets/file_list_item.dart | 29 +++++++++++++++++++++-------- pubspec.yaml | 2 +- version.json | 7 +++++++ 5 files changed, 47 insertions(+), 9 deletions(-) diff --git a/lib/pages/home/content_bar.dart b/lib/pages/home/content_bar.dart index f86e067..25b96bd 100644 --- a/lib/pages/home/content_bar.dart +++ b/lib/pages/home/content_bar.dart @@ -43,6 +43,11 @@ class ContentBar extends StatelessWidget { originName: '${S.of(context).originalName}[${provider.selectedFilesCount}/${provider.filesCount}]', targetName: S.of(context).renameName, + titleAction: IconButton( + icon: const Icon(Icons.sort_by_alpha_rounded), + iconSize: 20, + onPressed: provider.sortFiles, + ), action: PopupMenuButton( icon: const Icon(Icons.filter_alt), iconSize: 24, diff --git a/lib/provider/rename.dart b/lib/provider/rename.dart index 2b5eb54..8d503a0 100644 --- a/lib/provider/rename.dart +++ b/lib/provider/rename.dart @@ -398,6 +398,19 @@ class RenameProvider extends ChangeNotifier { notifyListeners(); } + // 排序 + bool _order = true; + bool get order => _order; + void sortFiles() { + if (_order) { + _files.sort((a, b) => a.name.compareTo(b.name)); + } else { + _files.sort((a, b) => b.name.compareTo(a.name)); + } + _order = !_order; + notifyListeners(); + } + // 获取文件类型 FileClassify getFileClassify(String extension) { if (image.contains(extension)) return FileClassify.image; diff --git a/lib/widgets/file_list_item.dart b/lib/widgets/file_list_item.dart index 0e4f5a5..5eeda83 100644 --- a/lib/widgets/file_list_item.dart +++ b/lib/widgets/file_list_item.dart @@ -11,6 +11,7 @@ class FileListItem extends StatelessWidget { required this.originName, required this.targetName, required this.action, + this.titleAction, this.color, required this.onChanged, this.onDoubleTap, @@ -21,6 +22,7 @@ class FileListItem extends StatelessWidget { final String originName; final String targetName; final Widget action; + final Widget? titleAction; final Color? color; final void Function(bool?)? onChanged; final void Function()? onDoubleTap; @@ -35,7 +37,11 @@ class FileListItem extends StatelessWidget { child: Row( children: [ Checkbox(value: selected, onChanged: onChanged), - ShowTitle(originName, color: color ?? Colors.black54), + ShowTitle( + originName, + color: color ?? Colors.black54, + action: titleAction, + ), const SpaceBoxWidth(), ShowTitle(targetName), action, @@ -47,20 +53,27 @@ class FileListItem extends StatelessWidget { } class ShowTitle extends StatelessWidget { - const ShowTitle(this.title, {super.key, this.color}); + const ShowTitle(this.title, {super.key, this.color, this.action}); final String title; final Color? color; + final Widget? action; @override Widget build(BuildContext context) { return Expanded( - child: MyText( - title, - color: color ?? Colors.black, - fontSize: 13, - fontWeight: FontWeight.normal, - maxLines: 1, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + MyText( + title, + color: color ?? Colors.black, + fontSize: 13, + fontWeight: FontWeight.normal, + maxLines: 1, + ), + if (action != null) action!, + ], ), ); } diff --git a/pubspec.yaml b/pubspec.yaml index c922969..860914e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.2.0+0 +version: 1.2.1+0 environment: sdk: ">=2.19.3 <3.0.0" diff --git a/version.json b/version.json index 18e6848..daf8efd 100644 --- a/version.json +++ b/version.json @@ -1,5 +1,12 @@ { "info": [ + { + "version": "1.2.1", + "desc": { + "zh": "添加了给名称自动排序的功能", + "en": "Added the ability to automatically sort names" + } + }, { "version": "1.2.0", "desc": {