MissingPluginException - Problem with several plugins on iOS only.
Christer-Muntean opened this issue · 3 comments
I have issues on iOS with this simple code sample, it throws an MissingPluginException. On Android everything works perfectly fine.
flutter_isolate: ^2.0.2
void connect(String args) async {
SpotifySdk.subscribeConnectionStatus().listen((event) {
print(event);
SpotifySdk.subscribePlayerState().listen((playerStreamData) {
print('track name: ${playerStreamData.track?.name}');
});
});
SpotifySdk.connectToSpotifyRemote(
clientId: 'xxxxxx',
redirectUrl: 'spotify-ios-quick-start://spotify-login-callback',
);
}
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await FlutterIsolate.spawn(connect, '');
Error spotify_sdk:
======= Exception caught by services library ======================================================
The following MissingPluginException was thrown while activating platform stream on channel player_state_subscription:
MissingPluginException(No implementation found for method listen on channel player_state_subscription)
When the exception was thrown, this was the stack:
#0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:175:7)
<asynchronous suspension>
#1 EventChannel.receiveBroadcastStream.<anonymous closure> (package:flutter/src/services/platform_channel.dart:516:9)
<asynchronous suspension>
====================================================================================================
Also having problem with shared_preferences:
[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)
@Christer-Muntean did you resolve the shared preferences issue?
@Christer-Muntean
After much trials I discovered you have to re-initialize the shared preferences plugin after entering isolate
Using these two plugins; add to pubspec.yaml
shared_preferences_ios: shared_preferences_android:
In your isolate function
if (Platform.isAndroid) { SharedPreferencesAndroid.registerWith(); } else if (Platform.isIOS) { SharedPreferencesIOS.registerWith(); }
Unfortunately due to the way that flutter_isolate
creates new isolates (by creating a new FlutterEngine), many plugins will have incompatibilities that have to be addressed on the plugin side (or at least with workarounds like the one @DennisMuchiri posted). There's not much that can be done on the flutter_isolate
side and this is unlikely to change in the near future.
@Christer-Muntean does reinitializing fix your issue?