backgroundHandler 需要是静态函数或顶级函数才能作为 Flutter 入口点进行访问

Emi*_*iri 4 flutter flutter-test flutter-local-notification

嘿伙计们,当我在flutter_local_notification中使用 onDidReceiveBackgroundNotificationResponse 时,我收到错误有人可以帮助我吗?

这是错误

这是我的代码

实际上我想在用户在后台模式下选择我的通知后导航到第二页,但我遇到了这个问题

Cle*_*rin 9

将用作backgroundHandler 的函数的定义放在任何类之外。

例如:

// 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.
}
Run Code Online (Sandbox Code Playgroud)

为了更清楚起见,您可以发布整个页面的代码吗?