MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences) while getting FCM in background

403

please reference to my post

you need to register share_preference for background access

io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin.registerWith(registry.registrarFor("io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin"));
Share:
403
Urvesh Rathod
Author by

Urvesh Rathod

Updated on January 03, 2023

Comments

  • Urvesh Rathod
    Urvesh Rathod over 1 year

    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.

    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() {
    
    }
    
    • Anmol Mishra
      Anmol Mishra about 2 years
      Something that work for me is: Delete your pubspec.lock, and press Pub Get in your pubspec.yaml, it'll regenerate pubspec.lock file again and should fix the problem.
    • Urvesh Rathod
      Urvesh Rathod about 2 years
      @Amol Mishra It doesn't work for me.
    • Anmol Mishra
      Anmol Mishra about 2 years
      you try this command Flutter clean
    • Urvesh Rathod
      Urvesh Rathod about 2 years
      @Amol Mishra i have tried flutter clean also its not working for me.
    • Pokaboom
      Pokaboom about 2 years
      try uninstalling the app and reinstalling it
    • Urvesh Rathod
      Urvesh Rathod about 2 years
      @Pokaboom i have already try this many times. but not working getting same error.
  • Urvesh Rathod
    Urvesh Rathod about 2 years
    I have already done in my application.kt but its not working for me.
  • MerdanDev
    MerdanDev about 2 years
    In the latest versions of flutter plugins are automatically registered by generated_plugin_registrant.dart, in this case FirebaseMessaging.onBackgroundMessage uses seperate isolate than main and in this isolate all third party dependencies gets unavailable.
  • George ozzy
    George ozzy almost 2 years
    @MerdaDev, How can we fix this then?