From 18d31dcef622014f2fc2bfa4de03add71fab0678 Mon Sep 17 00:00:00 2001 From: Augsorn Chanklad Date: Thu, 14 Mar 2024 09:15:52 +0700 Subject: [PATCH] Fix toggle Lyrics --- .../song_detail_screen.dart | 27 ++++++++++++++++--- .../widgets/song_detail_content.dart | 5 +++- .../widgets/song_detail_with_pv.dart | 17 ++---------- .../song_detail_screen_test.dart | 14 +++++----- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/lib/src/features/songs/presentation/song_detail_screen/song_detail_screen.dart b/lib/src/features/songs/presentation/song_detail_screen/song_detail_screen.dart index 5e50757f..b2a3305a 100644 --- a/lib/src/features/songs/presentation/song_detail_screen/song_detail_screen.dart +++ b/lib/src/features/songs/presentation/song_detail_screen/song_detail_screen.dart @@ -21,7 +21,6 @@ import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/wi import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/widgets/song_hero_image.dart'; class SongDetailScreen extends ConsumerStatefulWidget { - const SongDetailScreen({super.key, required this.song, this.pvPlayerWidget}); final Song song; @@ -43,6 +42,12 @@ class SongDetailScreen extends ConsumerStatefulWidget { } class _SongDetailScreenState extends ConsumerState { + _toggleShowLyric() { + ref + .read(songDetailScreenControllerProvider(widget.song.id).notifier) + .toggleLyricContent(); + } + @override Widget build(BuildContext context) { final state = ref.watch(songDetailScreenControllerProvider(widget.song.id)); @@ -52,9 +57,23 @@ class _SongDetailScreenState extends ConsumerState { data: (song) => SafeArea( child: Scaffold( appBar: GlobalAppBar(title: Text(song.name ?? 'Song detail')), - body: (song.hasYoutubePV) - ? SongDetailWithPV(song: song, pvPlayerWidget: widget.pvPlayerWidget, onTapLyricButton: () {},) - : SongDetailWithoutPV(song: song, onTapLyricButton: () {},), + body: Column(children: [ + // PV or thumbnail + (song.hasYoutubePV) + ? widget.pvPlayerWidget ?? SongDetailPVPlayer(song: song) + : SongHeroImage(imageUrl: song.imageUrl!), + + // Lyrics or Song detail content + (state.showLyricContent) + ? LyricContent( + lyrics: song.lyrics, + onTapClose: _toggleShowLyric, + ) + : SongDetailContent( + song: song, + onTapLyricButton: _toggleShowLyric, + ), + ]), ), ), ); diff --git a/lib/src/features/songs/presentation/song_detail_screen/widgets/song_detail_content.dart b/lib/src/features/songs/presentation/song_detail_screen/widgets/song_detail_content.dart index 91d8bf1c..8d2c96a4 100644 --- a/lib/src/features/songs/presentation/song_detail_screen/widgets/song_detail_content.dart +++ b/lib/src/features/songs/presentation/song_detail_screen/widgets/song_detail_content.dart @@ -26,7 +26,10 @@ class SongDetailContent extends StatelessWidget { child: ListView( key: SongDetailScreen.songDetailScrollKey, children: [ - SongDetailButtonBar(song: song, onTapLyricButton: onTapLyricButton), + SongDetailButtonBar( + song: song, + onTapLyricButton: onTapLyricButton, + ), SongDetailInfoSection(song: song), SongDetailTagsSection(song: song), SongDetailArtistsSection(song: song), diff --git a/lib/src/features/songs/presentation/song_detail_screen/widgets/song_detail_with_pv.dart b/lib/src/features/songs/presentation/song_detail_screen/widgets/song_detail_with_pv.dart index e634e965..47f83fb5 100644 --- a/lib/src/features/songs/presentation/song_detail_screen/widgets/song_detail_with_pv.dart +++ b/lib/src/features/songs/presentation/song_detail_screen/widgets/song_detail_with_pv.dart @@ -4,6 +4,7 @@ import 'package:vocadb_app/src/features/songs/domain/song.dart'; import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/widgets/song_detail_albums_section.dart'; import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/widgets/song_detail_artists_section.dart'; import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/widgets/song_detail_button_bar.dart'; +import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/widgets/song_detail_content.dart'; import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/widgets/song_detail_derived_section.dart'; import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/widgets/song_detail_info_section.dart'; import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/widgets/song_detail_pv_player.dart'; @@ -25,21 +26,7 @@ class SongDetailWithPV extends StatelessWidget { Widget build(BuildContext context) { return Column(children: [ pvPlayerWidget ?? SongDetailPVPlayer(song: song), - Expanded( - child: ListView( - children: [ - SongDetailButtonBar(song: song, onTapLyricButton: onTapLyricButton), - SongDetailInfoSection(song: song), - SongDetailTagsSection(song: song), - SongDetailArtistsSection(song: song), - SongDetailPVsSection(song: song), - SongDetailAlbumsSection(song: song), - SongDetailDerivedSongsSection(song: song), - SongDetailRelatedSection(song: song), - SongDetailWebLinksSection(song: song), - ], - ), - ), + SongDetailContent(song: song, onTapLyricButton: onTapLyricButton), ]); } } diff --git a/test/src/features/songs/presentation/song_detail_screen/song_detail_screen_test.dart b/test/src/features/songs/presentation/song_detail_screen/song_detail_screen_test.dart index b232b937..84be2a24 100644 --- a/test/src/features/songs/presentation/song_detail_screen/song_detail_screen_test.dart +++ b/test/src/features/songs/presentation/song_detail_screen/song_detail_screen_test.dart @@ -187,18 +187,18 @@ void main() { verify(callFetchSongRelated).called(1); // /// Verify before tap lyric button - // await r.expectSongInfoContentVisible(true); + await r.expectSongInfoContentVisible(true); await r.expectSongLyricContentVisible(false); await r.expectLyricButtonVisible(true); // /// Verify after tap lyric button await r.tapLyricButton(); - // await r.expectSongInfoContentVisible(false); - // await r.expectSongLyricContentVisible(true); + await r.expectSongInfoContentVisible(false); + await r.expectSongLyricContentVisible(true); - // /// Verify after tap close lyric button - // await r.tapCloseLyricButton(); - // await r.expectSongInfoContentVisible(true); - // await r.expectSongLyricContentVisible(false); + /// Verify after tap close lyric button + await r.tapCloseLyricButton(); + await r.expectSongInfoContentVisible(true); + await r.expectSongLyricContentVisible(false); }); }