How to get real-time notifications in Flutter - flutter

I am new in Flutter, I have used web_socket_channel in my app. Now I want to get notifications when the app is not running. Keeping the app running in the background is not possible, so what do you recommend me to do?
So far I found them:
Websocket Manager- They claim to open socket connection in the background, but I couldn't find enough resources to find out.
https://pub.dev/packages/websocket_manager
Background Fetch - Opens the app for a few seconds in the background periodically (15 minutes or more). I do not prefer this one actually :( .
https://pub.dev/packages/background_fetch

You can use firebase_messaging, it's easy to implement in android and got a bit of configurations to do in IOS but it's good.

Related

How to make periodic background fetches in Flutter iOS and Android App?

I am developing an app that should fetch an API periodically (every 15 or 30 minutes). I am using Flutter for the frontend development. The app should be available for both Android and iOS devices.
The background task includes a call to the backend. In the backend, a worker is determining certain data (this can take up to one minute) and sending it then back to the frontend. The task has to be (at least partially) initiated by the frontend, as an decryption key is passed to the backend.
I had the idea to use Firebase Cloud Messaging to push the requested data to the devices. Unfortunately, it seems to be necessary to have the Apple Development Program enrolled to use it. As the app is an university project, and I'm not even sure, if the FCM approach is the best one, I don't want to pay the 99€ for the enrollment.
Beside the FCM approach, I found some flutter packages like "background_fetch", to pull the data instead of pushing it, which wouldn't be a problem for me. But all packages I found have the problem, that they work differently on iOS and Android, and are also not very reliable in terms of background task management by the respective operating systems.
Is there any "simple" solution for this problem, like a flutter package allowing me to schedule periodic background tasks on both iOS and Android, which is mostly reliable in that the time periode is respected at least roughly and the background task is not killed while waiting for the response? Or will I have to implement an own server-side Push-Service to avoid the costs for the Apple Developer Program?
Thank you in advance!

Keep websocket connection alive Flutter

I've been running through this for along time and i'm still stuck.
I'm working on a chat app using Flutter/Dart that it's based on Websocket .
I would like to keep the state of a connected user alive even if he terminates the app.
At this moment :
Foreground : Fully working
Paused : Fully Working
Background : Fully Working
Terminated : Not Working
I'm using Websocket_manager as a package to help
Thank you for your time.
I think this is not possible, you can try something like Firebase cloud messaging (link here), or something similar.
I'm working with FCM for the notifications and sometimes when the app is terminated and phone is locked.
it doesn't receive notifications.
I don't know what i should use right now :/
I am working on same solution, trying to keep app in the background - similar to what is Viber, WhatsApp, Signal etc doing. If I get it working, will share complete project. I have setup FCM google messaging and next bit is to have websocket. It does happen that notification from FCM does not go through.
If someone can explain how Viber, Signal and other can keep apps running and with 99 or 100% delivery rate.
UPDATE:
I have not try this yet but looks promising https://github.com/ppicas/flutter-android-background
And HowTo:
https://medium.com/stuart-engineering/keep-flutter-running-background-on-android-6ffc85be0234

How to run background service in flutter

I am trying to develop a flutter app which will fetch data from server every 10 seconds using timer. It all works well when in foreground. So I followed the documentation provided here Work Manager and I can get the data from server even when app is in background but cannot reduce the frequency below 15 minutes. I dont want to code in native android and ios. How can I approach this situation ? Is there a solution I am missing ?
Please take a look at the tutorial about background job processing

iOS: how to run code in background when app is closed?

Using Swift5.2, iOS13.4,
I try to run code in the background (when app is fully closed) at a particular date.
Local Notifications work great if App is foreground (or if user-interaction then also in background).
Some people say (here or here, that you will have to use "background timer" or "Packet Tunnel VPN" tricks in order to keep your app alive in background and in order to have a chance to run some callback-method eventually.
But is there no easier way ?
My goal is to execute code at a particular date in the future (fully from background when app is closed). How would you do that with Swift5 and >iOS12 ?
Short answer, there is no easy way to do this. You can use Background Fetch to perform some actions if the app is running in the background (not fully closed). The easiest way I’ve found to perform actions when the app is fully closed is connecting to Google Firebase and using cloud functions (but those are written in JavaScript? I believe and it’s fairly complex).

how to use network connectivity plugin in background process in flutter

Is it possible to use connectivity plugin in background process?
I don't know how to call dart code in background there is little about this in docs.
I need this functionality to sync offline data with backend whenever there is a connection wether app is in foreground or background and app is in killed state like the way Whatsapp syncs messages.
You can use existing plugins for background execution (on android & ios usually in a roughly 15 minute interval)
https://pub.dev/packages/background_fetch
There is also a article dedicated to using isolates for background executions
https://flutter.dev/docs/development/packages-and-plugins/background-processes
https://medium.com/flutter/executing-dart-in-the-background-with-flutter-plugins-and-geofencing-2b3e40a1a124