🐛 Bug fixes on library screen
This commit is contained in:
@@ -362,17 +362,53 @@ class LibraryScreen extends HookConsumerWidget {
|
|||||||
return StreamBuilder<List<Track>>(
|
return StreamBuilder<List<Track>>(
|
||||||
stream: repo.watchAllTracks(),
|
stream: repo.watchAllTracks(),
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (snapshot.hasError) {
|
// Calculate hintText
|
||||||
return Center(child: Text('Error: ${snapshot.error}'));
|
String hintText;
|
||||||
}
|
if (!snapshot.hasData || snapshot.hasError) {
|
||||||
if (!snapshot.hasData) {
|
hintText = 'Search tracks...';
|
||||||
return const Center(child: CircularProgressIndicator());
|
} else {
|
||||||
}
|
|
||||||
final tracks = snapshot.data!;
|
final tracks = snapshot.data!;
|
||||||
if (tracks.isEmpty) {
|
final totalTracks = tracks.length;
|
||||||
return const Center(child: Text('No tracks yet. Add some!'));
|
if (searchQuery.value.isEmpty) {
|
||||||
|
hintText = 'Search tracks... ($totalTracks tracks)';
|
||||||
|
} else {
|
||||||
|
final query = searchQuery.value.toLowerCase();
|
||||||
|
final filteredCount = tracks.where((track) {
|
||||||
|
if (track.title.toLowerCase().contains(query)) return true;
|
||||||
|
if (track.artist?.toLowerCase().contains(query) ?? false) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (track.album?.toLowerCase().contains(query) ?? false) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (track.lyrics != null) {
|
||||||
|
try {
|
||||||
|
final lyricsData = LyricsData.fromJsonString(track.lyrics!);
|
||||||
|
for (final line in lyricsData.lines) {
|
||||||
|
if (line.text.toLowerCase().contains(query)) return true;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Ignore parsing errors
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}).length;
|
||||||
|
hintText =
|
||||||
|
'Search tracks... ($filteredCount of $totalTracks tracks)';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determine main content
|
||||||
|
Widget mainContent;
|
||||||
|
if (snapshot.hasError) {
|
||||||
|
mainContent = Center(child: Text('Error: ${snapshot.error}'));
|
||||||
|
} else if (!snapshot.hasData) {
|
||||||
|
mainContent = const Center(child: CircularProgressIndicator());
|
||||||
|
} else {
|
||||||
|
final tracks = snapshot.data!;
|
||||||
|
if (tracks.isEmpty) {
|
||||||
|
mainContent = const Center(child: Text('No tracks yet. Add some!'));
|
||||||
|
} else {
|
||||||
List<Track> filteredTracks;
|
List<Track> filteredTracks;
|
||||||
if (searchQuery.value.isEmpty) {
|
if (searchQuery.value.isEmpty) {
|
||||||
filteredTracks = tracks;
|
filteredTracks = tracks;
|
||||||
@@ -401,12 +437,11 @@ class LibraryScreen extends HookConsumerWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (filteredTracks.isEmpty && searchQuery.value.isNotEmpty) {
|
if (filteredTracks.isEmpty && searchQuery.value.isNotEmpty) {
|
||||||
return const Center(child: Text('No tracks match your search.'));
|
mainContent = const Center(
|
||||||
}
|
child: Text('No tracks match your search.'),
|
||||||
|
);
|
||||||
return Stack(
|
} else {
|
||||||
children: [
|
mainContent = ListView.builder(
|
||||||
ListView.builder(
|
|
||||||
padding: EdgeInsets.only(
|
padding: EdgeInsets.only(
|
||||||
bottom: 72 + MediaQuery.paddingOf(context).bottom,
|
bottom: 72 + MediaQuery.paddingOf(context).bottom,
|
||||||
top: 80,
|
top: 80,
|
||||||
@@ -458,11 +493,13 @@ class LibraryScreen extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.of(context).pop(false),
|
onPressed: () =>
|
||||||
|
Navigator.of(context).pop(false),
|
||||||
child: const Text('Cancel'),
|
child: const Text('Cancel'),
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.of(context).pop(true),
|
onPressed: () =>
|
||||||
|
Navigator.of(context).pop(true),
|
||||||
style: TextButton.styleFrom(
|
style: TextButton.styleFrom(
|
||||||
foregroundColor: Colors.red,
|
foregroundColor: Colors.red,
|
||||||
),
|
),
|
||||||
@@ -497,7 +534,14 @@ class LibraryScreen extends HookConsumerWidget {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Stack(
|
||||||
|
children: [
|
||||||
|
mainContent,
|
||||||
Positioned(
|
Positioned(
|
||||||
top: 0,
|
top: 0,
|
||||||
left: 0,
|
left: 0,
|
||||||
@@ -506,7 +550,7 @@ class LibraryScreen extends HookConsumerWidget {
|
|||||||
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 16),
|
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 16),
|
||||||
child: SearchBar(
|
child: SearchBar(
|
||||||
onChanged: (value) => searchQuery.value = value,
|
onChanged: (value) => searchQuery.value = value,
|
||||||
hintText: 'Search tracks...',
|
hintText: hintText,
|
||||||
leading: const Icon(Icons.search),
|
leading: const Icon(Icons.search),
|
||||||
padding: WidgetStatePropertyAll(
|
padding: WidgetStatePropertyAll(
|
||||||
EdgeInsets.symmetric(horizontal: 24),
|
EdgeInsets.symmetric(horizontal: 24),
|
||||||
|
|||||||
Reference in New Issue
Block a user