
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 ?

how are you handling the documents in your app?

I didn't get it

what's returning empty?

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

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

please see my original message about optimistic updates

where and how are you using this create method?

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

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

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));
}
}

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.

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

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 await
ing the createDocument()

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

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

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

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

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

Here's some additional info: https://github.com/appwrite/appwrite/discussions/5326

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) 🙂

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?
Recommended threads
- Database error
My code: await databases.createDocument( process.env.APPWRITE_DATABASE, process.env.APPWRITE_COLLECTION_USER, data.userId, ...
- Server Error when using Apprwrite in .NE...
Hello can somebody help me.. I'm getting server error 500 when I try use queries in ListDocuments function but when I removed it or just query without filter it...
- Migration
I want to migrate the data available on Appwrite cloud, from one project to another project in cloud itself. How can this be done, is not possible ?
