From 4f14849502960e2dfaf8d5e9d43e74f8b37b9c57 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Wed, 26 Jan 2022 19:42:13 +0600 Subject: [PATCH] Overflow Album error fix playtrack from found song in Search search on TexField submit --- lib/components/Player/Player.dart | 3 - lib/components/Search/Search.dart | 72 ++++++++++++++++------ lib/components/Shared/TracksTableView.dart | 16 ++--- 3 files changed, 58 insertions(+), 33 deletions(-) diff --git a/lib/components/Player/Player.dart b/lib/components/Player/Player.dart index 2bb8fa97..b3d6f697 100644 --- a/lib/components/Player/Player.dart +++ b/lib/components/Player/Player.dart @@ -4,11 +4,8 @@ import 'package:cached_network_image/cached_network_image.dart'; import 'package:hotkey_manager/hotkey_manager.dart'; import 'package:just_audio/just_audio.dart'; import 'package:spotify/spotify.dart'; -import 'package:spotube/components/Artist/ArtistProfile.dart'; import 'package:spotube/components/Shared/DownloadTrackButton.dart'; import 'package:spotube/components/Player/PlayerControls.dart'; -import 'package:spotube/components/Shared/LinkText.dart'; -import 'package:spotube/helpers/artist-to-string.dart'; import 'package:spotube/helpers/artists-to-clickable-artists.dart'; import 'package:spotube/helpers/image-to-url-string.dart'; import 'package:spotube/helpers/search-youtube.dart'; diff --git a/lib/components/Search/Search.dart b/lib/components/Search/Search.dart index 8a65d1f2..10649e1b 100644 --- a/lib/components/Search/Search.dart +++ b/lib/components/Search/Search.dart @@ -20,6 +20,7 @@ class Search extends StatefulWidget { class _SearchState extends State { late TextEditingController _controller; + String searchTerm = ""; @override @@ -43,6 +44,11 @@ class _SearchState extends State { child: TextField( decoration: const InputDecoration(hintText: "Search..."), controller: _controller, + onSubmitted: (value) { + setState(() { + searchTerm = _controller.value.text; + }); + }, ), ), const SizedBox(width: 5), @@ -64,7 +70,7 @@ class _SearchState extends State { ), FutureBuilder>( future: searchTerm.isNotEmpty - ? spotify.search.get(searchTerm).first(5) + ? spotify.search.get(searchTerm).first(10) : null, builder: (context, snapshot) { if (!snapshot.hasData && searchTerm.isNotEmpty) { @@ -116,7 +122,27 @@ class _SearchState extends State { duration: duration, thumbnailUrl: imageToUrlString(track.value.album?.images), - onTrackPlayButtonPressed: (currentTrack) {}, + onTrackPlayButtonPressed: (currentTrack) async { + var isPlaylistPlaying = + playback.currentPlaylist?.id != null && + playback.currentPlaylist?.id == + currentTrack.id; + if (!isPlaylistPlaying) { + playback.setCurrentPlaylist = CurrentPlaylist( + tracks: [currentTrack], + id: currentTrack.id!, + name: currentTrack.name!, + thumbnail: imageToUrlString( + currentTrack.album?.images), + ); + playback.setCurrentTrack = currentTrack; + } else if (isPlaylistPlaying && + currentTrack.id != null && + currentTrack.id != + playback.currentTrack?.id) { + playback.setCurrentTrack = currentTrack; + } + }, ); }), if (albums.isNotEmpty) @@ -125,12 +151,14 @@ class _SearchState extends State { style: Theme.of(context).textTheme.headline5, ), const SizedBox(height: 10), - Wrap( - spacing: 20, - runSpacing: 20, - children: albums.map((album) { - return AlbumCard(simpleAlbumToAlbum(album)); - }).toList(), + Center( + child: Wrap( + spacing: 20, + runSpacing: 20, + children: albums.map((album) { + return AlbumCard(simpleAlbumToAlbum(album)); + }).toList(), + ), ), const SizedBox(height: 20), if (artists.isNotEmpty) @@ -139,12 +167,14 @@ class _SearchState extends State { style: Theme.of(context).textTheme.headline5, ), const SizedBox(height: 10), - Wrap( - spacing: 20, - runSpacing: 20, - children: artists.map((artist) { - return ArtistCard(artist); - }).toList(), + Center( + child: Wrap( + spacing: 20, + runSpacing: 20, + children: artists.map((artist) { + return ArtistCard(artist); + }).toList(), + ), ), const SizedBox(height: 20), if (playlists.isNotEmpty) @@ -153,12 +183,14 @@ class _SearchState extends State { style: Theme.of(context).textTheme.headline5, ), const SizedBox(height: 10), - Wrap( - spacing: 20, - runSpacing: 20, - children: playlists.map((playlist) { - return PlaylistCard(playlist); - }).toList(), + Center( + child: Wrap( + spacing: 20, + runSpacing: 20, + children: playlists.map((playlist) { + return PlaylistCard(playlist); + }).toList(), + ), ), ], ), diff --git a/lib/components/Shared/TracksTableView.dart b/lib/components/Shared/TracksTableView.dart index 7e0b9f8d..6cacc577 100644 --- a/lib/components/Shared/TracksTableView.dart +++ b/lib/components/Shared/TracksTableView.dart @@ -81,16 +81,12 @@ class TracksTableView extends StatelessWidget { ), ), Expanded( - child: Row( - children: [ - LinkText( - track.value.album!.name!, - MaterialPageRoute( - builder: (context) => AlbumView(track.value.album!), - ), - overflow: TextOverflow.ellipsis, - ), - ], + child: LinkText( + track.value.album!.name!, + MaterialPageRoute( + builder: (context) => AlbumView(track.value.album!), + ), + overflow: TextOverflow.ellipsis, ), ), const SizedBox(width: 10),