Skip to content

Commit 06d4c22

Browse files
committed
updates for null safety
1 parent 3c86a0b commit 06d4c22

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

templates/flutter/lib/client.dart.twig

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ part of {{ language.params.packageName }};
33
class Client {
44
String endPoint;
55
String type = 'unknown';
6-
Map<String, String> headers;
7-
Map<String, String> config;
6+
Map<String, String>? headers;
7+
late Map<String, String> config;
88
bool selfSigned;
99
bool initialized = false;
1010
Dio http;
11-
PersistCookieJar cookieJar;
11+
late PersistCookieJar cookieJar;
1212

13-
Client({this.endPoint = '{{spec.endpoint}}', this.selfSigned = false, Dio http}) : this.http = http ?? Dio() {
13+
Client({this.endPoint = '{{spec.endpoint}}', this.selfSigned = false, Dio? http}) : this.http = http ?? Dio() {
1414
// Platform is not supported in web so if web, set type to web automatically and skip Platform check
1515
if(kIsWeb) {
1616
type = 'web';
@@ -68,7 +68,7 @@ class Client {
6868
}
6969

7070
Client addHeader(String key, String value) {
71-
headers[key] = value;
71+
headers![key] = value;
7272

7373
return this;
7474
}
@@ -77,21 +77,21 @@ class Client {
7777
// if web skip cookie implementation and origin header as those are automatically handled by browsers
7878
if(!kIsWeb) {
7979
final Directory cookieDir = await _getCookiePath();
80-
cookieJar = new PersistCookieJar(dir:cookieDir.path);
80+
cookieJar = new PersistCookieJar(storage: FileStorage(cookieDir.path));
8181
this.http.interceptors.add(CookieManager(cookieJar));
8282
PackageInfo packageInfo = await PackageInfo.fromPlatform();
83-
addHeader('Origin', 'appwrite-$type://${packageInfo.packageName ?? packageInfo.appName}');
83+
addHeader('Origin', 'appwrite-$type://${packageInfo.packageName}');
8484
} else {
8585
// if web set httpClientAdapter as BrowserHttpClientAdapter with withCredentials true to make cookies work
8686
this.http.options.extra['withCredentials'] = true;
8787
}
8888

8989
this.http.options.baseUrl = this.endPoint;
90-
this.http.options.validateStatus = (status) => status < 400;
90+
this.http.options.validateStatus = (status) => status! < 400;
9191
initialized = true;
9292
}
9393

94-
Future<Response> call(HttpMethod method, {String path = '', Map<String, String> headers = const {}, Map<String, dynamic> params = const {}, ResponseType responseType}) 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,14 +106,15 @@ class Client {
106106

107107
// Origin is hardcoded for testing
108108
Options options = Options(
109-
headers: {...this.headers, ...headers},
109+
headers: {...this.headers!, ...headers},
110110
method: method.name(),
111-
responseType: responseType
111+
responseType: responseType,
112+
listFormat: ListFormat.multiCompatible
112113
);
113114

114115
try {
115116
if(headers['content-type'] == 'multipart/form-data') {
116-
return await http.request(path, data: FormData.fromMap(params), options: options);
117+
return await http.request(path, data: FormData.fromMap(params, ListFormat.multiCompatible), options: options);
117118
}
118119

119120
if (method == HttpMethod.get) {
@@ -130,16 +131,16 @@ class Client {
130131
throw {{spec.title | caseUcfirst}}Exception(e.message);
131132
}
132133
if(responseType == ResponseType.bytes) {
133-
if(e.response.headers['content-type'].contains('application/json')) {
134-
final res = json.decode(utf8.decode(e.response.data));
134+
if(e.response!.headers['content-type']!.contains('application/json')) {
135+
final res = json.decode(utf8.decode(e.response!.data));
135136
throw {{spec.title | caseUcfirst}}Exception(res['message'],res['code'], e.response);
136137
} else {
137138
throw {{spec.title | caseUcfirst}}Exception(e.message);
138139
}
139140
}
140-
throw {{spec.title | caseUcfirst}}Exception(e.response.data['message'],e.response.data['code'], e.response.data);
141+
throw {{spec.title | caseUcfirst}}Exception(e.response!.data['message'],e.response!.data['code'], e.response!.data);
141142
} catch(e) {
142-
throw {{spec.title | caseUcfirst}}Exception(e.message);
143+
throw {{spec.title | caseUcfirst}}Exception(e.toString());
143144
}
144145
}
145146
}

templates/flutter/lib/exception.dart.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
part of {{ language.params.packageName }};
22

33
class {{spec.title | caseUcfirst}}Exception implements Exception {
4-
final String message;
5-
final int code;
4+
final String? message;
5+
final int? code;
66
final dynamic response;
77

88
{{spec.title | caseUcfirst}}Exception([this.message = "", this.code, this.response]);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
part of {{ language.params.packageName }};
22

33
{% macro parameter(parameter) %}
4-
{% if parameter.name == 'orderType' %}{% if parameter.required %}@required {% endif %}{{ 'OrderType orderType = OrderType.asc' }}{% else %}
5-
{% if parameter.required %}@required {% endif %}{{ parameter.type | typeName }} {{ parameter.name | caseCamel }}{{ parameter | escapeDollarSign | paramDefault }}{% endif %}
4+
{% if parameter.name == 'orderType' %}{% if parameter.required %}required {% endif %}{{ 'OrderType orderType = OrderType.asc' }}{% else %}
5+
{% if parameter.required %}required {% endif %}{{ parameter.type | typeName }} {{ parameter.name | caseCamel }}{{ parameter | escapeDollarSign | paramDefault }}{% endif %}
66
{% endmacro %}
77
{% macro method_parameters(parameters) %}
88
{% if parameters.all|length > 0 %}{{ '{' }}{% for parameter in parameters.all %}{{ _self.parameter(parameter) }}{% if not loop.last %}, {% endif %}{% endfor %}{{ '}' }}{% endif %}

0 commit comments

Comments
 (0)