@@ -3,13 +3,13 @@ part of {{ language.params.packageName }};
33class 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}
0 commit comments