-
Notifications
You must be signed in to change notification settings - Fork 91
Description
Is this a how to question?
No
Is this a native Spotify SDK issue?
No
Have you searched for existing issues?
Yes
Are you using a Free or Premium Spotify account?
Premium
Are you aware of the limitations of Free Spotify accounts?
Yes
Expected behavior
Connection Status subscription works in android release mode
Describe the bug
SpotifySdk.subscribeConnectionStatus() doesn't work when compiled in release mode on android.
Steps to Reproduce
Steps to reproduce the behavior:
- Create a new Flutter application with Android platform
- Add Spotify_sdk package -> flutter pub add spotify_sdk
- Run auto setup for android -> dart run spotify_sdk:android_setup
- Run -> flutter build apk
- Try to listen the function SpotifySdk.subscribeConnectionStatus()
- Use the function SpotifySdk.connectToSpotifyRemote() to sign in
- Nothing happens (The connection status event is not working).
Spotify_sdk Flutter package version 3.0.2
Flutter version 3.24.3
spotify_sdk:
dependency: "direct main"
description:
name: spotify_sdk
sha256: "4c7a3b79f0370e7ae8ac07cad5e630d0bb3ad118f4c16219ec37f6988a65465e"
url: "https://pub.dev"
source: hosted
version: "3.0.2"
Target Platform, Version & Device
- OS & Version: Tested Android 14 and 15
- Device: Tested in Android Emulator Medium Phone API 34 and 35
Development OS
- Windows
That bug only happens in release mode (on Android), where the Connection Status does not work correctly due to probably a parsing problem.
Found out that:
In the function ConnectionStatus _$ConnectionStatusFromJson(Map<String, dynamic> json) in the file:
"C:\Users{USERNAME}\AppData\Local\Pub\Cache\hosted\pub.dev\spotify_sdk-3.0.2\lib\models\connection_status.g.dart"
The parameter json is filled with keys:'a', 'b', 'c' and 'd' when in release mode, instead of 'connected', 'message', 'errorCode' and 'errorDetails'. The values are ok but the json keys are wrong.
As a temporary workaround I modified two files:
First, I added this import at the very top of the file: C:\Users\{USERNAME}\AppData\Local\Pub\Cache\hosted\pub.dev\spotify_sdk-3.0.2\lib\models\connection_status.dart
import 'package:flutter/foundation.dart';
Second, I modified this function on the file: C:\Users\{USERNAME}\AppData\Local\Pub\Cache\hosted\pub.dev\spotify_sdk-3.0.2\lib\models\connection_status.g.dart
ConnectionStatus _$ConnectionStatusFromJson(Map<String, dynamic> json) {
if (kReleaseMode) {
return ConnectionStatus(
json['b'] as String?,
json['c'] as String?,
json['d'] as String?,
connected: json['a'] as bool,
);
} else {
return ConnectionStatus(
json['message'] as String?,
json['errorCode'] as String?,
json['errorDetails'] as String?,
connected: json['connected'] as bool,
);
}
}
After the changes ConnectionStatus seems to work properly.