Back

Best way to return html from cloud function in DART

  • 0
  • Functions
  • Cloud
Ankit Maniya
12 Mar, 2025, 20:51

Right now I am return text

TypeScript
return response.text(JoinTeamHtml.successResponse(code), 200,
            {'Content-Type': 'text/html; charset=utf-8'});

my common fun

TypeScript
// Success response HTML
  static String successResponse(String code) {
    return """
      <!DOCTYPE html>
      <html lang="en">
      <head>
          <meta charset="UTF-8">
          <meta name="viewport" content="width=device-width, initial-scale=1.0">
          <title>Join Team</title>
          <style>
            $commonStyles
          </style>
      </head>
      <body>
          <div class="container">
              <h1>Welcome to the Team</h1>
              <p>Enter the following code in the app to continue:</p>
              <div class="code-display">$code</div>
          </div>
      </body>
      </html>
    """;
  }

Does a Dart cloud function have any knowledge of an HTML file? I found an example (https://github.com/appwrite/templates/blob/main/dart/whatsapp_with_vonage/lib/main.dart), but it does not work, as mentioned by one of the Appwrite supporters.

When a Dart function is deployed, it is compiled, so I cannot access .html, .proto, or other such files from the cloud function.

TL;DR
Developers need to return HTML from a Dart cloud function. One common way to do this is by creating a function that returns the HTML structure as a string. Deployed Dart functions are compiled and cannot access separate HTML files.
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