Search code examples
flutterflutter-testflutter-local-notification

The backgroundHandler needs to be either a static function or a top level function to be accessible as a Flutter entry point


hey guys when I use onDidReceiveBackgroundNotificationResponse in flutter_local_notification I got an error can someone help me?

here is error

here is my code

actually I want navigate to second page after user select my notification in background mode but I got this problem


Solution

  • Put the definition of function used as backgroundHandler outside of any class.

    For example:

    // If in main.dart
    main() {
      // ...
    }
    
    ClassABC {
      void getLetter() => print('a and b');
    }
    
    // Notice how this is outside of classABC scope and main scope.
    backgroundHandler() {
      // Put handling code here.
    }
    

    For more clarity, could you post the whole page code?