问题描述
在我的Flutter应用程序中,我必须在推送通知到达后立即更新提供商的状态保留,以便可以重建UI。 PushNotifications服务是这样的类(不是小部件):
class PushNotifications {
...
Future<void> init() async {
_firebaseMessaging.configure(onMessage: (Map<String,dynamic> data) {
// here I receive the data from the notification that I have to add to the provider
});
}
}
这是我简单的提供者:
class NewsProvider with ChangeNotifier {
List<News> _news;
get news => _news;
NewsProvider();
void addNews(News news) {
_news.add(news);
notifyListeners();
}
}
由于PushNotifications类没有上下文,因此我无法提出实现目标的方法。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)