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> {
|
class _FilesSelectorState extends State<FilesSelector> {
|
||||||
|
final _searchController = TextEditingController();
|
||||||
|
|
||||||
MusicusBackendState backend;
|
MusicusBackendState backend;
|
||||||
List<Document> history = [];
|
List<Document> history = [];
|
||||||
List<Document> children = [];
|
List<Document> children = [];
|
||||||
Set<Document> selection = {};
|
Set<Document> selection = {};
|
||||||
|
|
||||||
|
String _search = '';
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
_searchController.addListener(() {
|
||||||
|
setState(() {
|
||||||
|
_search = _searchController.text;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
|
|
@ -52,6 +67,11 @@ class _FilesSelectorState extends State<FilesSelector> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
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(
|
return WillPopScope(
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
|
|
@ -88,27 +108,38 @@ class _FilesSelectorState extends State<FilesSelector> {
|
||||||
icon: const Icon(Icons.arrow_upward),
|
icon: const Icon(Icons.arrow_upward),
|
||||||
onPressed: history.isNotEmpty ? up : null,
|
onPressed: history.isNotEmpty ? up : null,
|
||||||
),
|
),
|
||||||
title: Text(
|
title: TextField(
|
||||||
history.isNotEmpty ? history.last.name : 'Music library'),
|
autofocus: true,
|
||||||
|
controller: _searchController,
|
||||||
|
decoration: InputDecoration.collapsed(
|
||||||
|
hintText: 'Search in $title...'),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
itemCount: children.length,
|
itemCount: filteredChildren.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final document = children[index];
|
final document = filteredChildren[index];
|
||||||
|
|
||||||
if (document.isDirectory) {
|
if (document.isDirectory) {
|
||||||
return ListTile(
|
return ListTile(
|
||||||
leading: const Icon(Icons.folder),
|
leading: const Icon(Icons.folder),
|
||||||
title: Text(document.name),
|
title: Text(document.name),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
|
_searchController.text = '';
|
||||||
setState(() {
|
setState(() {
|
||||||
history.add(document);
|
history.add(document);
|
||||||
});
|
});
|
||||||
loadChildren();
|
loadChildren();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
if (widget.chooseDirectory) {
|
||||||
|
return ListTile(
|
||||||
|
leading: const Icon(Icons.insert_drive_file),
|
||||||
|
title: Text(document.name),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return CheckboxListTile(
|
return CheckboxListTile(
|
||||||
controlAffinity: ListTileControlAffinity.trailing,
|
controlAffinity: ListTileControlAffinity.trailing,
|
||||||
|
|
@ -126,6 +157,7 @@ class _FilesSelectorState extends State<FilesSelector> {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue