3

I am trying to setup the most basic version of flutter local notifications but I keep getting this error

[ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: MissingPluginException(No implementation found for method initialize on channel dexterous.com/flutter/local_notifications)

When looking at my autogenerated plugin registrant java file

package io.flutter.plugins;

import androidx.annotation.Keep;
import androidx.annotation.NonNull;

import io.flutter.embedding.engine.FlutterEngine;

/**
 * Generated file. Do not edit.
 * This file is generated by the Flutter tool based on the
 * plugins that support the Android platform.
 */
@Keep
public final class GeneratedPluginRegistrant {
  public static void registerWith(@NonNull FlutterEngine flutterEngine) {
    flutterEngine.getPlugins().add(new io.flutter.plugins.firebase.firestore.FlutterFirebaseFirestorePlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.firebase.auth.FlutterFirebaseAuthPlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.firebase.core.FlutterFirebaseCorePlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.firebasedynamiclinks.FirebaseDynamicLinksPlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.firebase.storage.FlutterFirebaseStoragePlugin());
    flutterEngine.getPlugins().add(new com.byneapp.flutter_config.FlutterConfigPlugin());
    flutterEngine.getPlugins().add(new app.meedu.flutter_facebook_auth.FlutterFacebookAuthPlugin());
    flutterEngine.getPlugins().add(new com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.googlesignin.GoogleSignInPlugin());
  }
}

I find that the plugin seems to be registered. So why does it throw the error then. This is the code I use

import 'package:flutter_local_notifications/flutter_local_notifications.dart';

class FirebaseMessagingProvider extends PushNotificationProvider {
  final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();

  FirebaseMessagingProvider() {
    initializeLocalNotifications();
  }

  Future<void> initializeLocalNotifications() async {
      const AndroidInitializationSettings initializationSettingsAndroid =
      AndroidInitializationSettings('app_icon');

    const AndroidNotificationChannel channel = AndroidNotificationChannel(
      'high_importance_channel', // id
      'High Importance Notifications', // title
      'This channel is used for important notifications.', // description
      importance: Importance.max,
    );

    final InitializationSettings initializationSettings =
        InitializationSettings(android: initializationSettingsAndroid);

    await flutterLocalNotificationsPlugin.initialize(initializationSettings,
        onSelectNotification: (_) async => print("notified"));

    await flutterLocalNotificationsPlugin
        .resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>()
        ?.createNotificationChannel(channel);
  }
}

The error is being thrown at this line

await flutterLocalNotificationsPlugin.initialize(initializationSettings,
    onSelectNotification: (_) async => print("notified"));

I looked at the following github issue

https://github.com/MaikuB/flutter_local_notifications/issues/238

but it seems to be targeted mostly at flutter 1 projects where you had to register the plugins yourself. I did try with the application.kt but it did not work.

So why am a getting this error?

Flutter version: Flutter 2.2.0 • channel stable • https://github.com/flutter/flutter.git flutter_local_notifications: ^6.0.0

anonymous-dev
  • 2,897
  • 9
  • 48
  • 112

0 Answers0