From e3c7b83ae012114c02abacbb4fe86975497c8124 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Fri, 3 Jun 2022 11:41:21 +0600 Subject: [PATCH] share playlists & track support added --- lib/components/Playlist/PlaylistView.dart | 22 +++++++++++++++++ lib/components/Shared/TrackTile.dart | 30 +++++++++++++++++++++++ lib/themes/dark-theme.dart | 8 +++++- lib/themes/light-theme.dart | 7 ++++++ 4 files changed, 66 insertions(+), 1 deletion(-) diff --git a/lib/components/Playlist/PlaylistView.dart b/lib/components/Playlist/PlaylistView.dart index 5f7c2597..d63bc3ea 100644 --- a/lib/components/Playlist/PlaylistView.dart +++ b/lib/components/Playlist/PlaylistView.dart @@ -1,3 +1,4 @@ +import 'package:flutter/services.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:spotube/components/Shared/HeartButton.dart'; @@ -109,6 +110,27 @@ class PlaylistView extends HookConsumerWidget { }, ); }), + IconButton( + icon: const Icon(Icons.share_rounded), + onPressed: () { + final data = + "https://open.spotify.com/playlist/${playlist.id}"; + Clipboard.setData( + ClipboardData(text: data), + ).then((_) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + width: 300, + behavior: SnackBarBehavior.floating, + content: Text( + "Copied $data to clipboard", + textAlign: TextAlign.center, + ), + ), + ); + }); + }, + ), // play playlist IconButton( icon: Icon( diff --git a/lib/components/Shared/TrackTile.dart b/lib/components/Shared/TrackTile.dart index a42eacf1..4f5ed5d5 100644 --- a/lib/components/Shared/TrackTile.dart +++ b/lib/components/Shared/TrackTile.dart @@ -1,5 +1,6 @@ import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:spotify/spotify.dart'; @@ -57,6 +58,22 @@ class TrackTile extends HookConsumerWidget { return await spotify.playlists.removeTrack(track.value.uri!, playlistId!); }, [playlistId, spotify, track.value.uri]); + void actionShare(Track track) { + final data = "https://open.spotify.com/track/${track.id}"; + Clipboard.setData(ClipboardData(text: data)).then((_) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + width: 300, + behavior: SnackBarBehavior.floating, + content: Text( + "Copied $data to clipboard", + textAlign: TextAlign.center, + ), + ), + ); + }); + } + actionAddToPlaylist() async { showDialog( context: context, @@ -252,6 +269,16 @@ class TrackTile extends HookConsumerWidget { ], ), value: "favorite", + ), + PopupMenuItem( + child: Row( + children: const [ + Icon(Icons.share_rounded), + SizedBox(width: 10), + Text("Share") + ], + ), + value: "share", ) ]; }, @@ -266,6 +293,9 @@ class TrackTile extends HookConsumerWidget { case "remove-playlist": actionRemoveFromPlaylist(); break; + case "share": + actionShare(track.value); + break; } }, ); diff --git a/lib/themes/dark-theme.dart b/lib/themes/dark-theme.dart index 968a147f..bcf96aac 100644 --- a/lib/themes/dark-theme.dart +++ b/lib/themes/dark-theme.dart @@ -13,7 +13,6 @@ ThemeData darkTheme({ scaffoldBackgroundColor: backgroundMaterialColor[900], dialogBackgroundColor: backgroundMaterialColor[800], shadowColor: Colors.black26, - popupMenuTheme: PopupMenuThemeData(color: backgroundMaterialColor[800]), buttonTheme: ButtonThemeData( buttonColor: accentMaterialColor, ), @@ -56,6 +55,13 @@ ThemeData darkTheme({ ), ), ), + popupMenuTheme: PopupMenuThemeData( + color: backgroundMaterialColor[800], + elevation: 2, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(18.0), + ), + ), cardColor: backgroundMaterialColor[800], canvasColor: backgroundMaterialColor[900], ); diff --git a/lib/themes/light-theme.dart b/lib/themes/light-theme.dart index 540def04..fe642365 100644 --- a/lib/themes/light-theme.dart +++ b/lib/themes/light-theme.dart @@ -81,6 +81,13 @@ ThemeData lightTheme({ ), ), ), + popupMenuTheme: PopupMenuThemeData( + color: backgroundMaterialColor[100], + elevation: 2, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(18.0), + ), + ), cardColor: backgroundMaterialColor[50], canvasColor: backgroundMaterialColor[50], );