Back

Function execution and response using Dart SDK

  • 0
  • Self Hosted
  • Flutter
  • Functions
punti_z
17 Mar, 2024, 20:24

Looking for a sample app or code snippet of how I can create a Appwrite Function execution passing some data, await and receive response synchronously using flutter SDK.

I am able to create an execution marking Async false but I am unable to receive a response. I am assuming I doing something wrong so I would really appreciate some help.

TL;DR
Developers seeking assistance with using Dart SDK for executing functions and receiving responses synchronously in a Flutter app. They are struggling to await responses client-side and have issues even after marking the function call as async false. The solution would be to await the function call and work with the responseBody as mentioned in the provided code snippet. Additionally, they can ping the Get Execution endpoint for updates on the execution status.
Ernest
17 Mar, 2024, 20:38

How are you sending the response from the function? Also, did you read the starter code (esp comments)? It contains pretty much everything you need to know about functions

punti_z
17 Mar, 2024, 20:50

I did and even tried writing it but the issue I run into is how to await a response client side. From what I can tell marking the call Async False doesn't help.

Docs mention " The returned object will return you the current execution status. You can ping the Get Execution endpoint to get updates on the current execution status."

If my function returns addition of 2 numbers, I want the response to be the sum and not the current status even if the function takes 2 secs to complete execution.

Ernest
17 Mar, 2024, 20:52

I suppose you're calling the function from a flutter app?

punti_z
17 Mar, 2024, 20:52

Yes

Ernest
17 Mar, 2024, 20:53

If so, just await the function call and do whatever you want with the response which is responseBody

Ernest
17 Mar, 2024, 20:56

Example:

TypeScript
final execution = await functions.createExecution(
      functionId: myFunctionId,
      body: data,
      xasync: false,
      path: '/',
      method: 'POST',
      // headers: {'X-Custom-Header': '123'},
    );

final response = execution.responseBody;
punti_z
17 Mar, 2024, 20:57

I tried this sample code as well but it dint work. Have you actually used this ? Maybe I missed something and can try again.

Ernest
17 Mar, 2024, 20:58

Yes I have a project I'm working on that uses functions

punti_z
17 Mar, 2024, 20:59

Will try again and report back. Thanks

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