From a9a1d4c9dc24aaf3181dc4090d1822ebfe755991 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Fri, 1 Mar 2024 18:55:33 +0600 Subject: [PATCH] fix: album, artist page not loading #1282 --- lib/pages/album/album.dart | 9 +-- .../spotify_endpoints.dart | 55 ------------------- lib/services/queries/artist.dart | 7 +-- pubspec.lock | 25 ++++++--- pubspec.yaml | 8 ++- 5 files changed, 29 insertions(+), 75 deletions(-) diff --git a/lib/pages/album/album.dart b/lib/pages/album/album.dart index 72f9a9afc..4578aea22 100644 --- a/lib/pages/album/album.dart +++ b/lib/pages/album/album.dart @@ -15,9 +15,9 @@ import 'package:spotube/utils/type_conversion_utils.dart'; class AlbumPage extends HookConsumerWidget { final AlbumSimple album; const AlbumPage({ - Key? key, + super.key, required this.album, - }) : super(key: key); + }); @override Widget build(BuildContext context, ref) { @@ -69,8 +69,9 @@ class AlbumPage extends HookConsumerWidget { shareUrl: album.externalUrls!.spotify!, isLiked: isLiked, onHeart: albumIsSaved.hasData - ? () { - toggleAlbumLike.mutate(isLiked); + ? () async { + await toggleAlbumLike.mutate(isLiked); + return null; } : null, child: const TrackView(), diff --git a/lib/services/custom_spotify_endpoints/spotify_endpoints.dart b/lib/services/custom_spotify_endpoints/spotify_endpoints.dart index e27b701b7..d1c078a74 100644 --- a/lib/services/custom_spotify_endpoints/spotify_endpoints.dart +++ b/lib/services/custom_spotify_endpoints/spotify_endpoints.dart @@ -175,59 +175,4 @@ class CustomSpotifyEndpoints { ); return SpotifyFriends.fromJson(jsonDecode(res.body)); } - - Future artist({required String id}) async { - final pathQuery = "$_baseUrl/artists/$id"; - - final res = await _client.get( - Uri.parse(pathQuery), - headers: { - "content-type": "application/json", - if (accessToken.isNotEmpty) "authorization": "Bearer $accessToken", - "accept": "application/json", - }, - ); - final data = jsonDecode(res.body); - - return Artist.fromJson(_purifyArtistResponse(data)); - } - - Future> relatedArtists({required String id}) async { - final pathQuery = "$_baseUrl/artists/$id/related-artists"; - - final res = await _client.get( - Uri.parse(pathQuery), - headers: { - "content-type": "application/json", - if (accessToken.isNotEmpty) "authorization": "Bearer $accessToken", - "accept": "application/json", - }, - ); - - final data = jsonDecode(res.body); - - return List.castFrom( - data["artists"] - .map((artist) => Artist.fromJson(_purifyArtistResponse(artist))) - .toList(), - ); - } - - Map _purifyArtistResponse(Map data) { - if (data["popularity"] != null) { - data["popularity"] = data["popularity"].toInt(); - } - if (data["followers"]?["total"] != null) { - data["followers"]["total"] = data["followers"]["total"].toInt(); - } - if (data["images"] != null) { - data["images"] = data["images"].map((e) { - e["height"] = e["height"].toInt(); - e["width"] = e["width"].toInt(); - return e; - }).toList(); - } - - return data; - } } diff --git a/lib/services/queries/artist.dart b/lib/services/queries/artist.dart index 5ccc4955e..1b939c823 100644 --- a/lib/services/queries/artist.dart +++ b/lib/services/queries/artist.dart @@ -4,7 +4,6 @@ import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:spotify/spotify.dart'; import 'package:spotube/hooks/spotify/use_spotify_infinite_query.dart'; import 'package:spotube/hooks/spotify/use_spotify_query.dart'; -import 'package:spotube/provider/custom_spotify_endpoint_provider.dart'; import 'package:spotube/provider/user_preferences/user_preferences_provider.dart'; import 'package:spotube/services/wikipedia/wikipedia.dart'; import 'package:wikipedia_api/wikipedia_api.dart'; @@ -16,10 +15,9 @@ class ArtistQueries { WidgetRef ref, String artist, ) { - final customSpotify = ref.watch(customSpotifyEndpointProvider); return useSpotifyQuery( "artist-profile/$artist", - (spotify) => customSpotify.artist(id: artist), + (spotify) => spotify.artists.get(artist), ref: ref, ); } @@ -127,11 +125,10 @@ class ArtistQueries { WidgetRef ref, String artist, ) { - final customSpotify = ref.watch(customSpotifyEndpointProvider); return useSpotifyQuery, dynamic>( "artist-related-artist-query/$artist", (spotify) { - return customSpotify.relatedArtists(id: artist); + return spotify.artists.relatedArtists(artist); }, ref: ref, ); diff --git a/pubspec.lock b/pubspec.lock index fbdb19fc2..b3658253e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1118,10 +1118,10 @@ packages: dependency: "direct main" description: name: http - sha256: "759d1a329847dd0f39226c688d3e06a6b8679668e350e2891a6474f8b4bb8525" + sha256: "761a297c042deedc1ffbb156d6e2af13886bb305c2a343a4d972504cd67dd938" url: "https://pub.dev" source: hosted - version: "1.1.0" + version: "1.2.1" http_multi_server: dependency: transitive description: @@ -1961,11 +1961,12 @@ packages: spotify: dependency: "direct main" description: - name: spotify - sha256: e967c5e295792e9d38f4c5e9e60d7c2868ed9cb2a8fac2a67c75303f8395e374 - url: "https://pub.dev" - source: hosted - version: "0.12.0" + path: "." + ref: fix-spotify-precision + resolved-ref: "1ddea720130203021a815253e37ebe5c06845dd2" + url: "https://github.com/KRTirtho/spotify-dart.git" + source: git + version: "0.13.1" sqflite: dependency: transitive description: @@ -2278,6 +2279,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.0" + web: + dependency: transitive + description: + name: web + sha256: "1d9158c616048c38f712a6646e317a3426da10e884447626167240d45209cbad" + url: "https://pub.dev" + source: hosted + version: "0.5.0" web_socket_channel: dependency: transitive description: @@ -2368,5 +2377,5 @@ packages: source: hosted version: "2.0.2" sdks: - dart: ">=3.2.0 <4.0.0" + dart: ">=3.3.0 <4.0.0" flutter: ">=3.13.0" diff --git a/pubspec.yaml b/pubspec.yaml index a434a2f0b..6fbfa8b72 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -61,7 +61,7 @@ dependencies: hive_flutter: ^1.1.0 hooks_riverpod: ^2.4.3 html: ^0.15.1 - http: ^1.1.0 + http: ^1.2.0 image_picker: ^1.0.4 intl: ^0.18.0 introduction_screen: ^3.0.2 @@ -89,7 +89,10 @@ dependencies: shared_preferences: ^2.2.2 skeleton_text: ^3.0.1 smtc_windows: ^0.1.1 - spotify: ^0.12.0 + spotify: + git: + url: https://github.com/KRTirtho/spotify-dart.git + ref: fix-spotify-precision stroke_text: ^0.0.2 system_theme: ^2.1.0 titlebar_buttons: ^1.0.0 @@ -145,7 +148,6 @@ dev_dependencies: freezed: ^2.4.6 dependency_overrides: - http: ^1.1.0 system_tray: 2.0.2 flutter: