mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 10:47:25 +01:00
Files chooser: Add search
This commit is contained in:
parent
d53b3bfce9
commit
ef40b4cd06
1 changed files with 51 additions and 19 deletions
|
|
@ -37,11 +37,26 @@ class FilesSelector extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _FilesSelectorState extends State<FilesSelector> {
|
||||
final _searchController = TextEditingController();
|
||||
|
||||
MusicusBackendState backend;
|
||||
List<Document> history = [];
|
||||
List<Document> children = [];
|
||||
Set<Document> selection = {};
|
||||
|
||||
String _search = '';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_searchController.addListener(() {
|
||||
setState(() {
|
||||
_search = _searchController.text;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
|
|
@ -52,6 +67,11 @@ class _FilesSelectorState extends State<FilesSelector> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final title = history.isNotEmpty ? history.last.name : 'base path';
|
||||
final filteredChildren = children
|
||||
.where((d) => d.name.toLowerCase().contains(_search.toLowerCase()))
|
||||
.toList();
|
||||
|
||||
return WillPopScope(
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
|
|
@ -88,27 +108,38 @@ class _FilesSelectorState extends State<FilesSelector> {
|
|||
icon: const Icon(Icons.arrow_upward),
|
||||
onPressed: history.isNotEmpty ? up : null,
|
||||
),
|
||||
title: Text(
|
||||
history.isNotEmpty ? history.last.name : 'Music library'),
|
||||
title: TextField(
|
||||
autofocus: true,
|
||||
controller: _searchController,
|
||||
decoration: InputDecoration.collapsed(
|
||||
hintText: 'Search in $title...'),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: children.length,
|
||||
itemCount: filteredChildren.length,
|
||||
itemBuilder: (context, index) {
|
||||
final document = children[index];
|
||||
final document = filteredChildren[index];
|
||||
|
||||
if (document.isDirectory) {
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.folder),
|
||||
title: Text(document.name),
|
||||
onTap: () {
|
||||
_searchController.text = '';
|
||||
setState(() {
|
||||
history.add(document);
|
||||
});
|
||||
loadChildren();
|
||||
},
|
||||
);
|
||||
} else {
|
||||
if (widget.chooseDirectory) {
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.insert_drive_file),
|
||||
title: Text(document.name),
|
||||
);
|
||||
} else {
|
||||
return CheckboxListTile(
|
||||
controlAffinity: ListTileControlAffinity.trailing,
|
||||
|
|
@ -126,6 +157,7 @@ class _FilesSelectorState extends State<FilesSelector> {
|
|||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue