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:io';
import 'dart:math'; import 'dart:math';
import 'package:desktop_drop/desktop_drop.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_breadcrumb/flutter_breadcrumb.dart'; import 'package:flutter_breadcrumb/flutter_breadcrumb.dart';
import 'package:flutter_hbb/mobile/pages/file_manager_page.dart'; import 'package:flutter_hbb/mobile/pages/file_manager_page.dart';
@ -39,6 +40,8 @@ class _FileManagerPageState extends State<FileManagerPage>
final _breadCrumbScrollerLocal = ScrollController(); final _breadCrumbScrollerLocal = ScrollController();
final _breadCrumbScrollerRemote = ScrollController(); final _breadCrumbScrollerRemote = ScrollController();
final _dropMaskVisible = false.obs;
ScrollController getBreadCrumbScrollController(bool isLocal) { ScrollController getBreadCrumbScrollController(bool isLocal) {
return isLocal ? _breadCrumbScrollerLocal : _breadCrumbScrollerRemote; return isLocal ? _breadCrumbScrollerLocal : _breadCrumbScrollerRemote;
} }
@ -155,6 +158,14 @@ class _FileManagerPageState extends State<FileManagerPage>
decoration: BoxDecoration(border: Border.all(color: Colors.black26)), decoration: BoxDecoration(border: Border.all(color: Colors.black26)),
margin: const EdgeInsets.all(16.0), margin: const EdgeInsets.all(16.0),
padding: const EdgeInsets.all(8.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: [ child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
headTools(isLocal), headTools(isLocal),
Expanded( Expanded(
@ -163,19 +174,14 @@ class _FileManagerPageState extends State<FileManagerPage>
children: [ children: [
Expanded( Expanded(
child: SingleChildScrollView( child: SingleChildScrollView(
child: entries.isEmpty child: ObxValue<RxString>(
? Offstage() (searchText) {
: Obx(
() {
final searchText =
isLocal ? _searchTextLocal : _searchTextRemote;
final filteredEntries = searchText.isEmpty final filteredEntries = searchText.isEmpty
? entries.where((element) { ? entries.where((element) {
if (searchText.isEmpty) { if (searchText.isEmpty) {
return true; return true;
} else { } else {
return element.name return element.name.contains(searchText.value);
.contains(searchText.value);
} }
}).toList(growable: false) }).toList(growable: false)
: entries; : entries;
@ -222,14 +228,16 @@ class _FileManagerPageState extends State<FileManagerPage>
onSelectChanged: (s) { onSelectChanged: (s) {
if (s != null) { if (s != null) {
if (s) { if (s) {
getSelectedItem(isLocal).add(isLocal, entry); getSelectedItem(isLocal)
.add(isLocal, entry);
} else { } else {
getSelectedItem(isLocal).remove(entry); getSelectedItem(isLocal).remove(entry);
} }
setState(() {}); setState(() {});
} }
}, },
selected: getSelectedItem(isLocal).contains(entry), selected:
getSelectedItem(isLocal).contains(entry),
cells: [ cells: [
DataCell(Icon( DataCell(Icon(
entry.isFile entry.isFile
@ -271,19 +279,18 @@ class _FileManagerPageState extends State<FileManagerPage>
.replaceAll(".000", "") + .replaceAll(".000", "") +
" ", " ",
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: 12, color: MyTheme.darkGray),
color: MyTheme.darkGray),
)), )),
DataCell(Text( DataCell(Text(
sizeStr, sizeStr,
style: TextStyle( style: TextStyle(
fontSize: 12, fontSize: 12, color: MyTheme.darkGray),
color: MyTheme.darkGray),
)), )),
]); ]);
}).toList(growable: false), }).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); 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(); job.totalSize = total_size.toInt();
} }
debugPrint("update folder files: ${info}"); debugPrint("update folder files: ${info}");
notifyListeners();
} }
bool get remoteSortAscending => _remoteSortAscending; bool get remoteSortAscending => _remoteSortAscending;

View File

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

View File

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