diff --git a/lib/core/global_variables.dart b/lib/core/global_variables.dart index b828d0a..9c663f6 100644 --- a/lib/core/global_variables.dart +++ b/lib/core/global_variables.dart @@ -1,5 +1,3 @@ -import 'dart:developer'; - import 'package:flutter/material.dart'; import 'package:musiq/models/song_model/song.dart'; import 'package:musiq/services/audio_handler.dart'; @@ -25,12 +23,9 @@ class AppGlobals { // Method to update the current song index void setCurrentSongIndex(int index) { - log("----------updated $index"); currentSongIndex = index; } - - void updateTheme(String? newTheme) { theme = newTheme; } diff --git a/lib/presentation/commanWidgets/popup_menu.dart b/lib/presentation/commanWidgets/popup_menu.dart new file mode 100644 index 0000000..e873c4b --- /dev/null +++ b/lib/presentation/commanWidgets/popup_menu.dart @@ -0,0 +1,81 @@ +import 'package:audio_service/audio_service.dart'; +import 'package:flutter/material.dart'; +import 'package:musiq/core/colors.dart'; +import 'package:musiq/core/global_variables.dart'; +import 'package:musiq/core/helper_funtions.dart'; +import 'package:musiq/presentation/commanWidgets/snack_bar.dart'; + + +class SongPopupMenu extends StatelessWidget { + final dynamic song; // Use your actual song type here + final BuildContext context; + + const SongPopupMenu({ + Key? key, + required this.song, + required this.context, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + final audioHandler = AppGlobals().audioHandler; + + return PopupMenuButton( + icon: const Icon(Icons.more_vert_sharp), + onSelected: (value) { + switch (value) { + case 0: + if (AppGlobals().lastPlayedSongNotifier.value.isNotEmpty) { + final mediaItem = MediaItem( + id: song.downloadUrl?.last.link ?? "", + album: song.album?.name ?? "No ", + title: song.label ?? "No ", + displayTitle: song.name ?? "", + artUri: Uri.parse(song.image?.last.imageUrl ?? errorImage()), + ); + + audioHandler.addToQueue(mediaItem: mediaItem, song: song); + customSnackbar( + context: context, + message: "${song.name} added to queue", + bgColor: AppColors.white, + textColor: AppColors.black, + duration: const Duration(seconds: 5), + ); + } + break; + case 1: + // Handle "Favorite" action + break; + case 2: + // Handle "Add to Playlist" action + break; + } + }, + itemBuilder: (context) => [ + PopupMenuItem( + value: 0, + child: Row( + children: const [ + Icon(Icons.wrap_text), + Text('Add to Queue'), + ], + ), + ), + PopupMenuItem( + value: 1, + child: Row( + children: [ + Icon(Icons.favorite), // Use your favorite icon + const Text("Favorite"), + ], + ), + ), + PopupMenuItem( + value: 2, + child: const Text('Add to Playlist'), + ), + ], + ); + } +} diff --git a/lib/presentation/screens/LibraryScreen/last_played_list.dart b/lib/presentation/screens/LibraryScreen/last_played_list.dart index 1fc175e..bb3837e 100644 --- a/lib/presentation/screens/LibraryScreen/last_played_list.dart +++ b/lib/presentation/screens/LibraryScreen/last_played_list.dart @@ -1,14 +1,12 @@ -import 'package:audio_service/audio_service.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; -import 'package:musiq/core/colors.dart'; import 'package:musiq/core/global_variables.dart'; import 'package:musiq/core/helper_funtions.dart'; import 'package:musiq/data/hive_funtion.dart'; import 'package:musiq/models/song_model/song.dart'; import 'package:musiq/presentation/commanWidgets/empty_screen.dart'; import 'package:musiq/presentation/commanWidgets/favorite_icon.dart'; -import 'package:musiq/presentation/commanWidgets/snack_bar.dart'; +import 'package:musiq/presentation/commanWidgets/popup_menu.dart'; import 'package:musiq/presentation/screens/player_screen/bottomPlayer/bottom_player.dart'; import 'package:musiq/presentation/screens/player_screen/player_screen.dart'; @@ -88,72 +86,7 @@ class _LastPlayedListState extends State { FavoriteIcon( song: lastplayed[index], ), - PopupMenuButton( - icon: Icon(Icons.more_vert_sharp), - onSelected: (value) { - // Handle selected menu action - final audioHandler = AppGlobals().audioHandler; - - switch (value) { - case 0: - if (AppGlobals() - .lastPlayedSongNotifier - .value - .isNotEmpty) { - final mediaItem = MediaItem( - id: song.downloadUrl?.last.link ?? "", - album: song.album?.name ?? "No ", - title: song.label ?? "No ", - displayTitle: song.name ?? "", - artUri: Uri.parse( - song.image?.last.imageUrl ?? - errorImage()), - ); - - audioHandler.addToQueue( - mediaItem: mediaItem, song: song); - customSnackbar( - context: context, - message: - "${song.name} added to queue", - bgColor: AppColors.white, - textColor: AppColors.black, - duration: Duration(seconds: 5)); - } - break; - case 1: - // Handle "Add to Playlist" action - break; - case 2: - // Handle "Share" action - break; - } - }, - itemBuilder: (context) => [ - PopupMenuItem( - value: 0, - child: Row( - children: [ - Icon(Icons.wrap_text), - Text('Add to Queue'), - ], - ), - ), - PopupMenuItem( - value: 1, - child: Row( - children: [ - FavoriteIcon(song: song), - Text("Favorite") - ], - ), - ), - PopupMenuItem( - value: 2, - child: Text('Add to Playlist'), - ), - ], - ), + SongPopupMenu(song: song, context: context) ], ), leading: Container( diff --git a/lib/presentation/screens/album_or_playlist_screen/album_or_playlist_screen.dart b/lib/presentation/screens/album_or_playlist_screen/album_or_playlist_screen.dart index 577aebf..808148c 100644 --- a/lib/presentation/screens/album_or_playlist_screen/album_or_playlist_screen.dart +++ b/lib/presentation/screens/album_or_playlist_screen/album_or_playlist_screen.dart @@ -11,7 +11,7 @@ import 'package:musiq/models/album_model/album_model.dart'; import 'package:musiq/models/play_list_model/play_list_model.dart'; import 'package:musiq/models/song_model/song.dart'; import 'package:musiq/presentation/commanWidgets/empty_screen.dart'; -import 'package:musiq/presentation/commanWidgets/favorite_icon.dart'; +import 'package:musiq/presentation/commanWidgets/popup_menu.dart'; import 'package:musiq/presentation/commanWidgets/snack_bar.dart'; import 'package:musiq/presentation/screens/artist/widgets/artist_horizontal_listview.dart'; import 'package:musiq/presentation/screens/player_screen/bottomPlayer/bottom_player.dart'; @@ -315,74 +315,7 @@ class _AlbumOrPlaylistScreenState extends State { song.label ?? "no", maxLines: 1, ), - trailing: PopupMenuButton( - icon: Icon(Icons.more_vert_sharp), - onSelected: (value) { - // Handle selected menu action - final audioHandler = - AppGlobals().audioHandler; - - switch (value) { - case 0: - if (AppGlobals() - .lastPlayedSongNotifier - .value - .isNotEmpty) { - final mediaItem = MediaItem( - id: song.downloadUrl?.last.link ?? "", - album: song.album?.name ?? "No ", - title: song.label ?? "No ", - displayTitle: song.name ?? "", - artUri: Uri.parse( - song.image?.last.imageUrl ?? - errorImage()), - ); - - audioHandler.addToQueue( - mediaItem: mediaItem, song: song); - customSnackbar( - context: context, - message: - "${song.name} added to queue", - bgColor: AppColors.white, - textColor: AppColors.black, - duration: Duration(seconds: 5)); - } - - break; - case 1: - // Handle "Add to Playlist" action - break; - case 2: - // Handle "Share" action - break; - } - }, - itemBuilder: (context) => [ - PopupMenuItem( - value: 0, - child: Row( - children: [ - Icon(Icons.wrap_text), - Text('Add to Queue'), - ], - ), - ), - PopupMenuItem( - value: 1, - child: Row( - children: [ - FavoriteIcon(song: song), - Text("Favorite") - ], - ), - ), - PopupMenuItem( - value: 2, - child: Text('Add to Playlist'), - ), - ], - ), + trailing: SongPopupMenu(song: song, context: context) ), ); }, diff --git a/lib/presentation/screens/artist/artist_screen.dart b/lib/presentation/screens/artist/artist_screen.dart index b0d28c4..ff85c2e 100644 --- a/lib/presentation/screens/artist/artist_screen.dart +++ b/lib/presentation/screens/artist/artist_screen.dart @@ -1,5 +1,4 @@ import 'dart:developer'; -import 'package:audio_service/audio_service.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -10,8 +9,7 @@ import 'package:musiq/core/helper_funtions.dart'; import 'package:musiq/core/sized.dart'; import 'package:musiq/models/artist_model/artist_model.dart'; import 'package:musiq/models/song_model/song.dart'; -import 'package:musiq/presentation/commanWidgets/favorite_icon.dart'; -import 'package:musiq/presentation/commanWidgets/snack_bar.dart'; +import 'package:musiq/presentation/commanWidgets/popup_menu.dart'; import 'package:musiq/presentation/screens/artist/widgets/artist_horizontal_listview.dart'; import 'package:musiq/presentation/screens/player_screen/bottomPlayer/bottom_player.dart'; import 'package:musiq/presentation/screens/player_screen/player_screen.dart'; @@ -160,77 +158,7 @@ class ArtistScreen extends StatelessWidget { ), )); }, - trailing: PopupMenuButton( - icon: Icon(Icons.more_vert_sharp), - onSelected: (value) { - - // Handle selected menu action - final audioHandler = - AppGlobals().audioHandler; - - switch (value) { - case 0: - if (AppGlobals() - .lastPlayedSongNotifier - .value - .isNotEmpty) { - final mediaItem = MediaItem( - id: song.downloadUrl?.last.link ?? - "", - album: song.album?.name ?? "No ", - title: song.label ?? "No ", - displayTitle: song.name ?? "", - artUri: Uri.parse( - song.image?.last.imageUrl ?? - errorImage()), - ); - - audioHandler.addToQueue( - mediaItem: mediaItem, - song: song); - customSnackbar( - context: context, - message: - "${song.name} added to queue", - bgColor: AppColors.white, - textColor: AppColors.black, - duration: Duration(seconds: 5)); - } - - break; - case 1: - // Handle "Add to Playlist" action - break; - case 2: - // Handle "Share" action - break; - } - }, - itemBuilder: (context) => [ - PopupMenuItem( - value: 0, - child: Row( - children: [ - Icon(Icons.wrap_text), - Text('Add to Queue'), - ], - ), - ), - PopupMenuItem( - value: 1, - child: Row( - children: [ - FavoriteIcon(song: song), - Text("Favorite") - ], - ), - ), - PopupMenuItem( - value: 2, - child: Text('Add to Playlist'), - ), - ], - ), + trailing: SongPopupMenu(song: song, context: context) ), ); }), diff --git a/lib/presentation/screens/homeScreen/widgets/homepage_lastplayed_widget.dart b/lib/presentation/screens/homeScreen/widgets/homepage_lastplayed_widget.dart index 0ebca8e..857273e 100644 --- a/lib/presentation/screens/homeScreen/widgets/homepage_lastplayed_widget.dart +++ b/lib/presentation/screens/homeScreen/widgets/homepage_lastplayed_widget.dart @@ -1,4 +1,3 @@ -import 'package:audio_service/audio_service.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:musiq/core/colors.dart'; @@ -6,8 +5,7 @@ import 'package:musiq/core/global_variables.dart'; import 'package:musiq/core/helper_funtions.dart'; import 'package:musiq/core/sized.dart'; import 'package:musiq/models/song_model/song.dart'; -import 'package:musiq/presentation/commanWidgets/favorite_icon.dart'; -import 'package:musiq/presentation/commanWidgets/snack_bar.dart'; +import 'package:musiq/presentation/commanWidgets/popup_menu.dart'; import 'package:musiq/presentation/screens/player_screen/player_screen.dart'; class HomepageLastplayedWidget extends StatelessWidget { @@ -107,74 +105,7 @@ class HomepageLastplayedWidget extends StatelessWidget { ), ); }, - trailing: PopupMenuButton( - icon: Icon(Icons.more_vert_sharp), - onSelected: (value) { - // Handle selected menu action - final audioHandler = - AppGlobals().audioHandler; - - switch (value) { - case 0: - if (AppGlobals() - .lastPlayedSongNotifier - .value - .isNotEmpty) { - final mediaItem = MediaItem( - id: song.downloadUrl?.last.link ?? - "", - album: song.album?.name ?? "No ", - title: song.label ?? "No ", - displayTitle: song.name ?? "", - artUri: Uri.parse( - song.image?.last.imageUrl ?? - errorImage()), - ); - - audioHandler.addToQueue( - mediaItem: mediaItem, song: song); - customSnackbar( - context: context, - message: - "${song.name} added to queue", - bgColor: AppColors.white, - textColor: AppColors.black, - duration: Duration(seconds: 5)); - } - - break; - case 1: - // Handle "Add to Playlist" action - break; - case 2: - // Handle "Share" action - break; - } - }, - itemBuilder: (context) => [ - PopupMenuItem( - value: 0, - child: Row( - children: [ - Icon(Icons.wrap_text), - Text('Add to Queue'), - ], - ), - ), - PopupMenuItem( - value: 1, - child: Row( - children: [ - FavoriteIcon(song: song), - Text("Favorite") - ], - ), - ), - PopupMenuItem( - value: 2, - child: Text('Add to Playlist'), - ), - ]), + trailing:SongPopupMenu(song: song, context: context) ), ); }), diff --git a/lib/presentation/screens/search_screen/widgets/song_search_result.dart b/lib/presentation/screens/search_screen/widgets/song_search_result.dart index 61f268d..c6c998e 100644 --- a/lib/presentation/screens/search_screen/widgets/song_search_result.dart +++ b/lib/presentation/screens/search_screen/widgets/song_search_result.dart @@ -10,7 +10,7 @@ import 'package:musiq/core/helper_funtions.dart'; import 'package:musiq/core/sized.dart'; import 'package:musiq/models/song_model/song.dart'; import 'package:musiq/presentation/commanWidgets/empty_screen.dart'; -import 'package:musiq/presentation/commanWidgets/favorite_icon.dart'; +import 'package:musiq/presentation/commanWidgets/popup_menu.dart'; import 'package:musiq/presentation/commanWidgets/snack_bar.dart'; class SongSearchResult extends StatelessWidget { @@ -119,71 +119,7 @@ class SongSearchResult extends StatelessWidget { song.album?.name ?? "no", maxLines: 1, ), - trailing: PopupMenuButton( - icon: Icon(Icons.more_vert_sharp), - onSelected: (value) { - // Handle selected menu action - final audioHandler = AppGlobals().audioHandler; - - switch (value) { - case 0: - if (AppGlobals() - .lastPlayedSongNotifier - .value - .isNotEmpty) { - final mediaItem = MediaItem( - id: song.downloadUrl?.last.link ?? "", - album: song.album?.name ?? "No ", - title: song.label ?? "No ", - displayTitle: song.name ?? "", - artUri: Uri.parse( - song.image?.last.imageUrl ?? errorImage()), - ); - - audioHandler.addToQueue( - mediaItem: mediaItem, song: song); - customSnackbar( - context: context, - message: "${song.name} added to queue", - bgColor: AppColors.white, - textColor: AppColors.black, - duration: Duration(seconds: 5)); - } - break; - case 1: - - // Handle "Add to Playlist" action - break; - case 2: - // Handle "Share" action - break; - } - }, - itemBuilder: (context) => [ - PopupMenuItem( - value: 0, - child: Row( - children: [ - Icon(Icons.wrap_text), - Text('Add to Queue'), - ], - ), - ), - PopupMenuItem( - value: 1, - child: Row( - children: [ - FavoriteIcon(song: song), - Text("Favorite") - ], - ), - ), - PopupMenuItem( - value: 2, - child: Text('Add to Playlist'), - ), - ], - ), + trailing:SongPopupMenu(song: song, context: context) ), ); },