Skip to content

Commit 05e89e4

Browse files
authored
Merge pull request #110 from lohanidamodar/feat-flutter-sdk-private-storage-files
feat-flutter-dart-sdk-private-storage-files
2 parents 1058203 + fcac80f commit 05e89e4

File tree

6 files changed

+34
-33
lines changed

6 files changed

+34
-33
lines changed

templates/dart/docs/example.md.twig

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void main() { // Init SDK
1717
{% endfor %} ;
1818

1919
{% endif %}
20-
{% if method.type == 'location' %}String{% else %}Future{% endif %} result = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}
20+
Future result = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}
2121
{% if loop.first %}
2222

2323
{% endif %}
@@ -26,14 +26,10 @@ void main() { // Init SDK
2626
{% endif %}
2727
{% endfor %}{% if method.parameters.all|length > 0 %} {% endif %});
2828

29-
{% if method.type == 'location' %}
30-
print(result); // Resource URL string
31-
{% else %}
3229
result
3330
.then((response) {
3431
print(response);
3532
}).catchError((error) {
3633
print(error.response);
3734
});
38-
{% endif %}
3935
}

templates/dart/lib/client.dart.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Client {
6060
}
6161
}
6262

63-
Future<Response> call(HttpMethod method, {String path = '', Map<String, String> headers = const {}, Map<String, dynamic> params = const {}}) async {
63+
Future<Response> call(HttpMethod method, {String path = '', Map<String, String> headers = const {}, Map<String, dynamic> params = const {}, ResponseType responseType}) async {
6464
if(selfSigned) {
6565
// Allow self signed requests
6666
(http.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (HttpClient client) {
@@ -75,6 +75,7 @@ class Client {
7575
Options options = Options(
7676
headers: {...this.headers, ...headers},
7777
method: method.name(),
78+
responseType: responseType
7879
);
7980
try {
8081

templates/dart/lib/services/service.dart.twig

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class {{ service.name | caseUcfirst }} extends Service {
2222
{{ method.description|dartComment }}
2323
///
2424
{% endif %}
25-
{% if method.type == 'webAuth' %}Future{% elseif method.type == 'location' %}String{% else %}Future<Response>{% endif %} {{ method.name | caseCamel }}({{ _self.method_parameters(method.parameters) }}) {
25+
{% if method.type == 'webAuth' %}Future{% else %}Future<Response>{% endif %} {{ method.name | caseCamel }}({{ _self.method_parameters(method.parameters) }}) {
2626
final String path = '{{ method.path }}'{% for parameter in method.parameters.path %}.replaceAll(RegExp('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}'), {{ parameter.name | caseCamel }}){% endfor %};
2727

2828
final Map<String, dynamic> params = {
@@ -48,15 +48,7 @@ class {{ service.name | caseUcfirst }} extends Service {
4848
params[key] = params[key].toString();
4949
}});
5050

51-
Uri endpoint = Uri.parse(client.endPoint);
52-
Uri location = new Uri(scheme: endpoint.scheme,
53-
host: endpoint.host,
54-
port: endpoint.port,
55-
path: endpoint.path + path,
56-
queryParameters:params,
57-
);
58-
59-
return location.toString();
51+
return client.call(HttpMethod.{{ method.method | caseLower }}, path: path, params: params, responseType: ResponseType.bytes);
6052
{% else %}
6153
final Map<String, String> headers = {
6254
{% for key, header in method.headers %}

templates/flutter/docs/example.md.twig

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,31 @@ void main() { // Init SDK
1515
.set{{header}}('{{node[header]['x-appwrite']['demo']}}') // {{node[header].description}}
1616
{% endfor %}
1717
{% endfor %} ;
18+
{% endif %}
19+
{% if method.type == 'location' %}
20+
}
21+
22+
//displaying image
23+
FutureBuilder(
24+
future: {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}
25+
{% if loop.first %}
1826

1927
{% endif %}
20-
{% if method.type == 'location' %}String{% else %}Future{% endif %} result = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}
28+
{% if parameter.required %}
29+
{{ parameter.name | caseCamel }}: {{ parameter | paramExample }},
30+
{% endif %}
31+
{% endfor %}{% if method.parameters.all|length > 0 %} {% endif %}
32+
), //works for both public file and private file, for private files you need to be logged in
33+
builder: (context, snapshot) {
34+
return snapshot.hasData && snapshot.data != null
35+
? Image.memory(
36+
snapshot.data.data,
37+
)
38+
: CircularProgressIndicator();
39+
},
40+
);
41+
{% else %}
42+
Future result = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}
2143
{% if loop.first %}
2244

2345
{% endif %}
@@ -26,14 +48,11 @@ void main() { // Init SDK
2648
{% endif %}
2749
{% endfor %}{% if method.parameters.all|length > 0 %} {% endif %});
2850

29-
{% if method.type == 'location' %}
30-
print(result); // Resource URL string
31-
{% else %}
3251
result
3352
.then((response) {
3453
print(response);
3554
}).catchError((error) {
3655
print(error.response);
3756
});
38-
{% endif %}
39-
}
57+
}
58+
{% endif %}

templates/flutter/lib/client.dart.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class Client {
9191
}
9292
}
9393

94-
Future<Response> call(HttpMethod method, {String path = '', Map<String, String> headers = const {}, Map<String, dynamic> params = const {}}) async {
94+
Future<Response> call(HttpMethod method, {String path = '', Map<String, String> headers = const {}, Map<String, dynamic> params = const {}, ResponseType responseType}) async {
9595
if(selfSigned && !kIsWeb) {
9696
// Allow self signed requests
9797
(http.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (HttpClient client) {
@@ -106,6 +106,7 @@ class Client {
106106
Options options = Options(
107107
headers: {...this.headers, ...headers},
108108
method: method.name(),
109+
responseType: responseType
109110
);
110111

111112
try {

templates/flutter/lib/services/service.dart.twig

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class {{ service.name | caseUcfirst }} extends Service {
2222
{{ method.description|dartComment }}
2323
///
2424
{% endif %}
25-
{% if method.type == 'webAuth' %}Future{% elseif method.type == 'location' %}String{% else %}Future<Response>{% endif %} {{ method.name | caseCamel }}({{ _self.method_parameters(method.parameters) }}) {
25+
{% if method.type == 'webAuth' %}Future{% else %}Future<Response>{% endif %} {{ method.name | caseCamel }}({{ _self.method_parameters(method.parameters) }}) {
2626
final String path = '{{ method.path }}'{% for parameter in method.parameters.path %}.replaceAll(RegExp('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}'), {{ parameter.name | caseCamel }}){% endfor %};
2727

2828
final Map<String, dynamic> params = {
@@ -90,16 +90,8 @@ class {{ service.name | caseUcfirst }} extends Service {
9090
params.keys.forEach((key) {if (params[key] is int || params[key] is double) {
9191
params[key] = params[key].toString();
9292
}});
93-
94-
Uri endpoint = Uri.parse(client.endPoint);
95-
Uri location = new Uri(scheme: endpoint.scheme,
96-
host: endpoint.host,
97-
port: endpoint.port,
98-
path: endpoint.path + path,
99-
queryParameters:params,
100-
);
10193

102-
return location.toString();
94+
return client.call(HttpMethod.{{ method.method | caseLower }}, path: path, params: params, responseType: ResponseType.bytes);
10395
{% else %}
10496
final Map<String, String> headers = {
10597
{% for key, header in method.headers %}

0 commit comments

Comments
 (0)