我有 Flutter 应用程序,它可以与 OneSignal 插件一起正常工作,但是我有一个问题,当单击通知时,如果应用程序关闭或在后台运行,我将无法打开应用程序,但是当它在前台打开通知时没有问题。我想在收到通知时打开应用程序,然后单击它。
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
void initState() {
super.initState();
initPlatformState();
}
static const String oneSignalAppId = "XXXXXX-XXXXX-XXXXXXX-XXXXXX-XXXXX";
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Manchester United"),
elevation: 0,
),
backgroundColor: Colors.red[200],
body: const WebView(
initialUrl: 'https://manchester-united.football/',
javascriptMode: JavascriptMode.unrestricted,
),
);
}
Future<void> initPlatformState() async {
OneSignal.shared.setAppId(
oneSignalAppId,
); //OneSignal.shared.setInFocusDisplayType(OSNotificationDisplayType.notification);
OneSignal.shared
.setNotificationOpenedHandler((OSNotificationOpenedResult result) {
var data = result.notification.additionalData;
globals.appNavigator?.currentState?.push(MaterialPageRoute(
builder: (context) => SecondPage(
postId: data!["myappurl"].toString(),
),
));
});
}
}