
As i don't want to download everytime mine app come to foreground (i.e. user shift to mine app from someother app)

realistically, not. iOS and Android can close background apps at any time.
You should be able to hook into lifecyle of your app using flutter. The realtime subscription should also have an onDone
callback

So when ondone is called, i can restart the connection again to keep it alive?

you can try...but again, don't expect it to stay connected if the app isn't in the foreground

Oh. Okay so it will again be killed. Better approach will be to check if it was closed and if yes then download the data when user comes again on foreground ?

you can either:
- use push notifications to send data to the device
- have a background job that tries to sync the data

Ok. Thanks 👍🏻

How to check if a realtime onnection is still active or not? When I closed the subscription it didn't gave any error but realtime was not active

I don't think the underlying websocket connection is exposed

I didn't understand what you mean. Can please explain more?

the websocket connection (https://github.com/appwrite/sdk-for-flutter/blob/f8480fdeecfb23782bd5b33d0e2a7db44fc8c391/lib/src/realtime_mixin.dart#L19) is a private property

So, my app was inactive for sometime and I updated a data to check realtime. But it didn't get updated in frontend. So subscribtion.close should have thrown the error which would have refreshed the data (i put it inside the error, so that if realtime was not active it should have refreshed the data). But it didn't worked

what version of the Appwrite Flutter SDK do you have and is your app running on mobile or web?

On flutter. And appwrite verison is 0.15.3 in server and flutter 6.0.0


ah ya...that version is older so you're affected by https://github.com/appwrite/sdk-for-flutter/issues/108

in short, in your version of the SDK, the realtime stream is not closed when the web socket closes

Ohh. So realtime was not active but it showed as active? As it didn't threw any error when I tried to close it? Any way to solve this issue or check it? So that I don't have to refresh data everytime my user brings app to foreground

if you need to be notified about when the websocket closes, you can refer to how it was fixed in the PR for that issue I linked. You may need to fork the SDK or something to apply the patch to the SDK for your version

Ok. These are the changes done to correct it? https://github.com/appwrite/sdk-for-flutter/commit/281e5d553fa7c25e6f5c9810cc73019648c99cca
Should, I directly change it in the src file of flutter and release it in the latest version, this will work right?

Thanks, these are the only lines that need to be changed, can you please confirm?
}, onDone: () {
for (var list in _channels.values) {
for (var stream in list) {
stream.close();
}
}
_closeConnection();
}, onError: (err, stack) {
for (var list in _channels.values) {
for (var stream in list) {
stream.sink.addError(err, stack);
}
}
if (_websok?.closeCode != null && _websok?.closeCode != 1008) {
debugPrint("Reconnecting in one second.");
Future.delayed(Duration(seconds: 1), _createSocket);
}
});

scanning quickly, it looks okay...

Ok. Thanks a lot 🙏🏻

I updated the package file and tried many things but neither : onError or onDone worked! I don't know whats the issue
liveDataSubscription!.stream.listen((data) {
///
///
}, onDone: () {
print('On Done');
liveStreamBroken = true;
}, onError: (error, st) {
print('On Error - $error, $st');
liveStreamBroken = true;
});
It should have worked

I would use the debugger and step through to see what's going on
Recommended threads
- Function 404 error - Deployment with the...
I have a function in my Appwrite Cloud (free plan) project that cannot be accessed or deleted (404 in both UI and CLI). I'm stuck at the 5 functions limit and c...
- 1.6 to 1.7 does not work
Appwrite (self-hosted) stopped working after updating from 1.6.2 that was stable. Getting the general_server_error. Mentioning I fallowed all steps for upgrad...
- How to have two Appwrite Instances in Sy...
Hello, I am new to Appwrite. I am currently developing a training app for our sport with a friend and we would like to use Appwrite for this. We would like to d...
