Skip to content
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

initialize() fails when called from a headless task #681

Closed
jweidner-mbible opened this issue Jun 25, 2020 · 1 comment
Closed

initialize() fails when called from a headless task #681

jweidner-mbible opened this issue Jun 25, 2020 · 1 comment

Comments

@jweidner-mbible
Copy link

I use the following class to display a notification.

import 'package:flutter_local_notifications/flutter_local_notifications.dart';

class NotificationsService {

  static void showNotification( String message, { String title = ''} ) async {
    var platformChannelSpecifics = NotificationDetails(AndroidNotificationDetails( "id2", "name2", "description2" ), IOSNotificationDetails());

    // Initialize local notifications plugin
    FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
    var initializationSettings =
    InitializationSettings(
        AndroidInitializationSettings("ic_launcher"),
        IOSInitializationSettings());
    await flutterLocalNotificationsPlugin.initialize(initializationSettings);
    await flutterLocalNotificationsPlugin.show(0, title, message, platformChannelSpecifics);
  }
}

This seems to work fine when called in response to some UI event while my app is running. However, I am integrating with flutter_background_geolocation plugin and would like to display a notification when a geofence event occurs. I'm using
bg.BackgroundGeolocation.registerHeadlessTask(headlessTask). However, if my headlessTask method calls the above showNotification method, it fails and logs the error:

[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method initialize on channel dexterous.com/flutter/local_notifications)
#0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:154:7)
#1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:329:12)
#2 AndroidFlutterLocalNotificationsPlugin.initialize (package:flutter_local_notifications/src/platform_flutter_local_notifications.dart:67:27)
#3 FlutterLocalNotificationsPlugin.initialize (package:flutter_local_notifications/src/flutter_local_notifications_plugin.dart:97:13)
#4 NotificationsService.showNotification (package:flutter_tic_tac_toe/services/notifications.dart:14:43)
#5 headlessTask (package:flutter_tic_tac_toe/main.dart:98:26)

@jweidner-mbible
Copy link
Author

Dupe of #238

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant