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