mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-04 23:57:54 +00:00
feat: file tree view responsive support (#856)
This commit is contained in:
6 files changed
+65
-59
No files matched your search
@@ -64,9 +64,8 @@ class TaskFilesView extends GetView<TaskFilesController> {
|
||||
[meta.opts.path, meta.res!.name, fileRelativePath]);
|
||||
final fileName = basename(filePath);
|
||||
return ListTile(
|
||||
leading: file.isDirectory
|
||||
? const Icon(folderIcon)
|
||||
: Icon(fileIcon(fileName)),
|
||||
leading:
|
||||
Icon(fileIcon(fileName, isFolder: file.isDirectory)),
|
||||
title: Text(fileName),
|
||||
subtitle: file.isDirectory
|
||||
? Text('items'.trParams({
|
||||
|
||||
@@ -183,9 +183,11 @@ class BuildTaskListView extends GetView {
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text(task.name),
|
||||
leading: isFolderTask()
|
||||
? const Icon(folderIcon)
|
||||
: Icon(fileIcon(task.name))),
|
||||
leading: Icon(
|
||||
fileIcon(task.name,
|
||||
isFolder: isFolderTask(),
|
||||
isBitTorrent: task.protocol == Protocol.bt),
|
||||
)),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
|
||||
@@ -52,9 +52,6 @@ final Map<String, IconData> _iconCache = Map.fromEntries(
|
||||
),
|
||||
);
|
||||
|
||||
const folderIcon = Gopeed.folder;
|
||||
const folderBtIcon = Gopeed.folder_bt;
|
||||
|
||||
String fileExt(String? name) {
|
||||
if (name == null) {
|
||||
return '';
|
||||
@@ -71,7 +68,7 @@ String fileExt(String? name) {
|
||||
IconData fileIcon(String? name,
|
||||
{bool isFolder = false, bool isBitTorrent = false}) {
|
||||
if (isFolder) {
|
||||
return isBitTorrent ? folderBtIcon : folderIcon;
|
||||
return isBitTorrent ? Gopeed.folder_bt : Gopeed.folder;
|
||||
}
|
||||
|
||||
final ext = fileExt(name);
|
||||
|
||||
@@ -14,6 +14,7 @@ const _toggleSwitchIcons = [
|
||||
Gopeed.file_audio,
|
||||
Gopeed.file_image,
|
||||
];
|
||||
const _sizeGapWidth = 72.0;
|
||||
|
||||
class FileTreeView extends StatefulWidget {
|
||||
final List<FileInfo> files;
|
||||
@@ -50,7 +51,7 @@ class _FileTreeViewState extends State<FileTreeView> {
|
||||
final selectedFileCount =
|
||||
key.currentState?.getSelectedValues().where((e) => e != null).length ??
|
||||
widget.files.length;
|
||||
final selectdFileSize = calcSelectedSize(null);
|
||||
final selectedFileSize = calcSelectedSize(null);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -144,52 +145,59 @@ class _FileTreeViewState extends State<FileTreeView> {
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
InkWell(
|
||||
onTap: () {},
|
||||
child: ToggleSwitch(
|
||||
minHeight: 32,
|
||||
cornerRadius: 8,
|
||||
doubleTapDisable: true,
|
||||
inactiveBgColor: Theme.of(context).dividerColor,
|
||||
activeBgColor: [Theme.of(context).colorScheme.primary],
|
||||
initialLabelIndex: toggleSwitchIndex,
|
||||
icons: _toggleSwitchIcons,
|
||||
onToggle: (index) {
|
||||
toggleSwitchIndex = index;
|
||||
if (index == null) {
|
||||
key.currentState?.setSelectedValues(List.empty());
|
||||
return;
|
||||
}
|
||||
Flexible(
|
||||
flex: 4,
|
||||
child: InkWell(
|
||||
onTap: () {},
|
||||
child: ToggleSwitch(
|
||||
minHeight: 32,
|
||||
cornerRadius: 8,
|
||||
doubleTapDisable: true,
|
||||
inactiveBgColor: Theme.of(context).dividerColor,
|
||||
activeBgColor: [Theme.of(context).colorScheme.primary],
|
||||
initialLabelIndex: toggleSwitchIndex,
|
||||
icons: _toggleSwitchIcons,
|
||||
onToggle: (index) {
|
||||
toggleSwitchIndex = index;
|
||||
if (index == null) {
|
||||
key.currentState?.setSelectedValues(List.empty());
|
||||
return;
|
||||
}
|
||||
|
||||
final iconFileExtArr =
|
||||
iconConfigMap[_toggleSwitchIcons[index]] ?? [];
|
||||
final selectedFileIndexes = widget.files
|
||||
.asMap()
|
||||
.entries
|
||||
.where(
|
||||
(e) => iconFileExtArr.contains(fileExt(e.value.name)))
|
||||
.map((e) => e.key)
|
||||
.toList();
|
||||
key.currentState?.setSelectedValues(selectedFileIndexes);
|
||||
},
|
||||
final iconFileExtArr =
|
||||
iconConfigMap[_toggleSwitchIcons[index]] ?? [];
|
||||
final selectedFileIndexes = widget.files
|
||||
.asMap()
|
||||
.entries
|
||||
.where((e) =>
|
||||
iconFileExtArr.contains(fileExt(e.value.name)))
|
||||
.map((e) => e.key)
|
||||
.toList();
|
||||
key.currentState?.setSelectedValues(selectedFileIndexes);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Text('fileSelectedCount'.tr),
|
||||
Text(
|
||||
selectedFileCount.toString(),
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Text('fileSelectedSize'.tr),
|
||||
Text(
|
||||
selectedFileCount > 0 && selectdFileSize == 0
|
||||
? 'unknown'.tr
|
||||
: Util.fmtByte(selectdFileSize),
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
Flexible(
|
||||
flex: 6,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Text('fileSelectedCount'.tr),
|
||||
Text(
|
||||
selectedFileCount.toString(),
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text('fileSelectedSize'.tr),
|
||||
Text(
|
||||
selectedFileCount > 0 && selectedFileSize == 0
|
||||
? 'unknown'.tr
|
||||
: Util.fmtByte(selectedFileSize),
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -241,7 +249,7 @@ class _FileTreeViewState extends State<FileTreeView> {
|
||||
return size > 0
|
||||
? Text(Util.fmtByte(calcSelectedSize(node)),
|
||||
style: Theme.of(context).textTheme.bodySmall)
|
||||
: const SizedBox();
|
||||
: const SizedBox(width: _sizeGapWidth);
|
||||
},
|
||||
children: [],
|
||||
);
|
||||
@@ -265,7 +273,7 @@ class _FileTreeViewState extends State<FileTreeView> {
|
||||
return file.size > 0
|
||||
? Text(Util.fmtByte(file.size),
|
||||
style: Theme.of(context).textTheme.bodySmall)
|
||||
: const SizedBox();
|
||||
: const SizedBox(width: _sizeGapWidth);
|
||||
},
|
||||
isSelected: widget.initialValues.contains(i),
|
||||
children: [],
|
||||
|
||||
@@ -149,10 +149,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: checkable_treeview
|
||||
sha256: e38cf0a1088b803707a1f0b271ac46210108aac81c2dad506d0d56e7932ab690
|
||||
sha256: "3d7543e2c93a968864a57ca0666fc3b5827d89d13b22cb637a427596032f9272"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.3.0"
|
||||
version: "1.3.1"
|
||||
checked_yaml:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -68,7 +68,7 @@ dependencies:
|
||||
toggle_switch: ^2.3.0
|
||||
permission_handler: ^11.3.1
|
||||
device_info_plus: ^9.1.2
|
||||
checkable_treeview: ^1.3.0
|
||||
checkable_treeview: ^1.3.1
|
||||
dependency_overrides:
|
||||
permission_handler_windows:
|
||||
git:
|
||||
|
||||
Reference in new issue
Block a user