feat: add searchBar to level selection

This commit is contained in:
Orangerot 2025-01-10 20:55:03 +01:00
parent 3682fa551a
commit 86dfc815cd

View file

@ -20,6 +20,8 @@ class LevelSelection extends StatefulWidget {
class _LevelSelectionState extends State<LevelSelection> { class _LevelSelectionState extends State<LevelSelection> {
String? stepmaniaCoursesPath; String? stepmaniaCoursesPath;
List<Simfile> stepmaniaCoursesFolders = []; List<Simfile> stepmaniaCoursesFolders = [];
List<Simfile> stepmaniaCoursesFoldersFiltered = [];
String searchString = '';
@override @override
void initState() { void initState() {
@ -27,7 +29,6 @@ class _LevelSelectionState extends State<LevelSelection> {
loadFolderPath(); loadFolderPath();
} }
Future<void> loadFolderPath() async { Future<void> loadFolderPath() async {
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferences prefs = await SharedPreferences.getInstance();
final String? stepmaniaCoursesPathSetting = final String? stepmaniaCoursesPathSetting =
@ -40,6 +41,7 @@ class _LevelSelectionState extends State<LevelSelection> {
setState(() { setState(() {
stepmaniaCoursesPath = stepmaniaCoursesPathSetting; stepmaniaCoursesPath = stepmaniaCoursesPathSetting;
stepmaniaCoursesFolders = stepmaniaCoursesFoldersFuture; stepmaniaCoursesFolders = stepmaniaCoursesFoldersFuture;
stepmaniaCoursesFoldersFiltered = stepmaniaCoursesFoldersFuture;
}); });
} }
@ -68,7 +70,7 @@ class _LevelSelectionState extends State<LevelSelection> {
simfile.load(); simfile.load();
return simfile; return simfile;
}).toList(); }).toList();
simfiles.sort((a,b) => a.tags['TITLE']!.compareTo(b.tags['TITLE']!)); simfiles.sort((a, b) => a.tags['TITLE']!.compareTo(b.tags['TITLE']!));
return simfiles; return simfiles;
} catch (e) { } catch (e) {
@ -104,24 +106,48 @@ class _LevelSelectionState extends State<LevelSelection> {
return Text( return Text(
'Folder empty. Add Stepmania Songs to Folder or select a different folder on \'+\''); 'Folder empty. Add Stepmania Songs to Folder or select a different folder on \'+\'');
} else { } else {
return ListView.separated( return Column(
itemCount: stepmaniaCoursesFolders.length, children: [
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 0.0),
child: TextField(
onChanged: (input) {
setState(() {
stepmaniaCoursesFoldersFiltered = stepmaniaCoursesFolders
.where((simfile) => simfile.tags["TITLE"]!
.toLowerCase()
.contains(input.toLowerCase()))
.toList();
});
},
decoration: InputDecoration(
// icon: Icon(Icons.search),
hintText: 'Search'),
),
),
Expanded(
child: ListView.separated(
itemCount: stepmaniaCoursesFoldersFiltered.length,
separatorBuilder: (BuildContext context, int index) => separatorBuilder: (BuildContext context, int index) =>
const Divider(), const Divider(),
itemBuilder: (context, index) { itemBuilder: (context, index) {
Simfile simfile = stepmaniaCoursesFoldersFiltered[index];
return ListTile( return ListTile(
leading: Image.file( leading: Image.file(File(simfile.bannerPath!)),
File(stepmaniaCoursesFolders[index].bannerPath!)),
trailing: Icon(Icons.play_arrow), trailing: Icon(Icons.play_arrow),
title: Text(stepmaniaCoursesFolders[index].tags["TITLE"]!), title: Text(simfile.tags["TITLE"]!),
subtitle: Text('3:45'), subtitle: Text('3:45'),
onTap: () => Navigator.push( onTap: () => Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (BuildContext context) => builder: (BuildContext context) =>
Level(stepmaniaCoursesFolders[index]))), Level(simfile))),
); );
}, },
),
),
],
); );
} }
}), }),