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> {
String? stepmaniaCoursesPath;
List<Simfile> stepmaniaCoursesFolders = [];
List<Simfile> stepmaniaCoursesFoldersFiltered = [];
String searchString = '';
@override
void initState() {
@ -27,7 +29,6 @@ class _LevelSelectionState extends State<LevelSelection> {
loadFolderPath();
}
Future<void> loadFolderPath() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
final String? stepmaniaCoursesPathSetting =
@ -40,6 +41,7 @@ class _LevelSelectionState extends State<LevelSelection> {
setState(() {
stepmaniaCoursesPath = stepmaniaCoursesPathSetting;
stepmaniaCoursesFolders = stepmaniaCoursesFoldersFuture;
stepmaniaCoursesFoldersFiltered = stepmaniaCoursesFoldersFuture;
});
}
@ -68,7 +70,7 @@ class _LevelSelectionState extends State<LevelSelection> {
simfile.load();
return simfile;
}).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;
} catch (e) {
@ -104,24 +106,48 @@ class _LevelSelectionState extends State<LevelSelection> {
return Text(
'Folder empty. Add Stepmania Songs to Folder or select a different folder on \'+\'');
} else {
return ListView.separated(
itemCount: stepmaniaCoursesFolders.length,
return Column(
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) =>
const Divider(),
itemBuilder: (context, index) {
Simfile simfile = stepmaniaCoursesFoldersFiltered[index];
return ListTile(
leading: Image.file(
File(stepmaniaCoursesFolders[index].bannerPath!)),
leading: Image.file(File(simfile.bannerPath!)),
trailing: Icon(Icons.play_arrow),
title: Text(stepmaniaCoursesFolders[index].tags["TITLE"]!),
title: Text(simfile.tags["TITLE"]!),
subtitle: Text('3:45'),
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) =>
Level(stepmaniaCoursesFolders[index]))),
Level(simfile))),
);
},
),
),
],
);
}
}),