How to check if my Flutter Web app is currently running? - flutter

I am building a chat app in Flutter Web, and would like to add a feature for flagging when the user is "Online".
I want to send a bool to Firebase Firestore whenever the user launches and closes the app (for example, when the user launches the Flutter Web URL = true is being sent to Firestore for isOnline flag. And when the user closes the tap = false is being sent to isOnline).
For that, I would need a way to detect the lifecycle of the Flutter Web app, and to check whether the app is currently actively running or not.
Does anyone know what is the best way of doing that?
Thank you!

While you can easily update your firestore whenever a user opens your app (just add it to a point executed on launch, like before the runApp() part in your main method). However, there sadly is no guaranteed way to know, if a user closes your app. It could be force closed via task manager etc., robbing you of the ability to detect it. However, firebase offers the following solution to detect presence, see here.
You could also save a timestamp as the isOnline point and let it timeout. You could update it periodically in your app, giving you not a perfect but maybe a good enough idea if a user is online.

Related

Flutter best way to store App Notifications?

Is there a way to store app notifications in a flutter app. Most of the time this app will be closed and the app notifications will not directly be hitting the app. I would like to store app notifications in a notifications received section. I know I can get the notifications if the app is opened, but for if the app is closed and it just shows as a status, I can't get them in the device unless the user clicks on the notification message. and it opens the app. What options do I have and is what I am wanting to do even possible?
First interpretation of your question: If I read your question correctly, you're saying its not possible to have text in your notifications when the app is not open. This is definitely possible, almost all your apps create notifications on the device with more than just 'status'.
Another interpretation of your question: In response to a firebase cloud messaging message, you might want to save data or do some other background task, instead of just creating a notification the user sees. This is not enabled by default. There's lots more instructions on enabling and using this in the README
By default background messaging is not enabled. To handle messages in the background:
The golden nugget of information is _firebaseMessaging.configure(onBackgroundMessage: yourBackgroundMessageHandler) which is not listed under the receiving messages section.
Let me know if I misread. What do you mean by status?
You can use background Fetch to make the app stay in the background. The package will awaken an app in the background about every 15 minutes.

Can a flutter app run code on receiving a push notification while Not Running

I have push notifications working and have both a data and notification part in them. In the data part is a tag that tells the app what updates are available for the user.
The problem is that I would like the app to fetch those updates even if the user does not tap on the notification.
With other apps, eg Whatsapp, a notification is shown. Without tapping this notification, and even when the app is not running, the app downloads the data. For example if the user switches to flight mode right after receiving the notification and then opens whatsapp, the message and/or picture is there, already downloaded and displayed in the app.
So the question is how to get an app written in Flutter to download something in response to getting a push notification, regardless of whether the app is in the foreground, background, or not running.
Checkout isolate mentioned in Flutter background processes with a link to Medium Executing Dart in the Background with Flutter Plugins and Geofencing
Checking with GitHub issue Flutter should provide an abstraction for background execution and issue comments/references after that you may find some other examples. Bottom line is people need more examples.

Firebase - onDisconnectSetValue() fires when side button pressed

I'm trying to track when a user's app is about to terminate and send something to firebase when it happens. I looked through the Offline Capabilities documentation and tried using ".info/connected" as well as .onDisconnectSetValue().
I've had success with .onDisconnectSetValue(), but if the iPhone's side button is pressed and the iPhone goes to sleep, it fires and says the user is inactive (and I can't set another value until the user brings the app to the foreground again).
I tried moving .onDisconnectSetValue() to applicationWillTerminate() so it only catches terminations but it doesn't fire when I close the app (I assume because it can't in time)
Is there anything with Firebase that could set a value with the specific instance of the user closing the app?
The Firebase client can detect whether the app is online, with .info/connected and the app can tell the server to perform a specific write once it has gone offline with onDisconnect.
Firebase has no built in functionality for writing to the database when the user is about to close the app. That's something you're more likely to find on the iOS level, such as shown in iOS - detect when application exits and Which Event When i close app in iOS?. Typical lifecycle events on iOS are applicationWillTerminate, and applicationWillResignActive.

how to implement automatic update feature in iphone?

I am developing an iPhone app. It has an option called automatic update. it can be updated automatically once in a week/month/6 months. Could you please let me know How can I invoke my desired method based on this setting even my app was not opened by the user?
You can't, the user will need to open the app, there is no way to schedule update routines.
You could inform the user that he/she need to update with an UILocalNotification, but I would suggest only to update your app when the users starts it.
It's against apples rules to push an updated app within your app. You have to resubmit to the app store.
what you can do is that increase badge count of application icon on receiving notification from UIlocalNotification.
when user open application check the application badge count if it is more than zero apply your logic to update application.
else there will be no update popup to client.

Re-opening the app after finishing a call

I have a button in my app to make a telephone call, and I need to returen to my app after call is finished.
Is there any way to do this?
Can't be done. The user will have to open your app themselves.
If you mean that the user can make a phone call to another user, starting from your application, which closes said application, then what you are asking is simply impossible. The best you can do is have the application get into suspended mode. The user will need to get it back from the tray.
If for some reason your application has a button that calls the user (possibly by triggering some external server), then you should edit your question to be clearer... however, the user still needs to get your application back himself from suspended state.