Skip to content

Commit

Permalink
fix: check for unsynced lyrics and error handling for timed lyrics query
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Nov 8, 2023
1 parent 574406d commit 1d77556
Showing 1 changed file with 45 additions and 4 deletions.
49 changes: 45 additions & 4 deletions lib/pages/lyrics/synced_lyrics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class SyncedLyrics extends HookConsumerWidget {

final lyricValue = timedLyricsQuery.data;

final isUnSyncLyric = useMemoized(
() => lyricValue?.lyrics.every((l) => l.time == Duration.zero),
[lyricValue],
);

final lyricsMap = useMemoized(
() =>
lyricValue?.lyrics
Expand Down Expand Up @@ -72,6 +77,9 @@ class SyncedLyrics extends HookConsumerWidget {
: textTheme.headlineMedium?.copyWith(fontSize: 25))
?.copyWith(color: palette.titleTextColor);

var bodyTextTheme = textTheme.bodyLarge?.copyWith(
color: palette.bodyTextColor,
);
return Stack(
children: [
Column(
Expand All @@ -93,7 +101,9 @@ class SyncedLyrics extends HookConsumerWidget {
: textTheme.titleLarge,
),
),
if (lyricValue != null && lyricValue.lyrics.isNotEmpty)
if (lyricValue != null &&
lyricValue.lyrics.isNotEmpty &&
isUnSyncLyric == false)
Expanded(
child: ListView.builder(
controller: controller,
Expand All @@ -102,7 +112,7 @@ class SyncedLyrics extends HookConsumerWidget {
final lyricSlice = lyricValue.lyrics[index];
final isActive = lyricSlice.time.inSeconds == currentTime;

if (isActive) {
if (isActive && isUnSyncLyric == true) {
controller.scrollToIndex(
index,
preferPosition: AutoScrollPosition.middle,
Expand Down Expand Up @@ -173,8 +183,39 @@ class SyncedLyrics extends HookConsumerWidget {
),
),
if (playlist.activeTrack != null &&
(lyricValue == null || lyricValue.lyrics.isEmpty == true))
const Expanded(child: ShimmerLyrics()),
(timedLyricsQuery.isLoading || timedLyricsQuery.isRefreshing))
const Expanded(child: ShimmerLyrics())
else if (playlist.activeTrack != null &&
(timedLyricsQuery.hasError))
Text(
"Sorry, no Lyrics were found for `${playlist.activeTrack?.name}` :'(\n${timedLyricsQuery.error.toString()}",
style: bodyTextTheme,
)
else if (isUnSyncLyric == true)
Expanded(
child: Center(
child: RichText(
textAlign: TextAlign.center,
text: TextSpan(
style: bodyTextTheme,
children: [
const TextSpan(
text:
"Synced lyrics is not available for this song. Please use the",
),
TextSpan(
text: " Plain Lyrics ",
style: textTheme.bodyLarge?.copyWith(
color: palette.bodyTextColor,
fontWeight: FontWeight.bold,
),
),
const TextSpan(text: "tab instead."),
],
),
),
),
),
],
),
Align(
Expand Down

0 comments on commit 1d77556

Please sign in to comment.