Skip to content

Commit

Permalink
Add tap share on song detail
Browse files Browse the repository at this point in the history
  • Loading branch information
up2code committed Mar 19, 2024
1 parent 8910168 commit 9569e81
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:vocadb_app/src/constants/app_sizes.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_like_button.dart';
import 'package:vocadb_app/src/utils/share_launcher.dart';
import 'package:vocadb_app/src/utils/url_launcher.dart';

class SongDetailButtonBar extends StatelessWidget {
Expand Down Expand Up @@ -32,46 +33,48 @@ class SongDetailButtonBar extends StatelessWidget {
foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
),
child: const Column(
children: [
children: [
Icon(Icons.subtitles),
gapH4,
Text('Lyrics'),
],
),
),
),
TextButton(
key: shareBtnKey,
onPressed: () => {},
style: ButtonStyle(
foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
),
child: const Column(
children: [
Icon(Icons.share),
gapH4,
Text('Share'),
],
),
),
Consumer(
builder: (context, ref, _) {
return TextButton(
key: infoBtnKey,
onPressed: () {
ref.read(urlLauncherProvider).launchSongMoreInfo(song.id);
},
Consumer(builder: (context, ref, _) {
return TextButton(
key: shareBtnKey,
onPressed: () => ref.read(shareLauncherProvider).shareSong(song.id),
style: ButtonStyle(
foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
),
child: const Column(
children: [
Icon(Icons.info),
children: [
Icon(Icons.share),
gapH4,
Text('Info'),
Text('Share'),
],
),
);
}),
Consumer(
builder: (context, ref, _) {
return TextButton(
key: infoBtnKey,
onPressed: () {
ref.read(urlLauncherProvider).launchSongMoreInfo(song.id);
},
style: ButtonStyle(
foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
),
child: const Column(
children: [
Icon(Icons.info),
gapH4,
Text('Info'),
],
),
);
},
),
],
Expand Down
30 changes: 30 additions & 0 deletions lib/src/utils/share_launcher.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:share_plus/share_plus.dart';
import 'package:vocadb_app/flavor_config.dart';

class ShareLauncher {

final String host;

ShareLauncher(this.host);

shareSong(int id) =>
Share.share('$host/S/$id');

shareArtist(int id) =>
Share.share('$host/Ar/$id');

shareAlbum(int id) =>
Share.share('$host/Al/$id');

shareTag(int id) =>
Share.share('$host/T/$id');

shareReleaseEvent(int id) =>
Share.share('$host/E/$id');
}

final shareLauncherProvider = Provider<ShareLauncher>((ref) {
final flavorConfig = ref.watch(flavorConfigProvider);
return ShareLauncher('https://${flavorConfig.apiAuthority}');
});
76 changes: 34 additions & 42 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ packages:
dependency: transitive
description:
name: cross_file
sha256: f71079978789bc2fe78d79227f1f8cfe195b31bbd8db2399b0d15a4b96fb843b
sha256: "2f9d2cbccb76127ba28528cb3ae2c2326a122446a83de5a056aaa3880d3882c5"
url: "https://pub.dev"
source: hosted
version: "0.3.3+2"
version: "0.3.3+7"
crypto:
dependency: transitive
description:
Expand Down Expand Up @@ -561,10 +561,10 @@ packages:
dependency: transitive
description:
name: mime
sha256: "52e38f7e1143ef39daf532117d6b8f8f617bf4bcd6044ed8c29040d20d269630"
sha256: e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e
url: "https://pub.dev"
source: hosted
version: "1.0.3"
version: "1.0.4"
mocktail:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -609,58 +609,50 @@ packages:
dependency: transitive
description:
name: path_provider
sha256: "050e8e85e4b7fecdf2bb3682c1c64c4887a183720c802d323de8a5fd76d372dd"
sha256: b27217933eeeba8ff24845c34003b003b2b22151de3c908d0e679e8fe1aa078b
url: "https://pub.dev"
source: hosted
version: "2.0.11"
version: "2.1.2"
path_provider_android:
dependency: transitive
description:
name: path_provider_android
sha256: a776c088d671b27f6e3aa8881d64b87b3e80201c64e8869b811325de7a76c15e
sha256: "477184d672607c0a3bf68fbbf601805f92ef79c82b64b4d6eb318cbca4c48668"
url: "https://pub.dev"
source: hosted
version: "2.0.22"
path_provider_ios:
version: "2.2.2"
path_provider_foundation:
dependency: transitive
description:
name: path_provider_ios
sha256: "03d639406f5343478352433f00d3c4394d52dac8df3d847869c5e2333e0bbce8"
name: path_provider_foundation
sha256: "5a7999be66e000916500be4f15a3633ebceb8302719b47b9cc49ce924125350f"
url: "https://pub.dev"
source: hosted
version: "2.0.11"
version: "2.3.2"
path_provider_linux:
dependency: transitive
description:
name: path_provider_linux
sha256: ab0987bf95bc591da42dffb38c77398fc43309f0b9b894dcc5d6f40c4b26c379
url: "https://pub.dev"
source: hosted
version: "2.1.7"
path_provider_macos:
dependency: transitive
description:
name: path_provider_macos
sha256: "2a97e7fbb7ae9dcd0dfc1220a78e9ec3e71da691912e617e8715ff2a13086ae8"
sha256: f7a1fe3a634fe7734c8d3f2766ad746ae2a2884abe22e241a8b301bf5cac3279
url: "https://pub.dev"
source: hosted
version: "2.0.6"
version: "2.2.1"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
sha256: f0abc8ebd7253741f05488b4813d936b4d07c6bae3e86148a09e342ee4b08e76
sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334"
url: "https://pub.dev"
source: hosted
version: "2.0.5"
version: "2.1.2"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
sha256: bcabbe399d4042b8ee687e17548d5d3f527255253b4a639f5f8d2094a9c2b45c
sha256: "8bc9f22eee8690981c22aa7fc602f5c85b497a6fb2ceb35ee5a5e5ed85ad8170"
url: "https://pub.dev"
source: hosted
version: "2.1.3"
version: "2.2.1"
pedantic:
dependency: transitive
description:
Expand Down Expand Up @@ -689,10 +681,10 @@ packages:
dependency: transitive
description:
name: plugin_platform_interface
sha256: dbf0f707c78beedc9200146ad3cb0ab4d5da13c246336987be6940f026500d3a
sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
url: "https://pub.dev"
source: hosted
version: "2.1.3"
version: "2.1.8"
pointycastle:
dependency: transitive
description:
Expand Down Expand Up @@ -753,18 +745,18 @@ packages:
dependency: "direct main"
description:
name: share_plus
sha256: e387077716f80609bb979cd199331033326033ecd1c8f200a90c5f57b1c9f55e
sha256: "3ef39599b00059db0990ca2e30fca0a29d8b37aae924d60063f8e0184cf20900"
url: "https://pub.dev"
source: hosted
version: "6.3.0"
version: "7.2.2"
share_plus_platform_interface:
dependency: transitive
description:
name: share_plus_platform_interface
sha256: "82ddd4ab9260c295e6e39612d4ff00390b9a7a21f1bb1da771e2f232d80ab8a1"
sha256: df08bc3a07d01f5ea47b45d03ffcba1fa9cd5370fb44b3f38c70e42cced0f956
url: "https://pub.dev"
source: hosted
version: "3.2.0"
version: "3.3.1"
shelf:
dependency: transitive
description:
Expand Down Expand Up @@ -982,10 +974,10 @@ packages:
dependency: transitive
description:
name: url_launcher_linux
sha256: "360fa359ab06bcb4f7c5cd3123a2a9a4d3364d4575d27c4b33468bd4497dd094"
sha256: ab360eb661f8879369acac07b6bb3ff09d9471155357da8443fd5d3cf7363811
url: "https://pub.dev"
source: hosted
version: "3.0.1"
version: "3.1.1"
url_launcher_macos:
dependency: transitive
description:
Expand All @@ -998,26 +990,26 @@ packages:
dependency: transitive
description:
name: url_launcher_platform_interface
sha256: "4eae912628763eb48fc214522e58e942fd16ce195407dbf45638239523c759a6"
sha256: a932c3a8082e118f80a475ce692fde89dc20fddb24c57360b96bc56f7035de1f
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "2.3.1"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
sha256: "5669882643b96bb6d5786637cac727c6e918a790053b09245fd4513b8a07df2a"
sha256: ba140138558fcc3eead51a1c42e92a9fb074a1b1149ed3c73e66035b2ccd94f2
url: "https://pub.dev"
source: hosted
version: "2.0.13"
version: "2.0.19"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
sha256: e3c3b16d3104260c10eea3b0e34272aaa57921f83148b0619f74c2eced9b7ef1
sha256: ecf9725510600aa2bb6d7ddabe16357691b6d2805f66216a97d1b881e21beff7
url: "https://pub.dev"
source: hosted
version: "3.0.1"
version: "3.1.1"
uuid:
dependency: transitive
description:
Expand Down Expand Up @@ -1070,10 +1062,10 @@ packages:
dependency: transitive
description:
name: win32
sha256: c9ebe7ee4ab0c2194e65d3a07d8c54c5d00bb001b76081c4a04cdb8448b59e46
sha256: "7dacfda1edcca378031db9905ad7d7bd56b29fd1a90b0908b71a52a12c41e36b"
url: "https://pub.dev"
source: hosted
version: "3.1.3"
version: "5.0.3"
xdg_directories:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies:
cupertino_icons: 1.0.2
cached_network_image: 3.2.3
rxdart: 0.27.7
share_plus: 6.3.0
share_plus: 7.2.2
font_awesome_flutter: 10.3.0
url_launcher: 6.1.14
intl: 0.18.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,55 @@ void main() {
verify(() => urlLauncher.launchSongMoreInfo(1501)).called(1);
});

testWidgets('tap share button in song detail screen',
(tester) async {
/// Setup
final r = SongRobot(tester);
final songRepository = MockSongRepository();
final authRepository = MockAuthRepository();
final shareLauncher = MockShareLauncher();
final song = kFakeSongDetail;

/// Mock
callFetchSongId() =>
songRepository.fetchSongId(song.id, lang: PreferredLang.Default.name);
callFetchSongDerived() => songRepository.fetchSongsDerived(song.id,
lang: PreferredLang.Default.name);
callFetchSongRelated() => songRepository.fetchSongsRelated(song.id,
lang: PreferredLang.Default.name);

when(callFetchSongId).thenAnswer((_) => Future.value(song));
when(callFetchSongDerived).thenAnswer((_) => Future.value([
const Song(id: 1, name: 'Song_A'),
const Song(id: 2, name: 'Song_B'),
]));

when(callFetchSongRelated).thenAnswer(
(_) => Future.value(
const SongRelated(likeMatches: [
Song(id: 3, name: 'Song_Related_A'),
Song(id: 4, name: 'Song_Related_B'),
]),
),
);

/// Pump screen
await r.pumpSongDetailScreen(
songRepository: songRepository,
authRepository: authRepository,
songId: song.id,
shareLauncher: shareLauncher,
);

// Verify
verify(callFetchSongId).called(1);
verify(callFetchSongDerived).called(1);
verify(callFetchSongRelated).called(1);

await r.tapShare();

verify(() => shareLauncher.shareSong(1501)).called(1);
});


}
Loading

0 comments on commit 9569e81

Please sign in to comment.