Rank 5: Hypervisor
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 ?
Votes
0
Replies
24
Participants
Unknown
Messages
25
Rank 5: Hypervisor
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 ?
Admin
how are you handling the documents in your app?
Rank 5: Hypervisor
I didn't get it
Admin
what's returning empty?
Admin
no we're not using a separte isolate, but this is a good suggestion
Rank 5: Hypervisor
so, I removed the wrapper, and how I am handling is I expected document to be retuned else it will stuck at loading indicator
Admin
please see my original message about optimistic updates
Admin
where and how are you using this create method?
Rank 5: Hypervisor
I guess I didn't get it this part optimistic updates could you explain little bit more
Admin
Write operations will not resolve until online again. So, if you're offline and you have:
final document = await _database.createDocument();execution will be stuck at this line until the device goes online again
Rank 5: Hypervisor
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)); } }
Rank 5: Hypervisor
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.
Rank 5: Hypervisor
But, I wonder when I try to read the document it it getting returned, then while create why not return the document ?
Admin
again, see:
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()
Admin
because the resolution happens when the server receives the request and provides the response
Rank 5: Hypervisor
right, I am asking while reading in offline we are receving the document right, so why not return that it-self during the creation
Admin
you can only resolve a future once and it's reserved for when the server responds
Admin
in case there's an error from the server, you can respond accordingly
Rank 5: Hypervisor
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
Admin
Here's some additional info: https://github.com/appwrite/appwrite/discussions/5326
Rank 5: Hypervisor
thank you, this makes sense. I saw some Read.me doc. supper excited to deep dive into it
@Vedsaga I'm just checking if everything is good so we can close this topic (marking it as solved) 🙂
Rank 5: Hypervisor
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.
Okay, thank you for updating.
[SOLVED] How to setup offline-online sync and use it in flutter?