-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MissingPluginException when using external plugins (SharedPreferences, PathProvider, etc) #138
Comments
@ZiaUrRahmam sorry for unclear information, you have to replace YourPluginAndroid or YourPluginIOS with the plugin you using. |
i faced the same issue as well but with GetStorage & i tried using shared preferences but i kept on getting an exception. otherwise this is a great plugin and it so unfortunate that i could not preform what i wanted. |
@ReggieMiller1 the easiest way is try to use flutter beta channel. So, you will not be confused to register the plugins because you only need to call DartPluginRegistrant.ensureInitialized() |
alright i get you bro but please give me an example on how to do it DartPluginRegistrant.ensureInitialized() |
@ReggieMiller1 I already mentioned it at the top of this page. You should to call the method in |
thanks bro...i did what you said, at first i didnt understand but now everything works fine. thanks once again. |
@ekasetiawans I tried the above solution, but other error occur. Flutter version: |
btw it happens when socket IO is inside the flutter_background_service and SharedPreferences.getInstance() is called when have a coming notifications. Future onStart(ServiceInstance service) async { socket?.on('receive-notify-user', (data) async {//If this socket is triggered |
@ekasetiawans |
What do you mean by this : void onStart(ServiceInstance service){ I tried to replace "YourPluginIOS" and "YourPluginAndroid" by Shared prefe (for example), but the method registerWith() is not defined with any plugin. |
@hassanali2596 You have to add https://pub.dev/packages/shared_preferences_ios and https://pub.dev/packages/shared_preferences_android depending to your target platform. If you already using flutter 3, you can call |
@ekasetiawans
|
@lel101 that is different issue |
@ekasetiawans Sorry, Am I the only one having this error after applying this workaround(DartPluginRegistrant.ensureInitialized()) ? |
@lel101 you have to make sure which plugin that throws the error |
It throws error in SharedPreferences.getInstance(); Before the error was MissingPluginException but after the flutter upgrade to 3 and added the line DartPluginRegistrant.ensureInitialized(); the error change to PlatformException.
|
@lel101 which platform are you targeting? iOS or Android? |
@ekasetiawans IOS |
@lel101 okay, I will check it after work |
hi everyone, sorry for late @lel101 your issue is caused by the plugins not being registered in the iOS native side. I have update the version 2.1.0 to remove requirement for it, so I think it will be resolved once you update the dependency version. |
@ekasetiawans |
What if the plugin dont have registerWith() ? |
Hi, I'm using record (https://pub.dev/packages/record). I tried The exception: The package's code of v4.4.4: https://github.com/llfbandit/record/tree/404505e308d21cf7f0dc5ec180b213f7c26d3dd7 |
@nguyenphuc1995 Did you find a way to overcome the problem? |
When we use external plugin in background service, MissingPluginException will be thrown. This happens because the plugin we are using is not registered in the background service isolate (flutter engine) yet. To avoiding it, we have workaround below:
For Flutter prior to version 3.0.0, we have to call this code depending what plugins you use.
For Flutter version 3.0.0 and later, there is generated class to register all of plugins. So we can call like this
The text was updated successfully, but these errors were encountered: