feat: drop to send files to remote

Signed-off-by: Kingtous <kingtous@qq.com>
This commit is contained in:
Kingtous 2022-08-16 13:28:48 +08:00
parent 4bd5fe1509
commit a001b15335
4 changed files with 268 additions and 232 deletions

View File

@ -1,6 +1,7 @@
import 'dart:io';
import 'dart:math';
import 'package:desktop_drop/desktop_drop.dart';
import 'package:flutter/material.dart';
import 'package:flutter_breadcrumb/flutter_breadcrumb.dart';
import 'package:flutter_hbb/mobile/pages/file_manager_page.dart';
@ -39,6 +40,8 @@ class _FileManagerPageState extends State<FileManagerPage>
final _breadCrumbScrollerLocal = ScrollController();
final _breadCrumbScrollerRemote = ScrollController();
final _dropMaskVisible = false.obs;
ScrollController getBreadCrumbScrollController(bool isLocal) {
return isLocal ? _breadCrumbScrollerLocal : _breadCrumbScrollerRemote;
}
@ -155,6 +158,14 @@ class _FileManagerPageState extends State<FileManagerPage>
decoration: BoxDecoration(border: Border.all(color: Colors.black26)),
margin: const EdgeInsets.all(16.0),
padding: const EdgeInsets.all(8.0),
child: DropTarget(
onDragDone: (detail) => handleDragDone(detail, isLocal),
onDragEntered: (enter) {
_dropMaskVisible.value = true;
},
onDragExited: (exit) {
_dropMaskVisible.value = false;
},
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
headTools(isLocal),
Expanded(
@ -163,19 +174,14 @@ class _FileManagerPageState extends State<FileManagerPage>
children: [
Expanded(
child: SingleChildScrollView(
child: entries.isEmpty
? Offstage()
: Obx(
() {
final searchText =
isLocal ? _searchTextLocal : _searchTextRemote;
child: ObxValue<RxString>(
(searchText) {
final filteredEntries = searchText.isEmpty
? entries.where((element) {
if (searchText.isEmpty) {
return true;
} else {
return element.name
.contains(searchText.value);
return element.name.contains(searchText.value);
}
}).toList(growable: false)
: entries;
@ -222,14 +228,16 @@ class _FileManagerPageState extends State<FileManagerPage>
onSelectChanged: (s) {
if (s != null) {
if (s) {
getSelectedItem(isLocal).add(isLocal, entry);
getSelectedItem(isLocal)
.add(isLocal, entry);
} else {
getSelectedItem(isLocal).remove(entry);
}
setState(() {});
}
},
selected: getSelectedItem(isLocal).contains(entry),
selected:
getSelectedItem(isLocal).contains(entry),
cells: [
DataCell(Icon(
entry.isFile
@ -271,19 +279,18 @@ class _FileManagerPageState extends State<FileManagerPage>
.replaceAll(".000", "") +
" ",
style: TextStyle(
fontSize: 12,
color: MyTheme.darkGray),
fontSize: 12, color: MyTheme.darkGray),
)),
DataCell(Text(
sizeStr,
style: TextStyle(
fontSize: 12,
color: MyTheme.darkGray),
fontSize: 12, color: MyTheme.darkGray),
)),
]);
}).toList(growable: false),
);
},
isLocal ? _searchTextLocal : _searchTextRemote,
),
),
)
@ -392,6 +399,7 @@ class _FileManagerPageState extends State<FileManagerPage>
// },
// ))
]),
),
);
}
@ -831,4 +839,23 @@ class _FileManagerPageState extends State<FileManagerPage>
breadCrumbScrollToEnd(isLocal);
});
}
void handleDragDone(DropDoneDetails details, bool isLocal) {
if (isLocal) {
// ignore local
return;
}
var items = SelectedItems();
details.files.forEach((file) {
final f = File(file.path);
items.add(
true,
Entry()
..path = file.path
..name = file.name
..size =
FileSystemEntity.isDirectorySync(f.path) ? 0 : f.lengthSync());
});
model.sendFiles(items, isRemote: false);
}
}

View File

@ -732,6 +732,7 @@ class FileModel extends ChangeNotifier {
job.totalSize = total_size.toInt();
}
debugPrint("update folder files: ${info}");
notifyListeners();
}
bool get remoteSortAscending => _remoteSortAscending;

View File

@ -239,6 +239,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.12"
desktop_drop:
dependency: "direct main"
description:
name: desktop_drop
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.3"
desktop_multi_window:
dependency: "direct main"
description:
@ -817,7 +824,7 @@ packages:
name: qr_code_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
version: "1.0.1"
quiver:
dependency: transitive
description:

View File

@ -69,6 +69,7 @@ dependencies:
get: ^4.6.5
visibility_detector: ^0.3.3
contextmenu: ^3.0.0
desktop_drop: ^0.3.3
dev_dependencies:
flutter_launcher_icons: ^0.9.1