From e8b2a6d0c08f9dba6dfc1d7797c138050c4cc217 Mon Sep 17 00:00:00 2001 From: "Vicente J. Ruiz Jurado" Date: Wed, 15 Aug 2018 05:42:22 +0200 Subject: [PATCH] Messages dispatch when store is loaded --- lib/homePage.dart | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/homePage.dart b/lib/homePage.dart index 5e1aaf1..f4c2544 100644 --- a/lib/homePage.dart +++ b/lib/homePage.dart @@ -84,14 +84,14 @@ class _HomePageState extends State { super.initState(); _firebaseMessaging.configure(onMessage: (Map message) { debugPrint("onMessage in fireApp (isLoaded: ${store.state.isLoaded}): $message"); - _showItemDialog(message, _notifForMessage(message)); + _showItemDialog(message, _notifForMessage(message, store.state.isLoaded)); }, onLaunch: (Map message) { debugPrint("onLaunch (isLoaded: ${store.state.isLoaded}): $message"); - _notifForMessage(message); + _notifForMessage(message, store.state.isLoaded); _navigateToItemDetail(message); }, onResume: (Map message) { debugPrint("onResume (isLoaded: ${store.state.isLoaded}): $message"); - _notifForMessage(message); + _notifForMessage(message, store.state.isLoaded); _navigateToItemDetail(message); }); _firebaseMessaging.requestNotificationPermissions( @@ -282,7 +282,7 @@ class _HomePageState extends State { // https://pub.dartlang.org/packages/firebase_messaging#-example-tab- final FirebaseMessaging _firebaseMessaging = new FirebaseMessaging(); - FireNotification _notifForMessage(Map message) { + FireNotification _notifForMessage(Map message, bool isLoaded) { FireNotification notif; try { notif = new FireNotification( @@ -299,7 +299,12 @@ class _HomePageState extends State { debugPrint(e.toString()); } if (notif != null) - newNotifications.add(notif); + // if our store is loaded, we just dispatch the notification, if not, we wait til is loaded + if (isLoaded) { + store.dispatch(new AddFireNotificationAction(notif)); + } else { + newNotifications.add(notif); + } return notif; } }