mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
before del file_manager pub
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:file_manager/file_manager.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:flutter_hbb/models/file_model.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter_breadcrumb/flutter_breadcrumb.dart';
|
||||
|
||||
import '../common.dart';
|
||||
import '../models/model.dart';
|
||||
@@ -24,6 +26,10 @@ class _FileManagerPageState extends State<FileManagerPage> {
|
||||
Timer? _timer;
|
||||
var _reconnects = 1;
|
||||
var _isLocal = false;
|
||||
var _selectMode = false;
|
||||
final List<String> _selectedItems = [];
|
||||
|
||||
// final _breadCrumbScrollController = ScrollController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -36,8 +42,8 @@ class _FileManagerPageState extends State<FileManagerPage> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_localFileModel.dispose();
|
||||
_remoteFileModel.dispose();
|
||||
_localFileModel.dispose();
|
||||
_interval?.cancel();
|
||||
FFI.close();
|
||||
EasyLoading.dismiss();
|
||||
@@ -49,6 +55,7 @@ class _FileManagerPageState extends State<FileManagerPage> {
|
||||
return ChangeNotifierProvider.value(
|
||||
value: _remoteFileModel,
|
||||
child: Scaffold(
|
||||
backgroundColor: MyTheme.grayBg,
|
||||
appBar: AppBar(
|
||||
leading: Row(children: [
|
||||
IconButton(icon: Icon(Icons.arrow_back), onPressed: goBack),
|
||||
@@ -65,43 +72,89 @@ class _FileManagerPageState extends State<FileManagerPage> {
|
||||
})),
|
||||
],
|
||||
),
|
||||
body:
|
||||
Consumer<RemoteFileModel>(builder: (context, remoteModel, child) {
|
||||
return FileManager(
|
||||
controller: _localFileModel,
|
||||
builder: (context, localSnapshot) {
|
||||
final snapshot = _isLocal
|
||||
? localSnapshot
|
||||
: remoteModel.currentRemoteDir.entries;
|
||||
return ListView.builder(
|
||||
itemCount: snapshot.length,
|
||||
itemBuilder: (context, index) {
|
||||
return Card(
|
||||
child: ListTile(
|
||||
leading: FileManager.isFile(snapshot[index])
|
||||
? Icon(Icons.feed_outlined)
|
||||
: Icon(Icons.folder),
|
||||
title: Text(FileManager.basename(snapshot[index])),
|
||||
onTap: () {
|
||||
if (FileManager.isDirectory(snapshot[index])) {
|
||||
_isLocal
|
||||
? _localFileModel
|
||||
.openDirectory(snapshot[index])
|
||||
: readRemoteDir(
|
||||
snapshot[index].path); // open directory
|
||||
} else {
|
||||
// Perform file-related tasks.
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
}),
|
||||
body: body(),
|
||||
bottomSheet: bottomSheet(),
|
||||
));
|
||||
}
|
||||
|
||||
Widget body() => Consumer<RemoteFileModel>(
|
||||
builder: (context, remoteModel, _child) => FileManager(
|
||||
controller: _localFileModel,
|
||||
emptyFolder: emptyPage(),
|
||||
builder: (context, localSnapshot) {
|
||||
final snapshot =
|
||||
_isLocal ? localSnapshot : remoteModel.currentRemoteDir.entries;
|
||||
return Column(children: [
|
||||
headTools(),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: snapshot.length + 1,
|
||||
itemBuilder: (context, index) {
|
||||
if (index >= snapshot.length) {
|
||||
// 添加尾部信息 文件统计信息等
|
||||
// 添加快速返回上部
|
||||
// 使用 bottomSheet 提示以选择的文件数量 点击后展开查看更多
|
||||
return listTail();
|
||||
}
|
||||
|
||||
var isFile = false;
|
||||
if (_isLocal){
|
||||
isFile = FileManager.isFile(snapshot[index]);
|
||||
}else {
|
||||
isFile = (snapshot[index] as RemoteFileSystemEntity).isFile();
|
||||
}
|
||||
|
||||
final path = snapshot[index].path;
|
||||
var selected = false;
|
||||
if (_selectMode) {
|
||||
selected = _selectedItems.any((e) => e == path);
|
||||
}
|
||||
return Card(
|
||||
child: ListTile(
|
||||
leading: isFile
|
||||
? Icon(Icons.feed_outlined)
|
||||
: Icon(Icons.folder),
|
||||
title: Text(FileManager.basename(snapshot[index])),
|
||||
trailing: _selectMode
|
||||
? Checkbox(
|
||||
value: selected,
|
||||
onChanged: (v) {
|
||||
if (v == null) return;
|
||||
if (v && !selected) {
|
||||
setState(() {
|
||||
_selectedItems.add(path);
|
||||
});
|
||||
} else if (!v && selected) {
|
||||
setState(() {
|
||||
_selectedItems.remove(path);
|
||||
});
|
||||
}
|
||||
})
|
||||
: null,
|
||||
onTap: () {
|
||||
if (!isFile) {
|
||||
if (_isLocal) {
|
||||
_localFileModel.openDirectory(snapshot[index]);
|
||||
} else {
|
||||
readRemoteDir(path);
|
||||
}
|
||||
} else {
|
||||
// Perform file-related tasks.
|
||||
}
|
||||
},
|
||||
onLongPress: () {
|
||||
setState(() {
|
||||
_selectedItems.clear();
|
||||
_selectMode = !_selectMode;
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
))
|
||||
]);
|
||||
}));
|
||||
|
||||
goBack() {
|
||||
if (_isLocal) {
|
||||
_localFileModel.goToParentDirectory();
|
||||
@@ -142,4 +195,144 @@ class _FileManagerPageState extends State<FileManagerPage> {
|
||||
_reconnects = 1;
|
||||
}
|
||||
}
|
||||
|
||||
Widget headTools() => Container(
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: BreadCrumb(
|
||||
items: getPathBreadCrumbItems(() => debugPrint("pressed home"),
|
||||
(e) => debugPrint("pressed url:$e")),
|
||||
divider: Icon(Icons.chevron_right),
|
||||
overflow: ScrollableOverflow(reverse: false), // TODO 计算容器宽度判断
|
||||
)),
|
||||
Row(
|
||||
children: [
|
||||
// IconButton(onPressed: () {}, icon: Icon(Icons.sort)),
|
||||
PopupMenuButton<SortBy>(
|
||||
icon: Icon(Icons.sort),
|
||||
itemBuilder: (context) {
|
||||
return SortBy.values.map((e) => PopupMenuItem(
|
||||
child: Text(translate(e.toString().split(".").last)),
|
||||
value: e,
|
||||
)).toList();
|
||||
},
|
||||
onSelected: changeSortStyle),
|
||||
IconButton(onPressed: () {}, icon: Icon(Icons.more_vert)),
|
||||
],
|
||||
)
|
||||
],
|
||||
));
|
||||
|
||||
changeSortStyle(SortBy sort){
|
||||
if(_isLocal){
|
||||
_localFileModel.sortedBy = sort;
|
||||
}else{
|
||||
_remoteFileModel.changeSortStyle(sort);
|
||||
}
|
||||
}
|
||||
|
||||
Widget emptyPage() {
|
||||
return Column(
|
||||
children: [
|
||||
headTools(),
|
||||
Expanded(child: Center(child: Text("Empty Directory")))
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget listTail() {
|
||||
return SizedBox(height: 100);
|
||||
}
|
||||
|
||||
BottomSheet? bottomSheet() {
|
||||
if (!_selectMode) return null;
|
||||
return BottomSheet(
|
||||
backgroundColor: MyTheme.grayBg,
|
||||
enableDrag: false,
|
||||
onClosing: () {
|
||||
debugPrint("BottomSheet close");
|
||||
},
|
||||
builder: (context) {
|
||||
return Container(
|
||||
height: 65,
|
||||
alignment: Alignment.centerLeft,
|
||||
decoration: BoxDecoration(
|
||||
color: MyTheme.accent50,
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(10))),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 15),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.check),
|
||||
SizedBox(width: 5),
|
||||
Text(
|
||||
"已选择 ${_selectedItems.length}",
|
||||
style: TextStyle(fontSize: 18),
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.paste),
|
||||
onPressed: () {},
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.delete_forever),
|
||||
onPressed: () {},
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.cancel_outlined),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_selectMode = false;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
List<BreadCrumbItem> getPathBreadCrumbItems(
|
||||
void Function() onHome, void Function(String) onPressed) {
|
||||
final path = _isLocal
|
||||
? _localFileModel.getCurrentPath
|
||||
: _remoteFileModel.currentRemoteDir.path;
|
||||
final list = path.trim().split('/');
|
||||
list.remove("");
|
||||
final breadCrumbList = [
|
||||
BreadCrumbItem(
|
||||
content: IconButton(
|
||||
icon: Icon(Icons.home_filled),
|
||||
onPressed: onHome,
|
||||
))
|
||||
];
|
||||
breadCrumbList.addAll(list.map((e) => BreadCrumbItem(
|
||||
content: TextButton(
|
||||
child: Text(e),
|
||||
style:
|
||||
ButtonStyle(minimumSize: MaterialStateProperty.all(Size(0, 0))),
|
||||
onPressed: () => onPressed(e)))));
|
||||
return breadCrumbList;
|
||||
}
|
||||
|
||||
// // NOT GOOD
|
||||
// void breadCrumbToLast() {
|
||||
// try {
|
||||
// _breadCrumbScrollController.animateTo(
|
||||
// _breadCrumbScrollController.position.maxScrollExtent,
|
||||
// curve: Curves.easeOut,
|
||||
// duration: const Duration(milliseconds: 300),
|
||||
// );
|
||||
// } catch (e) {}
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user