扑动一个信号如何导航到通知点击屏幕?



我想在通知点击时导航到屏幕,但我无法在OneSignal.shared.setNotificationOpenedHandler中上下文,我尝试使用全局导航键,如下所示。

OneSignal.shared.setNotificationOpenedHandler(
(final OSNotificationOpenedResult result) {
const String s1 = 'Your account has been credited with';
const String s2 = 'New gift product has been added to your account';
final String? body = result.notification.body;
final int productId = result.notification.additionalData!['product_id'];
// tried it without the delay 
// tried it with addPostFramecallback
// all don't work
Future.delayed(Duration(milliseconds: 100), () {
navigatorKey.currentState!.pushReplacement(
MaterialPageRoute(builder: (_) => SomePage()),
);
print('After the frame has been painted');
});
});

我的导航器是这样设置的

final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
return GetMaterialApp(
title: 'Crown Store',
theme: theme,
navigatorKey: navigatorKey,
debugShowCheckedModeBanner: false,
home: const SplashScreen(),
);
}),

现在当我点击通知,它只是打开应用程序,没有别的吗?!

我的代码在final int productId = result.notification.additionalData!['product_id'];因为错误的数据类型现在一切正常

相关内容

  • 没有找到相关文章

最新更新