Skip to content

Commit b127ade

Browse files
author
Shalmon Anandas
committed
Change String return to Map return
1 parent cd4d557 commit b127ade

File tree

6 files changed

+113
-116
lines changed

6 files changed

+113
-116
lines changed

example/lib/main.dart

Lines changed: 70 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class MyApp extends StatefulWidget {
1818

1919
class _MyAppState extends State<MyApp> {
2020
final _dohApiClientPlugin = DohApiClient();
21-
String _apiGetRequest = "";
22-
String _apiPostRequest = "";
23-
String _apiPutRequest = "";
24-
String _apiPatchRequest = "";
25-
String _apiDeleteRequest = "";
21+
Map<String, dynamic> _apiGetRequest = {};
22+
Map<String, dynamic> _apiPostRequest = {};
23+
Map<String, dynamic> _apiPutRequest = {};
24+
Map<String, dynamic> _apiPatchRequest = {};
25+
Map<String, dynamic> _apiDeleteRequest = {};
2626

2727
@override
2828
void initState() {
@@ -32,123 +32,120 @@ class _MyAppState extends State<MyApp> {
3232

3333
// Platform messages are asynchronous, so we initialize in an async method.
3434
Future<void> initPlatformState() async {
35-
String apiGetRequest;
36-
String apiPostRequest;
37-
String apiPutRequest;
38-
String apiPatchRequest;
39-
String apiDeleteRequest;
35+
Map<String, dynamic>? apiGetRequest;
36+
Map<String, dynamic>? apiPostRequest;
37+
Map<String, dynamic>? apiPutRequest;
38+
Map<String, dynamic>? apiPatchRequest;
39+
Map<String, dynamic>? apiDeleteRequest;
4040
// Platform messages may fail, so we use a try/catch PlatformException.
4141
// We also handle the message potentially returning null.
4242

4343
try {
4444
apiGetRequest = await _dohApiClientPlugin.get(
45-
url: "https://jsonplaceholder.typicode.com/posts/1",
46-
headers: {
47-
"User-Agent":
48-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
49-
},
50-
dohProvider: DohProvider.CloudFlare) ??
51-
"Method Channel Called for GET Request but Failure Received";
45+
url: "https://jsonplaceholder.typicode.com/posts/1",
46+
headers: {
47+
"User-Agent":
48+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
49+
},
50+
dohProvider: DohProvider.CloudFlare);
5251
setState(() {
53-
_apiGetRequest = apiGetRequest;
52+
_apiGetRequest = apiGetRequest ?? {};
5453
});
5554
} catch (e) {
56-
apiGetRequest = "Method Channel Failed to call for GET Request";
55+
apiGetRequest = {
56+
"ERROR": "Method Channel Failed to call for GET Request"
57+
};
5758
setState(() {
58-
_apiGetRequest = apiGetRequest;
59+
_apiGetRequest = apiGetRequest ?? {};
5960
});
6061
}
6162

6263
try {
6364
apiPostRequest = await _dohApiClientPlugin.post(
64-
url: "https://jsonplaceholder.typicode.com/posts",
65-
headers: {
66-
"User-Agent":
67-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36",
68-
'Content-type': 'application/json; charset=UTF-8'
69-
},
70-
body: jsonEncode({
71-
"title": 'foo',
72-
"body": 'bar',
73-
"userId": 1,
74-
}),
75-
dohProvider: DohProvider.CloudFlare) ??
76-
"Method Channel Called for POST Request but Failure Received";
65+
url: "https://jsonplaceholder.typicode.com/posts",
66+
headers: {
67+
"User-Agent":
68+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36",
69+
'Content-type': 'application/json; charset=UTF-8'
70+
},
71+
body: jsonEncode({
72+
"title": 'foo',
73+
"body": 'bar',
74+
"userId": 1,
75+
}),
76+
dohProvider: DohProvider.CloudFlare);
7777
setState(() {
78-
_apiPostRequest = apiPostRequest;
78+
_apiPostRequest = apiPostRequest ?? {};
7979
});
8080
} catch (e) {
8181
apiPostRequest = "Method Channel Failed to call for POST Request";
8282
setState(() {
83-
_apiPostRequest = apiPostRequest;
83+
_apiPostRequest = apiPostRequest ?? {};
8484
});
8585
}
8686

8787
try {
8888
apiPutRequest = await _dohApiClientPlugin.put(
89-
url: "https://jsonplaceholder.typicode.com/posts/1",
90-
headers: {
91-
"User-Agent":
92-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36",
93-
'Content-type': 'application/json; charset=UTF-8'
94-
},
95-
body: jsonEncode({
96-
"id": 1,
97-
"title": 'foo',
98-
"body": 'bar',
99-
"userId": 1,
100-
}),
101-
dohProvider: DohProvider.CloudFlare) ??
102-
"Method Channel Called for PUT Request but Failure Received";
89+
url: "https://jsonplaceholder.typicode.com/posts/1",
90+
headers: {
91+
"User-Agent":
92+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36",
93+
'Content-type': 'application/json; charset=UTF-8'
94+
},
95+
body: jsonEncode({
96+
"id": 1,
97+
"title": 'foo',
98+
"body": 'bar',
99+
"userId": 1,
100+
}),
101+
dohProvider: DohProvider.CloudFlare);
103102
setState(() {
104-
_apiPutRequest = apiPutRequest;
103+
_apiPutRequest = apiPutRequest ?? {};
105104
});
106105
} catch (e) {
107106
apiPutRequest = "Method Channel Failed to call for PUT Request";
108107
setState(() {
109-
_apiPutRequest = apiPutRequest;
108+
_apiPutRequest = apiPutRequest ?? {};
110109
});
111110
}
112111

113112
try {
114113
apiPatchRequest = await _dohApiClientPlugin.patch(
115-
url: "https://jsonplaceholder.typicode.com/posts/1",
116-
headers: {
117-
"User-Agent":
118-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36",
119-
'Content-type': 'application/json; charset=UTF-8'
120-
},
121-
body: jsonEncode({
122-
"title": 'foo',
123-
}),
124-
dohProvider: DohProvider.CloudFlare) ??
125-
"Method Channel Called for PATCH Request but Failure Received";
114+
url: "https://jsonplaceholder.typicode.com/posts/1",
115+
headers: {
116+
"User-Agent":
117+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36",
118+
'Content-type': 'application/json; charset=UTF-8'
119+
},
120+
body: jsonEncode({
121+
"title": 'foo',
122+
}),
123+
dohProvider: DohProvider.CloudFlare);
126124
setState(() {
127-
_apiPatchRequest = apiPatchRequest;
125+
_apiPatchRequest = apiPatchRequest ?? {};
128126
});
129127
} catch (e) {
130128
apiPatchRequest = "Method Channel Failed to call for PATCH Request";
131129
setState(() {
132-
_apiPatchRequest = apiPatchRequest;
130+
_apiPatchRequest = apiPatchRequest ?? {};
133131
});
134132
}
135133

136134
try {
137135
apiDeleteRequest = await _dohApiClientPlugin.delete(
138-
url: "https://jsonplaceholder.typicode.com/posts/1",
139-
headers: {
140-
"User-Agent":
141-
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
142-
},
143-
dohProvider: DohProvider.CloudFlare) ??
144-
"Method Channel Called for DELETE Request but Failure Received";
136+
url: "https://jsonplaceholder.typicode.com/posts/1",
137+
headers: {
138+
"User-Agent":
139+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
140+
},
141+
dohProvider: DohProvider.CloudFlare);
145142
setState(() {
146-
_apiDeleteRequest = apiDeleteRequest;
143+
_apiDeleteRequest = apiDeleteRequest ?? {};
147144
});
148145
} catch (e) {
149146
apiDeleteRequest = "Method Channel Failed to call for DELETE Request";
150147
setState(() {
151-
_apiDeleteRequest = apiDeleteRequest;
148+
_apiDeleteRequest = apiDeleteRequest ?? {};
152149
});
153150
}
154151
// If the widget was removed from the tree while the asynchronous platform

