Back

[SOLVED] How to setup offline-online sync and use it in flutter?

  • 0
  • Tools
  • Flutter
  • Databases
Vedsaga
7 Apr, 2023, 16:36

and also it seems to be slowing down the app by alot, it the http request being like opened in the new isolate or is it in the same ?

TL;DR
The user was seeking help on setting up offline-online sync in a Flutter project. They mentioned that they want to wait for an architecture redesign before proceeding. Other users provided suggestions and references to documentation. The user also discussed returning documents during creation and optimistic updates. In the end, they clarified their approach and mentioned that the app seems to be slowing down. Solution: No specific solution provided in the thread. Further troubleshooting is required to identify the cause of the app slowdown.
Drake
7 Apr, 2023, 16:37

how are you handling the documents in your app?

Vedsaga
7 Apr, 2023, 16:38

I didn't get it

Drake
7 Apr, 2023, 16:38

what's returning empty?

Drake
7 Apr, 2023, 16:39

no we're not using a separte isolate, but this is a good suggestion

Vedsaga
7 Apr, 2023, 16:40

so, I removed the wrapper, and how I am handling is I expected document to be retuned else it will stuck at loading indicator

Drake
7 Apr, 2023, 16:40

please see my original message about optimistic updates

Drake
7 Apr, 2023, 16:41

where and how are you using this create method?

Vedsaga
7 Apr, 2023, 16:42

I guess I didn't get it this part optimistic updates could you explain little bit more

Drake
7 Apr, 2023, 16:43

Write operations will not resolve until online again. So, if you're offline and you have:

TypeScript
final document = await _database.createDocument();

execution will be stuck at this line until the device goes online again

Vedsaga
7 Apr, 2023, 16:44

So, I am follwing repository Arch using Bloc, and what happens is when user click on button it trigger a event that call a Repository function which then call this Centeral Appwrite Repository... dart Future<Either<Failure, Document>> createBeatInRemote( CreateBeatRequestModel requestModel, ) async { try { final cacheResponse = await Instance.appwrite.create<CreateBeatRequestModel>( collectionId: AppwriteCollectionIDs.beat, requestModel: requestModel, ); return Right(cacheResponse); } catch (error) { return Left(Failure.fromErrorObject(error)); } }

Vedsaga
7 Apr, 2023, 16:48

oh, got it... this seems I would need wrapper but have to handle is different way I think because if Appwrite doesn't return Document then whole app won't work I guess I have to come-up with some other way I think because no matter what need to return object or exception so that repository can then passed to bloc layer which then can notifiy the bloc.

Vedsaga
7 Apr, 2023, 16:48

But, I wonder when I try to read the document it it getting returned, then while create why not return the document ?

Drake
7 Apr, 2023, 16:49

again, see:

TypeScript
  void submitTodo() async {
    final messenger = ScaffoldMessenger.of(context);
    final newTodo = Todo(
      content: inputController.text,
      id: ID.unique(),
    );

    // create optimistically
    databases.createDocument(
      databaseId: constants.appwriteDatabaseId,
      collectionId: constants.appwriteCollectionId,
      documentId: newTodo.id,
      data: {"content": newTodo.content, "isComplete": newTodo.isComplete},
    ).catchError((e) {
      // handle errors
      messenger.showSnackBar(createErrorSnackBar(e.toString()));
      todos.remove(newTodo);
    });

    inputController.text = '';
    setState(() {
      todos.add(newTodo);
    });
  }

Notice how the todo is added to the list of todos without awaiting the createDocument()

Drake
7 Apr, 2023, 16:50

because the resolution happens when the server receives the request and provides the response

Vedsaga
7 Apr, 2023, 16:52

right, I am asking while reading in offline we are receving the document right, so why not return that it-self during the creation

Drake
7 Apr, 2023, 16:52

you can only resolve a future once and it's reserved for when the server responds

Drake
7 Apr, 2023, 16:54

in case there's an error from the server, you can respond accordingly

Vedsaga
7 Apr, 2023, 16:58

I got the point, so you are saying if & when internet is back then you receive the document, I guess it make sense, it would be helpful to go-through the RFC & Arch Diagram that will clear doubts... rn just thinking how to twick my Arch to make offine workable

Drake
7 Apr, 2023, 18:16
Vedsaga
7 Apr, 2023, 18:18

thank you, this makes sense. I saw some Read.me doc. supper excited to deep dive into it

Tessa
7 Apr, 2023, 20:46

@Vedsaga I'm just checking if everything is good so we can close this topic (marking it as solved) πŸ™‚

Vedsaga
8 Apr, 2023, 04:51

I guess initial test seems to be working fine, so we may can close this. I just eagerly waiting for RFC to re design architecture of my project to support offline. And after that if I stuck somewhere I can create new ticket.

Tessa
8 Apr, 2023, 14:06

Okay, thank you for updating.

Tessa
8 Apr, 2023, 14:06

[SOLVED] How to setup offline-online sync and use it in flutter?

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more