feat: file transfer path scrollable

Signed-off-by: Kingtous <kingtous@qq.com>
This commit is contained in:
Kingtous 2022-08-16 12:28:12 +08:00
parent 2017a0f02b
commit eea62352d2

View File

@ -34,8 +34,14 @@ class _FileManagerPageState extends State<FileManagerPage>
FocusNode(debugLabel: "locationNodeLocal"); FocusNode(debugLabel: "locationNodeLocal");
final FocusNode _locationNodeRemote = final FocusNode _locationNodeRemote =
FocusNode(debugLabel: "locationNodeRemote"); FocusNode(debugLabel: "locationNodeRemote");
final searchTextLocal = "".obs; final _searchTextLocal = "".obs;
final searchTextRemote = "".obs; final _searchTextRemote = "".obs;
final _breadCrumbScrollerLocal = ScrollController();
final _breadCrumbScrollerRemote = ScrollController();
ScrollController getBreadCrumbScrollController(bool isLocal) {
return isLocal ? _breadCrumbScrollerLocal : _breadCrumbScrollerRemote;
}
late FFI _ffi; late FFI _ffi;
@ -159,19 +165,13 @@ class _FileManagerPageState extends State<FileManagerPage>
child: SingleChildScrollView( child: SingleChildScrollView(
child: Obx( child: Obx(
() { () {
final searchText =
isLocal ? _searchTextLocal : _searchTextRemote;
final filteredEntries = entries.where((element) { final filteredEntries = entries.where((element) {
if (isLocal) { if (searchText.isEmpty) {
if (searchTextLocal.isEmpty) {
return true; return true;
} else { } else {
return element.name.contains(searchTextLocal.value); return element.name.contains(searchText.value);
}
} else {
if (searchTextRemote.isEmpty) {
return true;
} else {
return element.name.contains(searchTextRemote.value);
}
} }
}).toList(growable: false); }).toList(growable: false);
return DataTable( return DataTable(
@ -241,8 +241,7 @@ class _FileManagerPageState extends State<FileManagerPage>
overflow: TextOverflow.ellipsis), overflow: TextOverflow.ellipsis),
)), onTap: () { )), onTap: () {
if (entry.isDirectory) { if (entry.isDirectory) {
model.openDirectory(entry.path, openDirectory(entry.path, isLocal: isLocal);
isLocal: isLocal);
if (isLocal) { if (isLocal) {
_localSelectedItems.clear(); _localSelectedItems.clear();
} else { } else {
@ -367,7 +366,7 @@ class _FileManagerPageState extends State<FileManagerPage>
// return; // return;
// } // }
// if (entries[index].isDirectory) { // if (entries[index].isDirectory) {
// model.openDirectory(entries[index].path, isLocal: isLocal); // openDirectory(entries[index].path, isLocal: isLocal);
// breadCrumbScrollToEnd(isLocal); // breadCrumbScrollToEnd(isLocal);
// } else { // } else {
// // Perform file-related tasks. // // Perform file-related tasks.
@ -492,7 +491,7 @@ class _FileManagerPageState extends State<FileManagerPage>
final _locationStatus = final _locationStatus =
isLocal ? _locationStatusLocal : _locationStatusRemote; isLocal ? _locationStatusLocal : _locationStatusRemote;
final _locationFocus = isLocal ? _locationNodeLocal : _locationNodeRemote; final _locationFocus = isLocal ? _locationNodeLocal : _locationNodeRemote;
final _searchTextObs = isLocal ? searchTextLocal : searchTextRemote; final _searchTextObs = isLocal ? _searchTextLocal : _searchTextRemote;
return Container( return Container(
child: Column( child: Column(
children: [ children: [
@ -579,7 +578,7 @@ class _FileManagerPageState extends State<FileManagerPage>
], ],
onChanged: (path) { onChanged: (path) {
if (path is String && path.isNotEmpty) { if (path is String && path.isNotEmpty) {
model.openDirectory(path, isLocal: isLocal); openDirectory(path, isLocal: isLocal);
} }
}) })
], ],
@ -762,9 +761,11 @@ class _FileManagerPageState extends State<FileManagerPage>
for (var item in list) { for (var item in list) {
path = PathUtil.join(path, item, model.getCurrentIsWindows(isLocal)); path = PathUtil.join(path, item, model.getCurrentIsWindows(isLocal));
} }
model.openDirectory(path, isLocal: isLocal); openDirectory(path, isLocal: isLocal);
}), }),
divider: Text("/").paddingSymmetric(horizontal: 4.0), divider: Text("/").paddingSymmetric(horizontal: 4.0),
overflow: ScrollableOverflow(
controller: getBreadCrumbScrollController(isLocal)),
); );
} }
@ -782,6 +783,16 @@ class _FileManagerPageState extends State<FileManagerPage>
return breadCrumbList; return breadCrumbList;
} }
breadCrumbScrollToEnd(bool isLocal) {
Future.delayed(Duration(milliseconds: 200), () {
final _breadCrumbScroller = getBreadCrumbScrollController(isLocal);
_breadCrumbScroller.animateTo(
_breadCrumbScroller.position.maxScrollExtent,
duration: Duration(milliseconds: 200),
curve: Curves.fastLinearToSlowEaseIn);
});
}
Widget buildPathLocation(bool isLocal) { Widget buildPathLocation(bool isLocal) {
return TextField( return TextField(
focusNode: isLocal ? _locationNodeLocal : _locationNodeRemote, focusNode: isLocal ? _locationNodeLocal : _locationNodeRemote,
@ -793,16 +804,23 @@ class _FileManagerPageState extends State<FileManagerPage>
controller: controller:
TextEditingController(text: model.getCurrentDir(isLocal).path), TextEditingController(text: model.getCurrentDir(isLocal).path),
onSubmitted: (path) { onSubmitted: (path) {
model.openDirectory(path, isLocal: isLocal); openDirectory(path, isLocal: isLocal);
}, },
); );
} }
onSearchText(String searchText, bool isLocal) { onSearchText(String searchText, bool isLocal) {
if (isLocal) { if (isLocal) {
searchTextLocal.value = searchText; _searchTextLocal.value = searchText;
} else { } else {
searchTextRemote.value = searchText; _searchTextRemote.value = searchText;
} }
} }
openDirectory(String path, {bool isLocal = false}) {
model.openDirectory(path, isLocal: isLocal).then((_) {
print("scroll");
breadCrumbScrollToEnd(isLocal);
});
}
} }