feat: improve file_tree_view display on mobile (#862)

This commit is contained in:
Levi authored and GitHub committed 2024-12-30 20:35:39 +08:00
1 parent 107141bbe7
commit 1249493a8a
2 files changed
+61 -60

No files matched your search

@@ -1,5 +1,4 @@
import 'package:autoscale_tabbarview/autoscale_tabbarview.dart'; import 'package:autoscale_tabbarview/autoscale_tabbarview.dart';
import 'package:checkable_treeview/checkable_treeview.dart';
import 'package:desktop_drop/desktop_drop.dart'; import 'package:desktop_drop/desktop_drop.dart';
import 'package:file_picker/file_picker.dart'; import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@@ -17,7 +16,6 @@ import '../../../../database/database.dart';
import '../../../../util/input_formatter.dart'; import '../../../../util/input_formatter.dart';
import '../../../../util/message.dart'; import '../../../../util/message.dart';
import '../../../../util/util.dart'; import '../../../../util/util.dart';
import '../../../../util/extensions.dart';
import '../../../routes/app_pages.dart'; import '../../../routes/app_pages.dart';
import '../../../views/compact_checkbox.dart'; import '../../../views/compact_checkbox.dart';
import '../../../views/directory_selector.dart'; import '../../../views/directory_selector.dart';
@@ -42,7 +40,6 @@ class CreateView extends GetView<CreateController> {
final _httpCookieController = TextEditingController(); final _httpCookieController = TextEditingController();
final _httpRefererController = TextEditingController(); final _httpRefererController = TextEditingController();
final _btTrackerController = TextEditingController(); final _btTrackerController = TextEditingController();
final _fileTreeViewKey = GlobalKey<TreeViewState<int>>();
final _availableSchemes = ["http:", "https:", "magnet:"]; final _availableSchemes = ["http:", "https:", "magnet:"];
+61 -57
View File
@@ -7,6 +7,7 @@ import '../../api/model/resource.dart';
import '../../icon/gopeed_icons.dart'; import '../../icon/gopeed_icons.dart';
import '../../util/util.dart'; import '../../util/util.dart';
import 'file_icon.dart'; import 'file_icon.dart';
import 'responsive_builder.dart';
import 'sort_icon_button.dart'; import 'sort_icon_button.dart';
const _toggleSwitchIcons = [ const _toggleSwitchIcons = [
@@ -53,6 +54,52 @@ class _FileTreeViewState extends State<FileTreeView> {
widget.files.length; widget.files.length;
final selectedFileSize = calcSelectedSize(null); final selectedFileSize = calcSelectedSize(null);
final filterRow = 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 countRow = Row(
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,
),
],
);
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
@@ -141,66 +188,23 @@ class _FileTreeViewState extends State<FileTreeView> {
), ),
), ),
const SizedBox(height: 12), const SizedBox(height: 12),
Row( !ResponsiveBuilder.isNarrow(context)
mainAxisAlignment: MainAxisAlignment.spaceBetween, ? Row(
crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ crossAxisAlignment: CrossAxisAlignment.center,
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);
},
),
),
),
Flexible(
flex: 6,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [ children: [
Text('fileSelectedCount'.tr), filterRow,
Text( countRow,
selectedFileCount.toString(), ],
style: Theme.of(context).textTheme.bodySmall, )
), : Column(
const SizedBox(width: 12), crossAxisAlignment: CrossAxisAlignment.start,
Text('fileSelectedSize'.tr), children: [
Text( filterRow,
selectedFileCount > 0 && selectedFileSize == 0 const SizedBox(height: 8),
? 'unknown'.tr countRow,
: Util.fmtByte(selectedFileSize),
style: Theme.of(context).textTheme.bodySmall,
),
], ],
), ),
),
],
),
], ],
); );
} }