example/pubspec.lock

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ packages:
3737
dependency: transitive
3838
description:
3939
name: collection
40-
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
40+
sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf
4141
url: "https://pub.dev"
4242
source: hosted
43-
version: "1.18.0"
43+
version: "1.19.0"
4444
cupertino_icons:
4545
dependency: "direct main"
4646
description:
@@ -55,7 +55,7 @@ packages:
5555
path: ".."
5656
relative: true
5757
source: path
58-
version: "1.0.0"
58+
version: "1.0.3"
5959
fake_async:
6060
dependency: transitive
6161
description:
@@ -109,18 +109,18 @@ packages:
109109
dependency: transitive
110110
description:
111111
name: leak_tracker
112-
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
112+
sha256: "7bb2830ebd849694d1ec25bf1f44582d6ac531a57a365a803a6034ff751d2d06"
113113
url: "https://pub.dev"
114114
source: hosted
115-
version: "10.0.5"
115+
version: "10.0.7"
116116
leak_tracker_flutter_testing:
117117
dependency: transitive
118118
description:
119119
name: leak_tracker_flutter_testing
120-
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
120+
sha256: "9491a714cca3667b60b5c420da8217e6de0d1ba7a5ec322fab01758f6998f379"
121121
url: "https://pub.dev"
122122
source: hosted
123-
version: "3.0.5"
123+
version: "3.0.8"
124124
leak_tracker_testing:
125125
dependency: transitive
126126
description:
@@ -197,7 +197,7 @@ packages:
197197
dependency: transitive
198198
description: flutter
199199
source: sdk
200-
version: "0.0.99"
200+
version: "0.0.0"
201201
source_span:
202202
dependency: transitive
203203
description:
@@ -210,10 +210,10 @@ packages:
210210
dependency: transitive
211211
description:
212212
name: stack_trace
213-
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
213+
sha256: "9f47fd3630d76be3ab26f0ee06d213679aa425996925ff3feffdec504931c377"
214214
url: "https://pub.dev"
215215
source: hosted
216-
version: "1.11.1"
216+
version: "1.12.0"
217217
stream_channel:
218218
dependency: transitive
219219
description:
@@ -226,10 +226,10 @@ packages:
226226
dependency: transitive
227227
description:
228228
name: string_scanner
229-
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
229+
sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3"
230230
url: "https://pub.dev"
231231
source: hosted
232-
version: "1.2.0"
232+
version: "1.3.0"
233233
sync_http:
234234
dependency: transitive
235235
description:
@@ -250,10 +250,10 @@ packages:
250250
dependency: transitive
251251
description:
252252
name: test_api
253-
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
253+
sha256: "664d3a9a64782fcdeb83ce9c6b39e78fd2971d4e37827b9b06c3aa1edc5e760c"
254254
url: "https://pub.dev"
255255
source: hosted
256-
version: "0.7.2"
256+
version: "0.7.3"
257257
vector_math:
258258
dependency: transitive
259259
description:
@@ -266,18 +266,18 @@ packages:
266266
dependency: transitive
267267
description:
268268
name: vm_service
269-
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
269+
sha256: f6be3ed8bd01289b34d679c2b62226f63c0e69f9fd2e50a6b3c1c729a961041b
270270
url: "https://pub.dev"
271271
source: hosted
272-
version: "14.2.5"
272+
version: "14.3.0"
273273
webdriver:
274274
dependency: transitive
275275
description:
276276
name: webdriver
277-
sha256: "003d7da9519e1e5f329422b36c4dcdf18d7d2978d1ba099ea4e45ba490ed845e"
277+
sha256: "3d773670966f02a646319410766d3b5e1037efb7f07cc68f844d5e06cd4d61c8"
278278
url: "https://pub.dev"
279279
source: hosted
280-
version: "3.0.3"
280+
version: "3.0.4"
281281
sdks:
282282
dart: ">=3.5.3 <4.0.0"
283283
flutter: ">=3.18.0-18.0.pre.54"

