Back

[SOLVED] How to create and deploy a dart function?

  • 0
  • Functions
Guille
26 May, 2023, 13:17

did you update sdk: >=2.19.3 <3.0.0 to sdk: >=2.17.7 <3.0.0?

TL;DR
Summary: User had a curl error while creating and deploying a Dart function but was able to solve it. They received guidance on using Appwrite CLI and were provided with a sample code for their `main.dart` file. They also received a suggestion to update their Dart sdk version. Solution: User solved their initial curl error. They were guided to check the Appwrite CLI documentation and provided with a sample code for their `main.dart` file. Additionally, they were advised to update their Dart sdk version from `sdk: >=2.19.3 <3.0.0` to `sdk: >=2.17.7 <
siddesh31
26 May, 2023, 13:17

yes

Guille
26 May, 2023, 13:18

you main.dart should have something like this:

TypeScript
import 'dart:math';
import 'dart:async';

Future <void> start(final req, final res) async {
  final payload =
    !req.payload?.isEmpty ? req.payload :
    'No payload provided. Add custom data when executing function.';

  final secretKey =
    req.variables['SECRET_KEY'] ??
    'SECRET_KEY variable not found. You can set it in Function settings.';

  final randomNumber = new Random().nextDouble();

  final trigger = req.variables['APPWRITE_FUNCTION_TRIGGER'];

  res.json({
    'message': 'Hello from Appwrite!',
    'payload': payload,
    'secretKey': secretKey,
    'randomNumber': randomNumber,
    'trigger': trigger,
  });
}
Guille
26 May, 2023, 13:19

Or a simpler version

TypeScript
import 'dart:async';

Future <void> start(final req, final res) async {
  res.json({
    'message': 'Hello from Appwrite!'
  });
}
Guille
26 May, 2023, 13:20

Have you considerate to use Appwrite CLI?

siddesh31
26 May, 2023, 13:21

its working now

siddesh31
26 May, 2023, 13:21

<:appwritepeepo:902865250427215882>

siddesh31
26 May, 2023, 13:21

thankyou @Guille

siddesh31
26 May, 2023, 13:21

i have completed the setup

siddesh31
26 May, 2023, 13:22

is that more easy?

Guille
26 May, 2023, 13:23

Yes it's, it handles all automatically, you just run a command and it's deployed in Appwrite

Guille
26 May, 2023, 13:23

Check this documentation: https://appwrite.io/docs/command-line

siddesh31
26 May, 2023, 13:37
siddesh31
26 May, 2023, 13:37

wat probably might be wrong here

siddesh31
26 May, 2023, 13:37

@Guille

siddesh31
26 May, 2023, 13:37

i am getting a curl error

Guille
26 May, 2023, 14:12

are you using appwrite cloud?

siddesh31
26 May, 2023, 14:15

yes

siddesh31
26 May, 2023, 14:15

i fixed this

siddesh31
26 May, 2023, 14:15

but

siddesh31
26 May, 2023, 14:16
siddesh31
26 May, 2023, 14:16

for this code i am getting same curl error

Drake
26 May, 2023, 15:49

How to create and deploy a dart function?

Drake
26 May, 2023, 15:49

I'm going to mark this as solved since the part about creating and deploying the function is solved.

Drake
26 May, 2023, 15:50

[SOLVED] How to create and deploy a dart function?

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