Skip to content

Commit 3907acb

Browse files
committed
dart sdk null safety migration
1 parent d963762 commit 3907acb

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

templates/dart/lib/client.dart.twig

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ 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;
1111

12-
Client({this.endPoint = '{{spec.endpoint}}', this.selfSigned = false, Dio http}) : this.http = http ?? Dio() {
12+
Client({this.endPoint = '{{spec.endpoint}}', this.selfSigned = false, Dio? http}) : this.http = http ?? Dio() {
1313

1414
this.headers = {
1515
'content-type': 'application/json',
@@ -48,19 +48,19 @@ class Client {
4848
}
4949

5050
Client addHeader(String key, String value) {
51-
headers[key] = value;
51+
headers![key] = value;
5252

5353
return this;
5454
}
5555

5656
Future init() async {
5757
if(!initialized) {
5858
this.http.options.baseUrl = this.endPoint;
59-
this.http.options.validateStatus = (status) => status < 400;
59+
this.http.options.validateStatus = (status) => status! < 400;
6060
}
6161
}
6262

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

7474
// Origin is hardcoded for testing
7575
Options options = Options(
76-
headers: {...this.headers, ...headers},
76+
headers: {...this.headers!, ...headers},
7777
method: method.name(),
7878
responseType: responseType
7979
);
@@ -96,9 +96,9 @@ class Client {
9696
if(e.response == null) {
9797
throw {{spec.title | caseUcfirst}}Exception(e.message);
9898
}
99-
throw {{spec.title | caseUcfirst}}Exception(e.response.data['message'],e.response.data['code'], e.response.data);
99+
throw {{spec.title | caseUcfirst}}Exception(e.response!.data['message'],e.response!.data['code'], e.response!.data);
100100
} catch(e) {
101-
throw {{spec.title | caseUcfirst}}Exception(e.message);
101+
throw {{spec.title | caseUcfirst}}Exception(e.toString());
102102
}
103103
}
104104
}

templates/dart/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/dart/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 %}

templates/dart/pubspec.yaml.twig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ repository: https://github.com/{{sdk.gitUserName}}/{{sdk.gitRepoName}}
66
issue_tracker: https://github.com/appwrite/sdk-generator/issues
77
documentation: {{ spec.contactURL }}
88
environment:
9-
sdk: '>=2.6.0 <3.0.0'
9+
sdk: '>=2.12.0 <3.0.0'
1010
dependencies:
11-
dio: ^3.0.10
12-
meta: ^1.1.8
11+
dio: ^4.0.0-beta4
12+
meta: ^1.3.0
1313
1414
dev_dependencies:
15-
test:
15+
test: ^1.16.5

0 commit comments

Comments
 (0)