lib/doh_api_client.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import 'doh_api_client_platform_interface.dart';
22

33
class DohApiClient {
4-
Future<String?> get(
4+
Future<Map<String, dynamic>?> get(
55
{required String url,
66
Map<String, dynamic>? headers,
77
DohProvider? dohProvider}) {
88
return DohApiClientPlatform.instance
99
.get(url, headers ?? {}, dohProvider ?? DohProvider.CloudFlare);
1010
}
1111

12-
Future<String?> post(
12+
Future<Map<String, dynamic>?> post(
1313
{required String url,
1414
Map<String, dynamic>? headers,
1515
String? body,
@@ -18,7 +18,7 @@ class DohApiClient {
1818
url, headers ?? {}, body ?? "", dohProvider ?? DohProvider.CloudFlare);
1919
}
2020

21-
Future<String?> put(
21+
Future<Map<String, dynamic>?> put(
2222
{required String url,
2323
Map<String, dynamic>? headers,
2424
String? body,
@@ -27,7 +27,7 @@ class DohApiClient {
2727
url, headers ?? {}, body ?? "", dohProvider ?? DohProvider.CloudFlare);
2828
}
2929

30-
Future<String?> patch(
30+
Future<Map<String, dynamic>?> patch(
3131
{required String url,
3232
Map<String, dynamic>? headers,
3333
String? body,
@@ -36,7 +36,7 @@ class DohApiClient {
3636
url, headers ?? {}, body ?? "", dohProvider ?? DohProvider.CloudFlare);
3737
}
3838

39-
Future<String?> delete(
39+
Future<Map<String, dynamic>?> delete(
4040
{required String url,
4141
Map<String, dynamic>? headers,
4242
DohProvider? dohProvider}) {

0 commit comments

Comments
 (0)