Skip to content

[shared_preferences] MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences) in isolate #98473

Closed

Description

@urvesh-educloud

I'm working on a Flutter app in which I'm using the shared_preferences: ^2.0.13 package.

Flutter version : 2.10.1 (latest)
gradle version: 6.7
Android gradle plugin version: 4.1.3
kotlin version: 1.6.10
flutterEmbedding 2 (in android menifiest)

MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences).

While getting FCM message received in background.
Kindly refer the below code

main.dart

Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  await Firebase.initializeApp();

  print('Got a message onBackgroundMessageHandler_');
  print("Handling a background message: ${message.messageId}");

  print('Shared pref process starts');
  SharedPreferences sf = await SharedPreferences.getInstance();
  sf.setString("key", "Value");
  print('${sf.getKeys()}');
  print('Shared pref process ends');
}
void main() async{
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();

  FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);

  runApp(const MyApp());
}

MainActivity.kt

class MainActivity: FlutterActivity() {

}

Activity

  1. darshankawar commented on Feb 15, 2022

    @darshankawar
    Member

    @urvesh-educloud
    Since firebase_messaging is third party plugin, can you confirm if the same exception occurs without using that plugin ?
    If so, please provide an isolated minimal reproducible code sample. You can try the same using counter app using the plugin and see if you still get same error or not.

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Feb 15, 2022
  3. urvesh-educloud commented on Feb 15, 2022

    @urvesh-educloud
    Author

    @darshankawar i need to call shared_preferences to store some value
    i have already try with flutter clean, delete pubspeck.lock > pub get

  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Feb 15, 2022
  5. darshankawar commented on Feb 15, 2022

    @darshankawar
    Member

    @urvesh-educloud
    There are already many similar issues filed and were solved. You can just try to search in this repo. One among them is this. See if it helps.
    If not, as requested earlier, please provide an isolated minimal reproducible code sample.

  6. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Feb 15, 2022
  7. kuhnroyal commented on Feb 15, 2022

    @kuhnroyal

    I am suddenly seeing this error as well after running flutter pub upgrade. flutter-team-archive/plugins@08ba6bd looks suspicious

  8. kuhnroyal commented on Feb 15, 2022

    @kuhnroyal

    This is definitely a problem with the commit above. The updates to the individual platform packages breaks all my background isolates, no matter if FCM, flutter_isolate or flutter_downloader. The correct plugin instance is not correctly registered in the background isolates anymore (not sure what exactly is required there, but now the method channel names are different and the native side is listening on a different channel name).

  9. kuhnroyal commented on Feb 15, 2022

    @kuhnroyal

    @BeMacized Do you have an idea what could be missing regarding the registration in background isolates?

  10. kuhnroyal commented on Feb 15, 2022

    @kuhnroyal
  11. maximilienGilet commented on Feb 16, 2022

    @maximilienGilet
  12. rahulmawana commented on Feb 16, 2022

    @rahulmawana

    I am suddenly seeing this error as well after running flutter pub upgrade. flutter/plugins@08ba6bd looks suspicious

    same here, I started to facing this as I did flutter pub upgrade, currently it was updated "Flutter 2.10.1"

  13. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Feb 16, 2022
  14. stuartmorgan-g commented on Feb 16, 2022

    @stuartmorgan-g
    Contributor

    Thanks for filing this; I've filed #98591 for the general problem (which we weren't aware of when updating the plugins).

    While we investigate whether we can adjust Flutter to handle this automatically in the future, here's a workaround that should allow using the current versions of the plugins:

    • Add dependencies on shared_preferences_android and shared_preferences_ios.
    • At the beginning of your background isolate entry point, add something like:
      if (Platform.isAndroid) SharedPreferencesAndroid.registerWith();
      if (Platform.isIOS) SharedPreferencesIOS.registerWith();
      
  15. 30 remaining items

  16. tatraef commented on Mar 7, 2022

    @tatraef
  17. pedromassango commented on Mar 7, 2022

    @pedromassango
    Member

    @tatraef your code should look like the image below:

    Screen Shot 2022-03-07 at 11 18 52 AM

  18. tatraef commented on Mar 7, 2022

    @tatraef
  19. stuartmorgan-g commented on Mar 7, 2022

    @stuartmorgan-g
    Contributor

    @tatraef Please file a new issue with details about your case. You are using versions of shared_preferences_* that this issue doesn't apply to so whatever issue you are having is unrelated to this one.

  20. stuartmorgan-g commented on Mar 7, 2022

    @stuartmorgan-g
    Contributor

    Note: I have hidden all comments that instruct people to pin old versions of packages, as that a) is causing a lot of confusion (since people are trying to combine it with manual plugin registration, which cannot work) and b) is not a good idea now as it will prevent receiving any future updates. I would ask anyone commenting here to refrain from posting new comments telling people to do that.

    To summarize the actual solution: at the start of the entry point for any isolate that needs to use plugins (where you are presumably already calling WidgetsFlutterBinding.ensureInitialized()):

    • For Flutter 2.11+ (currently master), call DartPluginRegistrant.ensureInitialized(), which will run the Dart plugin registration for all plugins that need it.
    • For older versions of Flutter, manually call the registerWith of any plugin implementations you use that have Dart registration. For shared_preferences, see above for details.

    Since the plan going forward is to require DartPluginRegistrant.ensureInitialized() in isolates, closing as fixed.

  21. prjmax commented on Mar 7, 2022

    @prjmax
  22. stuartmorgan-g commented on Mar 8, 2022

    @stuartmorgan-g
  23. changed the title [-]MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences) in isolate[/-] [+][shared_preferences] MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences) in isolate[/+] on Mar 8, 2022
  24. added
    r: fixedIssue is closed as already fixed in a newer version
    on Mar 8, 2022
  25. github-actions commented on Mar 22, 2022

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  26. locked as resolved and limited conversation to collaborators on Mar 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority issues at the top of the work listfound in release: 2.10Found to occur in 2.10found in release: 2.11Found to occur in 2.11has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: shared_preferencesPlugin to read and write Shared Preferencespackageflutter/packages repository. See also p: labels.r: fixedIssue is closed as already fixed in a newer version

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions