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: [
separatorBuilder: (BuildContext context, int index) => Padding(
const Divider(), padding:
itemBuilder: (context, index) { const EdgeInsets.symmetric(horizontal: 16.0, vertical: 0.0),
return ListTile( child: TextField(
leading: Image.file( onChanged: (input) {
File(stepmaniaCoursesFolders[index].bannerPath!)), setState(() {
trailing: Icon(Icons.play_arrow), stepmaniaCoursesFoldersFiltered = stepmaniaCoursesFolders
title: Text(stepmaniaCoursesFolders[index].tags["TITLE"]!), .where((simfile) => simfile.tags["TITLE"]!
subtitle: Text('3:45'), .toLowerCase()
onTap: () => Navigator.push( .contains(input.toLowerCase()))
context, .toList();
MaterialPageRoute( });
builder: (BuildContext context) => },
Level(stepmaniaCoursesFolders[index]))), 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(simfile.bannerPath!)),
trailing: Icon(Icons.play_arrow),
title: Text(simfile.tags["TITLE"]!),
subtitle: Text('3:45'),
onTap: () => Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) =>
Level(simfile))),
);
},
),
),
],
); );
} }
}), }),