From d2683c52d81d807be6ff72f15b8e9eb18181e211 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Sat, 1 Jun 2024 11:41:35 +0600 Subject: [PATCH] fix: some text are garbled in different parts of the app #1463 #1505 --- lib/provider/spotify/lyrics/synced.dart | 4 ++-- .../custom_spotify_endpoints/spotify_endpoints.dart | 13 +++++++------ lib/utils/service_utils.dart | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/provider/spotify/lyrics/synced.dart b/lib/provider/spotify/lyrics/synced.dart index 066596a9..afb27a6b 100644 --- a/lib/provider/spotify/lyrics/synced.dart +++ b/lib/provider/spotify/lyrics/synced.dart @@ -30,7 +30,7 @@ class SyncedLyricsNotifier extends FamilyAsyncNotifier ); } final linesRaw = Map.castFrom( - jsonDecode(res.body), + jsonDecode(utf8.decode(res.bodyBytes)), )["lyrics"]?["lines"] as List?; final lines = linesRaw?.map((line) { @@ -83,7 +83,7 @@ class SyncedLyricsNotifier extends FamilyAsyncNotifier ); } - final json = jsonDecode(res.body) as Map; + final json = jsonDecode(utf8.decode(res.bodyBytes)) as Map; final syncedLyricsRaw = json["syncedLyrics"] as String?; final syncedLyrics = syncedLyricsRaw?.isNotEmpty == true diff --git a/lib/services/custom_spotify_endpoints/spotify_endpoints.dart b/lib/services/custom_spotify_endpoints/spotify_endpoints.dart index d8600366..553f6824 100644 --- a/lib/services/custom_spotify_endpoints/spotify_endpoints.dart +++ b/lib/services/custom_spotify_endpoints/spotify_endpoints.dart @@ -75,7 +75,7 @@ class CustomSpotifyEndpoints { ); if (res.statusCode == 200) { - return jsonDecode(res.body); + return jsonDecode(utf8.decode(res.bodyBytes)); } else { throw Exception( '[CustomSpotifyEndpoints.getView]: Failed to get view' @@ -96,7 +96,7 @@ class CustomSpotifyEndpoints { ); if (res.statusCode == 200) { - final body = jsonDecode(res.body); + final body = jsonDecode(utf8.decode(res.bodyBytes)); return List.from(body["genres"] ?? []); } else { throw Exception( @@ -160,7 +160,7 @@ class CustomSpotifyEndpoints { "accept": "application/json", }, ); - final result = jsonDecode(res.body); + final result = jsonDecode(utf8.decode(res.bodyBytes)); return List.castFrom( result["tracks"].map((track) => Track.fromJson(track)).toList(), ); @@ -175,7 +175,7 @@ class CustomSpotifyEndpoints { "accept": "application/json", }, ); - return SpotifyFriends.fromJson(jsonDecode(res.body)); + return SpotifyFriends.fromJson(jsonDecode(utf8.decode(res.bodyBytes))); } Future getHomeFeed({ @@ -232,7 +232,7 @@ class CustomSpotifyEndpoints { final data = SpotifyHomeFeed.fromJson( transformHomeFeedJsonMap( - jsonDecode(response.body), + jsonDecode(utf8.decode(response.bodyBytes)), ), ); @@ -293,7 +293,8 @@ class CustomSpotifyEndpoints { final data = SpotifyHomeFeedSection.fromJson( transformSectionItemJsonMap( - jsonDecode(response.body)["data"]["homeSections"]["sections"][0], + jsonDecode(utf8.decode(response.bodyBytes))["data"]["homeSections"] + ["sections"][0], ), ); diff --git a/lib/utils/service_utils.dart b/lib/utils/service_utils.dart index 50e92347..1432eb53 100644 --- a/lib/utils/service_utils.dart +++ b/lib/utils/service_utils.dart @@ -115,7 +115,7 @@ abstract class ServiceUtils { Uri.parse(authHeader ? reqUrl : "$reqUrl&access_token=$apiKey"), headers: authHeader ? headers : null, ); - Map data = jsonDecode(response.body)["response"]; + Map data = jsonDecode(utf8.decode(response.bodyBytes))["response"]; if (data["hits"]?.length == 0) return null; List results = data["hits"]?.map((val) { return {