大佬教程收集整理的这篇文章主要介绍了如何从 fcm 静态方法 flutter 访问上下文,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经在我的 Flutter 应用上实现了 FCM
。但是在我的静态方法中确实访问上下文,因为我想从后台处理程序方法在我的主页上加载一个对话框。有没有办法得到这个。
我的后台服务处理程序方法拒绝接受正在我的 homescreen.dart
文件中初始化的 psh 通知服务类的上下文方法。
Future<dynamic> _myBACkgroundmessageHandler (Map<String,dynamic> messagE) async { print("onBACkground message called"); print(messagE); return PushNotificationservice().showNotification(messagE); //I need to access context from here and pass it to my showNotification method but I can't } class PushNotificationservice{ BuildContext buildContext; final Firebasemessaging _firebasemessaging = Firebasemessaging(); _firebasemessaging.configure( onBACkgroundmessage: Platform.isIOS ? null:_myBACkgroundmessageHandler,); ///fetch user messaging token here getToken(); } voID fetchRIDeInfo(orderID,context,String typE) { print("fetching info"); showDialog( barrIErdismissible: false,context: context,builder: (BuildContext context) => CustomProgressDialog(status:'Fetching details',),); ProvIDer.of<MainBloc>(context,Listen: falsE). fetchRIDeInfo(context,orderID).then((value){ Navigator.pop(context); Navigator.push( context,MaterialPageRoute(builder: (context) => RIDerequestPage(orderID: orderID)),); }).catchError((error) { Navigator.pop(context); AlertManager.showToast(error.toString()); }); } Future showNotification(Map<String,dynamic> messagE) async { var androidplatformChAnnelSpecifics = new AndroIDNotificationDetails( 'chAnnel ID','chAnnel name','chAnnel desc',importance: importance.max,priority: Priority.high,playSound: true,icon: "ic_stat_ic_notification",largeIcon: DrawableresourceAndroIDBitmap("ic_launcher"),sound: RawresourceAndroIDNotificationSound("alert") ); var platformChAnnelSpecifics = new NotificationDetails(androID: androidplatformChAnnelSpecifics); await FlutterlocalnotificationsPlugin.show( 0,'New Incoming request','New incoming rIDe request',platformChAnnelSpecifics,payload: 'Default_Sound',); fetchRIDeInfo(message['data']['orderID'],buildContext,"onBACkgroundmessage");//this method don't get called cos build context is null } }
@H_489_13@解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
大佬总结
以上是大佬教程为你收集整理的如何从 fcm 静态方法 flutter 访问上下文全部内容,希望文章能够帮你解决如何从 fcm 静态方法 flutter 访问上下文所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。