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,103 +157,127 @@ class _FileManagerPageState extends State<FileManagerPage>
children: [ children: [
Expanded( Expanded(
child: SingleChildScrollView( child: SingleChildScrollView(
child: DataTable( child: Obx(
key: ValueKey(isLocal ? 0 : 1), () {
showCheckboxColumn: true, final filteredEntries = entries.where((element) {
dataRowHeight: 25, if (isLocal) {
headingRowHeight: 30, if (searchTextLocal.isEmpty) {
columnSpacing: 8, return true;
showBottomBorder: true, } else {
sortColumnIndex: sortIndex, return element.name.contains(searchTextLocal.value);
sortAscending: sortAscending, }
columns: [ } else {
DataColumn(label: Text(translate(" "))), // icon if (searchTextRemote.isEmpty) {
DataColumn( return true;
label: Text( } else {
translate("Name"), return element.name.contains(searchTextRemote.value);
), }
onSort: (columnIndex, ascending) { }
model.changeSortStyle(SortBy.Name, }).toList(growable: false);
isLocal: isLocal, ascending: ascending); return DataTable(
}), key: ValueKey(isLocal ? 0 : 1),
DataColumn( showCheckboxColumn: true,
label: Text( dataRowHeight: 25,
translate("Modified"), headingRowHeight: 30,
), columnSpacing: 8,
onSort: (columnIndex, ascending) { showBottomBorder: true,
model.changeSortStyle(SortBy.Modified, sortColumnIndex: sortIndex,
isLocal: isLocal, ascending: ascending); sortAscending: sortAscending,
}), columns: [
DataColumn( DataColumn(label: Text(translate(" "))), // icon
label: Text(translate("Size")), DataColumn(
onSort: (columnIndex, ascending) { label: Text(
model.changeSortStyle(SortBy.Size, translate("Name"),
isLocal: isLocal, ascending: ascending); ),
}), onSort: (columnIndex, ascending) {
], model.changeSortStyle(SortBy.Name,
rows: entries.map((entry) { isLocal: isLocal, ascending: ascending);
final sizeStr = entry.isFile }),
? readableFileSize(entry.size.toDouble()) DataColumn(
: ""; label: Text(
return DataRow( translate("Modified"),
key: ValueKey(entry.name), ),
onSelectChanged: (s) { onSort: (columnIndex, ascending) {
if (s != null) { model.changeSortStyle(SortBy.Modified,
if (s) { isLocal: isLocal, ascending: ascending);
getSelectedItem(isLocal).add(isLocal, entry); }),
} else { DataColumn(
getSelectedItem(isLocal).remove(entry); label: Text(translate("Size")),
} onSort: (columnIndex, ascending) {
setState(() {}); model.changeSortStyle(SortBy.Size,
} isLocal: isLocal, ascending: ascending);
}, }),
selected: getSelectedItem(isLocal).contains(entry), ],
cells: [ rows: filteredEntries.map((entry) {
DataCell(Icon( final sizeStr = entry.isFile
entry.isFile ? Icons.feed_outlined : Icons.folder, ? readableFileSize(entry.size.toDouble())
size: 25)), : "";
DataCell( return DataRow(
ConstrainedBox( key: ValueKey(entry.name),
constraints: BoxConstraints(maxWidth: 100), onSelectChanged: (s) {
child: Tooltip( if (s != null) {
message: entry.name, if (s) {
child: Text(entry.name, getSelectedItem(isLocal).add(isLocal, entry);
overflow: TextOverflow.ellipsis), } else {
)), onTap: () { getSelectedItem(isLocal).remove(entry);
if (entry.isDirectory) { }
model.openDirectory(entry.path, isLocal: isLocal); setState(() {});
if (isLocal) {
_localSelectedItems.clear();
} else {
_remoteSelectedItems.clear();
} }
} else { },
// Perform file-related tasks. selected: getSelectedItem(isLocal).contains(entry),
final _selectedItems = getSelectedItem(isLocal); cells: [
if (_selectedItems.contains(entry)) { DataCell(Icon(
_selectedItems.remove(entry); entry.isFile
} else { ? Icons.feed_outlined
_selectedItems.add(isLocal, entry); : Icons.folder,
} size: 25)),
setState(() {}); DataCell(
} ConstrainedBox(
}), constraints:
DataCell(Text( BoxConstraints(maxWidth: 100),
entry child: Tooltip(
.lastModified() message: entry.name,
.toString() child: Text(entry.name,
.replaceAll(".000", "") + overflow: TextOverflow.ellipsis),
" ", )), onTap: () {
style: TextStyle( if (entry.isDirectory) {
fontSize: 12, color: MyTheme.darkGray), model.openDirectory(entry.path,
)), isLocal: isLocal);
DataCell(Text( if (isLocal) {
sizeStr, _localSelectedItems.clear();
style: TextStyle( } else {
fontSize: 12, color: MyTheme.darkGray), _remoteSelectedItems.clear();
)), }
]); } else {
}).toList(), // Perform file-related tasks.
final _selectedItems =
getSelectedItem(isLocal);
if (_selectedItems.contains(entry)) {
_selectedItems.remove(entry);
} else {
_selectedItems.add(isLocal, entry);
}
setState(() {});
}
}),
DataCell(Text(
entry
.lastModified()
.toString()
.replaceAll(".000", "") +
" ",
style: TextStyle(
fontSize: 12, color: MyTheme.darkGray),
)),
DataCell(Text(
sizeStr,
style: TextStyle(
fontSize: 12, color: MyTheme.darkGray),
)),
]);
}).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;
}
}
} }