Skip to content

Commit

Permalink
Sorting for GridView
Browse files Browse the repository at this point in the history
Add functionality to set sort type and order
  • Loading branch information
chesnoksatan committed Jul 24, 2022
1 parent 48409ed commit 7ca1b61
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions lib/widgets/workspace.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ class _FilesWorkspaceState extends State<FilesWorkspace> {
setState(() {
if (type != null) {
controller.sortType = type;
controller.columnIndex = type.index;
controller.changeCurrentDir(controller.currentDir);
}
});
}

void _setSortOrder(bool ascending) {
setState(() {
if (ascending != controller.ascending) {
controller.ascending = ascending;
controller.changeCurrentDir(controller.currentDir);
}
});
}
Expand Down Expand Up @@ -202,7 +213,10 @@ class _FilesWorkspaceState extends State<FilesWorkspace> {
shortcut: Radio<SortType>(
value: SortType.name,
groupValue: controller.sortType,
onChanged: _setSortType,
onChanged: (SortType? type) {
_setSortType(type);
Navigator.pop(context);
},
),
),
ContextMenuEntry(
Expand All @@ -212,7 +226,10 @@ class _FilesWorkspaceState extends State<FilesWorkspace> {
shortcut: Radio<SortType>(
value: SortType.modified,
groupValue: controller.sortType,
onChanged: _setSortType,
onChanged: (SortType? type) {
_setSortType(type);
Navigator.pop(context);
},
),
),
ContextMenuEntry(
Expand All @@ -222,7 +239,10 @@ class _FilesWorkspaceState extends State<FilesWorkspace> {
shortcut: Radio<SortType>(
value: SortType.size,
groupValue: controller.sortType,
onChanged: _setSortType,
onChanged: (SortType? type) {
_setSortType(type);
Navigator.pop(context);
},
),
),
ContextMenuEntry(
Expand All @@ -232,10 +252,28 @@ class _FilesWorkspaceState extends State<FilesWorkspace> {
shortcut: Radio<SortType>(
value: SortType.type,
groupValue: controller.sortType,
onChanged: _setSortType,
onChanged: (SortType? type) {
_setSortType(type);
Navigator.pop(context);
},
),
),
const ContextMenuDivider(),
ContextMenuEntry(
id: 'ascending',
title: const Text('Ascending'),
onTap: () => _setSortOrder(true),
leading:
controller.ascending ? const Icon(Icons.check) : null,
),
ContextMenuEntry(
id: 'descending',
title: const Text('Descending'),
onTap: () => _setSortOrder(false),
leading:
controller.ascending ? null : const Icon(Icons.check),
),
const ContextMenuDivider(),
],
ContextMenuEntry(
id: 'reload',
Expand Down

0 comments on commit 7ca1b61

Please sign in to comment.