Skip to content

Commit

Permalink
Separate logic song detail screen pv and without pv
Browse files Browse the repository at this point in the history
  • Loading branch information
up2code committed Mar 13, 2024
1 parent a6baf31 commit cdd6648
Show file tree
Hide file tree
Showing 7 changed files with 310 additions and 201 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,30 @@ import 'package:vocadb_app/src/common_widgets/async_value_widget.dart';
import 'package:vocadb_app/src/features/home/presentation/app_bar/global_app_bar.dart';
import 'package:vocadb_app/src/features/songs/domain/song.dart';
import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/song_detail_screen_controller.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_lyrics_content.dart';
import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/widgets/song_detail_pv_player.dart';
import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/widgets/song_detail_pvs_section.dart';
import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/widgets/song_detail_related_section.dart';
import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/widgets/song_detail_tags_section.dart';
import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/widgets/song_detail_web_links_section.dart';
import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/widgets/song_detail_with_pv.dart';
import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/widgets/song_detail_without_pv.dart';
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});

const SongDetailScreen({super.key, required this.song, this.pvPlayerWidget});

final Song song;

final Widget? pvPlayerWidget;

/// Keys for test
static const tagsKey = Key('tags-key');
static const artistsKey = Key('artists-key');
Expand All @@ -30,14 +46,17 @@ class _SongDetailScreenState extends ConsumerState<SongDetailScreen> {
@override
Widget build(BuildContext context) {
final state = ref.watch(songDetailScreenControllerProvider(widget.song.id));

return AsyncValueWidget(
value: state.song,
data: (song) => SafeArea(child: Scaffold(
appBar: const GlobalAppBar(title: Text('Song Detail')),
body:
(song.hasYoutubePV)? SongDetailPVPlayer(song: song) : const Text('No PV!!'),
),),
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: () {},),
),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ class SongDetailContent extends StatelessWidget {
child: ListView(
key: SongDetailScreen.songDetailScrollKey,
children: [
SongHeroImage(
imageUrl: song.imageUrl!,
),
SongDetailButtonBar(song: song, onTapLyricButton: onTapLyricButton),
SongDetailInfoSection(song: song),
SongDetailTagsSection(song: song),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class _SongDetailPVPlayerState extends ConsumerState<SongDetailPVPlayer> {
initialVideoId: YoutubePlayer.convertUrlToId(widget.song.youtubeUrl!)!,
flags: const YoutubePlayerFlags(
mute: false,
autoPlay: true,
autoPlay: false,
),
);
super.initState();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

import 'package:flutter/material.dart';
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_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';
import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/widgets/song_detail_pvs_section.dart';
import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/widgets/song_detail_related_section.dart';
import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/widgets/song_detail_tags_section.dart';
import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/widgets/song_detail_web_links_section.dart';

class SongDetailWithPV extends StatelessWidget {
final Song song;

final Widget? pvPlayerWidget;

final VoidCallback? onTapLyricButton;

const SongDetailWithPV({super.key, required this.song, this.pvPlayerWidget, this.onTapLyricButton});

@override
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),
],
),
),
]);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'package:flutter/material.dart';
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_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';
import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/widgets/song_detail_pvs_section.dart';
import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/widgets/song_detail_related_section.dart';
import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/widgets/song_detail_tags_section.dart';
import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/widgets/song_detail_web_links_section.dart';
import 'package:vocadb_app/src/features/songs/presentation/song_detail_screen/widgets/song_hero_image.dart';

class SongDetailWithoutPV extends StatelessWidget {
final Song song;

final VoidCallback? onTapLyricButton;

const SongDetailWithoutPV({super.key, required this.song, this.onTapLyricButton});

@override
Widget build(BuildContext context) {
return Column(children: [
SongHeroImage(
imageUrl: song.imageUrl!,
),
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),
],
),
),
]);
}
}
Loading

0 comments on commit cdd6648

Please sign in to comment.