feat: file transfer searchbar

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

View File

@ -34,10 +34,8 @@ class _FileManagerPageState extends State<FileManagerPage>
FocusNode(debugLabel: "locationNodeLocal");
final FocusNode _locationNodeRemote =
FocusNode(debugLabel: "locationNodeRemote");
final FocusNode _locationSearchLocal =
FocusNode(debugLabel: "locationSearchLocal");
final FocusNode _locationSearchRemote =
FocusNode(debugLabel: "locationSearchRemote");
final searchTextLocal = "".obs;
final searchTextRemote = "".obs;
late FFI _ffi;
@ -131,7 +129,7 @@ class _FileManagerPageState extends State<FileManagerPage>
}
Widget body({bool isLocal = false}) {
final fd = isLocal ? model.currentLocalDir : model.currentRemoteDir;
final fd = model.getCurrentDir(isLocal);
final entries = fd.entries;
final sortIndex = (SortBy style) {
switch (style) {
@ -159,7 +157,24 @@ class _FileManagerPageState extends State<FileManagerPage>
children: [
Expanded(
child: SingleChildScrollView(
child: DataTable(
child: Obx(
() {
final filteredEntries = entries.where((element) {
if (isLocal) {
if (searchTextLocal.isEmpty) {
return true;
} else {
return element.name.contains(searchTextLocal.value);
}
} else {
if (searchTextRemote.isEmpty) {
return true;
} else {
return element.name.contains(searchTextRemote.value);
}
}
}).toList(growable: false);
return DataTable(
key: ValueKey(isLocal ? 0 : 1),
showCheckboxColumn: true,
dataRowHeight: 25,
@ -193,7 +208,7 @@ class _FileManagerPageState extends State<FileManagerPage>
isLocal: isLocal, ascending: ascending);
}),
],
rows: entries.map((entry) {
rows: filteredEntries.map((entry) {
final sizeStr = entry.isFile
? readableFileSize(entry.size.toDouble())
: "";
@ -212,18 +227,22 @@ class _FileManagerPageState extends State<FileManagerPage>
selected: getSelectedItem(isLocal).contains(entry),
cells: [
DataCell(Icon(
entry.isFile ? Icons.feed_outlined : Icons.folder,
entry.isFile
? Icons.feed_outlined
: Icons.folder,
size: 25)),
DataCell(
ConstrainedBox(
constraints: BoxConstraints(maxWidth: 100),
constraints:
BoxConstraints(maxWidth: 100),
child: Tooltip(
message: entry.name,
child: Text(entry.name,
overflow: TextOverflow.ellipsis),
)), onTap: () {
if (entry.isDirectory) {
model.openDirectory(entry.path, isLocal: isLocal);
model.openDirectory(entry.path,
isLocal: isLocal);
if (isLocal) {
_localSelectedItems.clear();
} else {
@ -231,7 +250,8 @@ class _FileManagerPageState extends State<FileManagerPage>
}
} else {
// Perform file-related tasks.
final _selectedItems = getSelectedItem(isLocal);
final _selectedItems =
getSelectedItem(isLocal);
if (_selectedItems.contains(entry)) {
_selectedItems.remove(entry);
} else {
@ -256,6 +276,8 @@ class _FileManagerPageState extends State<FileManagerPage>
)),
]);
}).toList(),
);
},
),
),
)
@ -401,7 +423,6 @@ class _FileManagerPageState extends State<FileManagerPage>
child: Text(
'${item.jobName}',
maxLines: 1,
style: TextStyle(color: Colors.black45),
overflow: TextOverflow.ellipsis,
)),
Wrap(
@ -471,6 +492,7 @@ class _FileManagerPageState extends State<FileManagerPage>
final _locationStatus =
isLocal ? _locationStatusLocal : _locationStatusRemote;
final _locationFocus = isLocal ? _locationNodeLocal : _locationNodeRemote;
final _searchTextObs = isLocal ? searchTextLocal : searchTextRemote;
return Container(
child: Column(
children: [
@ -570,7 +592,13 @@ class _FileManagerPageState extends State<FileManagerPage>
child: ConstrainedBox(
constraints: BoxConstraints(minWidth: 200),
child: TextField(
decoration: InputDecoration(),
controller:
TextEditingController(text: _searchTextObs.value),
autofocus: true,
decoration:
InputDecoration(prefixIcon: Icon(Icons.search)),
onChanged: (searchText) =>
onSearchText(searchText, isLocal),
),
))
],
@ -769,4 +797,12 @@ class _FileManagerPageState extends State<FileManagerPage>
},
);
}
onSearchText(String searchText, bool isLocal) {
if (isLocal) {
searchTextLocal.value = searchText;
} else {
searchTextRemote.value = searchText;
}
}
}