@@ -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,14 +73,15 @@ 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(),
78- responseType: responseType
78+ responseType: responseType,
79+ listFormat: ListFormat.multiCompatible,
7980 );
8081 try {
8182
8283 if(headers['content-type'] == 'multipart/form-data') {
83- return await http.request(path, data: FormData.fromMap(params), options: options);
84+ return await http.request(path, data: FormData.fromMap(params,ListFormat.multiCompatible ), options: options);
8485 }
8586
8687 if (method == HttpMethod.get) {
@@ -97,16 +98,16 @@ class Client {
9798 throw {{spec .title | caseUcfirst }}Exception(e.message);
9899 }
99100 if(responseType == ResponseType.bytes) {
100- if(e.response.headers['content-type'].contains('application/json')) {
101- final res = json.decode(utf8.decode(e.response.data));
102- throw {{spec .title | caseUcfirst }}Exception(res['message'],res['code'], e.response );
101+ if(e.response! .headers['content-type']? .contains('application/json') ?? false ) {
102+ final res = json.decode(utf8.decode(e.response! .data));
103+ throw {{spec .title | caseUcfirst }}Exception(res['message'],res['code'], res );
103104 } else {
104105 throw {{spec .title | caseUcfirst }}Exception(e.message);
105106 }
106107 }
107- throw {{spec .title | caseUcfirst }}Exception(e.response.data['message'],e.response.data['code'], e.response.data);
108+ throw {{spec .title | caseUcfirst }}Exception(e.response? .data['message'],e.response? .data['code'], e.response? .data);
108109 } catch(e) {
109- throw {{spec .title | caseUcfirst }}Exception(e.message );
110+ throw {{spec .title | caseUcfirst }}Exception(e.toString() );
110111 }
111112 }
112113}
0 commit comments