Flutter how to access Provider Context in FCM backgroundHandler static method? - flutter

I have setup background notifications , Hive (To store Notification Locally Using Adapter Class) and Setup a ChangeNotifier ModelClass to get Updates in UI.
Problem: I want to Add Notification data In Hive With ModelClass to get Notified in UI ,If Application is Not Active.
Now I need to access Provider.of(context) in my backgroundHandler which must be a static method where there is no context.
All I need to do is to perform an action according to the data in the background notification.
Same As In this Post

Related

How can I use custom domain with call back function in firebase

I want my flutter app to use the custom domain not the firebase domain when calling the firebase function, and I want to use the callback not the http way, is that possible?
I want to call it this way:
final result = await FirebaseFunctions.instance.httpsCallable('FunctionName').call();
I already connected the custom domain to my firebase project, but now it is not using it, it is just using the firebase domain.

Flutter: reauthenticate on resume

Is there a way to reauthenticates user before all the stateful widgets resume in Flutter? I have multiple stateful widgets which does api calls on init state. The problem is when the auth token expires, it would log the user out without giving it a chance to fetch a new auth token since these requests are concurrent. I.e. When one request is fetching a new auth token, another request will not know and thus assume log the user out. I want to make sure a loading screen which re-authenticates the user is shown before other stateful widgets are added back to the hierarchy on resume.
I figure it out a way by pushing a new route on resume and disabling the back button. Its quick enough that they use doesn't even see the screen.

Storing session data in flutter across pages best practice

I have a Flutter app which holds a username and a token to communicate with a web service.
How can I manage the username and token efficiently using best practices? Currently I am writing them into a DB and select them each time I want to do a request.
I tried to use bloc provider flutter bloc with a BlocProvider. I have the states LoggedIn and LoggedOut and the events Login and Logout.
Furthermore, I had a look at
secure storage, but I can't get the data available throughout all pages.
Also, I am not using the firebase API.
Let me know if I should provide some code snippets.
I use SharedPreferences now. The API is very simple and I wrote a wrapper to get rid of the (Strings) keys. Furthermore, the wrapper holds the values for the current session. The advantage of that is, that I can address the values directly instead of needing to read them asynchronously.

How to pass value from one provider to another directly in flutter

I have 2 provider, general provider and blog provider. general provider is called on splash screen and here I normally call API that fetch most common data like blog, category, tags, notification and is stored in general provider. How can I use the same data and populate other provider from the 'general provider' itself ? reason to do so is save number of calls made on the start of the app.

Firebase Multiple Projects iOS Messaging Delegate

An iOS app has to use two firebase projects. I was super confused when I realized that the order of configuring the FirebaseApp seems to affect the messaging instance obtained by Messaging.messaging().
When I initialize the secondary app first, the Messaging delegate seems only to register registration token changes in the main app at func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String)
FirebaseApp.configure(name: AppDelegate.firebase_main_app_name, options: login_app_options)
FirebaseApp.configure()
Messaging.messaging().delegate = SOME DELEGATE OBJECT
But when I register the main app first, the messaging delegate seems to respond to only registration token changes in the secondary app.
When I register the main app first and
retrieve the FCM token by calling messaging_instance.retrieveFCMToken(forSenderID: AppDelegate.gcm_sender_id)
The token retrieved is different from the one from Messaging.messaging().fcmToken
But if I register the secondary app first then the two FCM tokens are the same.
The main firebase app can only send notification if I register the secondary app first.
I'm super confused by all this as this behavior isn't documented anywhere. What if I want to receive notifications from both firebase projects? Is there a way to tell which firebase project Messaing.messaging.delegate would reply to? Also, why does the order of configuring the two Firebase apps make a difference?