Skip to content

Commit

Permalink
✨ Added the ability to automatically sort names
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgnefz committed Apr 2, 2023
1 parent de47dfa commit 7a3da4c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 9 deletions.
5 changes: 5 additions & 0 deletions lib/pages/home/content_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions lib/provider/rename.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 21 additions & 8 deletions lib/widgets/file_list_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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,
Expand All @@ -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!,
],
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"info": [
{
"version": "1.2.1",
"desc": {
"zh": "添加了给名称自动排序的功能",
"en": "Added the ability to automatically sort names"
}
},
{
"version": "1.2.0",
"desc": {
Expand Down

0 comments on commit 7a3da4c

Please sign in to comment.