{% if method.type == 'upload' %}
import 'dart:io';
{% endif %}
import 'package:{{ language.params.packageName }}/{{ language.params.packageName }}.dart';

Client client = Client()
    {%~ if method.auth|length > 0 %}
    .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint
    {%~ for node in method.auth %}
    {%~ for key,header in node|keys %}
    .set{{header}}('{{node[header]['x-appwrite']['demo'] | raw }}'){% if loop.last %};{% endif%} // {{node[header].description}}
    {%~ endfor %}
    {%~ endfor %}
    {%~ endif %}

{{ service.name | caseUcfirst }} {{ service.name | caseCamel }} = {{service.name | caseUcfirst}}(client);

{% if method.type == 'location' %}
// Downloading file
UInt8List bytes = await {{ service.name | caseCamel }}.{{ method.name | caseCamel }}(
    {%~ for parameter in method.parameters.all %}
    {{ parameter.name | caseCamel | overrideIdentifier}}: {% if parameter.enumValues | length > 0%}{{parameter.enumName}}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}{% else %}{{ parameter | paramExample | replace({'<field-name>': (parameter.name | caseCamel) }) | raw }}{% endif %},{% if not parameter.required %} // optional{% endif %}

    {%~ endfor %}{% if method.parameters.all | length > 0 %}{% endif %})

final file = File('path_to_file/filename.ext');
file.writeAsBytesSync(bytes);

// Displaying image preview
FutureBuilder(
    future: {{ service.name | caseCamel }}.{{ method.name | caseCamel }}(
    {%~ for parameter in method.parameters.all %}
    {{ parameter.name | caseCamel | overrideIdentifier}}:{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}{% else %}{{ parameter | paramExample | replace({'<field-name>': (parameter.name | caseCamel) }) | raw }} {% endif %},{% if not parameter.required %} // optional{% endif %}

    {%~ endfor %}
), // Works for both public file and private file, for private files you need to be logged in
    builder: (context, snapshot) {
      return snapshot.hasData && snapshot.data != null
          ? Image.memory(snapshot.data)
          : CircularProgressIndicator();
    }
);
{% else %}
{% if method.method != 'delete' and method.type != 'webAuth' %}{% if method.type == 'location' %}UInt8List{% else %}{{ method.responseModel | caseUcfirst | overrideIdentifier }}{% endif %} result = {% endif %}await {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% if method.parameters.all | length == 0 %});{% endif %}

    {%~ for parameter in method.parameters.all %}
    {{ parameter.name | caseCamel | overrideIdentifier}}: {% if parameter.enumValues | length > 0%}{{parameter.enumName}}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}{% else %}{{ parameter | paramExample | replace({'<field-name>': (parameter.name | caseCamel) }) | raw }}{% endif %},{% if not parameter.required %} // optional{% endif %}

    {%~ endfor %}
{% if method.parameters.all | length > 0 %});
{% endif %}
{% endif %}