1

I'm trying to add my background notification's data into local DB, that is hive (into a box). My notifications are handled in such a way that when they come in, they get added to a box. I have a separate class for notification in which I have a static method myBackgroundHandler. I'm trying to initialize hive using await Hive.initFlutter() or Hive.init(path) but it gives me this error:

Unhandled Exception: MissingPluginException(No implementation found for method getApplicationDocumentsDirectory on channel plugins.flutter.io/path_provider)

My function:

static Future<dynamic> myBackgroundMessageHandler(
      Map<String, dynamic> message) async {
    try {
       WidgetsFlutterBinding.ensureInitialized();
       Hive.initFlutter();
       Box box = await Hive.openBox("notifs");
       box.add(message);
      print(message);
    } catch (e) {
       print("In catch block");
       print(e);
    }
Lin Du
  • 88,126
  • 95
  • 281
  • 483
Yash Dixit
  • 216
  • 3
  • 12
  • https://stackoverflow.com/questions/62623763/flutter-using-path-provider-when-app-is-in-background/62771536#62771536 This solved this! – Yash Dixit Oct 26 '20 at 11:18

0 Answers0