Back

[CLOSED] Unable to get the right syntax after days of research.

  • 0
  • Tools
  • Flutter
  • Self Hosted
  • Functions
dammy
29 Oct, 2023, 08:02

Currently, I cannot use the data sent by the Client to the Dart function (data is needed for decision making) and also I cannot format the response from the Dart function to the Client code as a Dart Map Object.

The goal in the Flutter code is to send a request to Dart function and get a response from the Dart function.

Flutter Code

TypeScript
    functionId: 'validator',
    body: jsonEncode({"Request": "Sign Up Phone Prefix"}),
    xasync: false,
    path: '/',
    method: 'POST',
    headers: {'X-Custom-Header': '123'});
       phoneValidatorExecutor.then((response) {
    // for decoding response from Dart function
         final decoded = response.toMap();
         print(decoded);
    }).catchError((error) {
        print(error);
 });```

--------------------------------------
The goal in the dart function is to receive client input and decide what to send back to client, so I deliberately removed the if statement to know if Client input was received and I decided to send it (data) back to Client.

**Dart Function Code**
```Future<dynamic> main(final context) async {
    final requestFromClient = context.req.query['Request'];
    return context.res.json({
    // normalUsersPriceDetailsSuperSet was declared in a lib file as Map and has data
    "Status": normalUsersPriceDetailsSuperSet["Network Prefixes"],
    "UserInput": requestFromClient['Request'],
  });
}```

**I've been on all these for more than 8 days 😭**
TL;DR
The user is unable to get the correct syntax after days of research. They are trying to send a request from Flutter code to a Dart function and receive a response. However, they are facing two issues: not being able to use the data sent by the client in the Dart function, and not being able to format the response as a Dart Map Object. Solution: - In the Flutter code, they can use `response.toMap()` to decode the response from the Dart function and print it. - In the Dart function, they need to make sure they are accessing the client input correctly and sending it back to the client. TL;
dammy
29 Oct, 2023, 08:06

Confirmation of code syntax, If they are correct.

dammy
29 Oct, 2023, 08:25

Unable to get the right syntax after days of research.

Drake
29 Oct, 2023, 15:02

You already have threads open. Do not create duplicate ones

Drake
29 Oct, 2023, 15:03

[CLOSED] Unable to get the right syntax after days of research.

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