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