@@ -7,11 +7,11 @@ import 'package:http/http.dart' as http;
77
88class HttpClient extends http.BaseClient {
99 final http.Client _client;
10- final Stack stack;
11- final Map <String , String > stackHeaders;
10+ final Stack ? stack;
11+ final Map <String , String >? stackHeaders;
1212
13- factory HttpClient (Map <String , String > headers,
14- {http.Client client, Stack stack}) {
13+ factory HttpClient (Map <String , String >? headers,
14+ {http.Client ? client, Stack ? stack}) {
1515 final stackClient = client ?? http.Client ();
1616 return HttpClient ._internal (stackClient, headers, stack);
1717 }
@@ -26,13 +26,13 @@ class HttpClient extends http.BaseClient {
2626 return _client.send (request);
2727 }
2828
29- Future <T > sendRequest <T , K >(Uri uri) async {
30- stackHeaders[CONTENT_TYPE ] = CONTENT_TYPE_VALUE ;
31- stackHeaders[X_USER_AGENT ] = X_USER_AGENT_VALUE ;
29+ Future <T ? > sendRequest <T , K >(Uri uri) async {
30+ stackHeaders! [CONTENT_TYPE ] = CONTENT_TYPE_VALUE ;
31+ stackHeaders! [X_USER_AGENT ] = X_USER_AGENT_VALUE ;
3232 final response = await http
33- .get (uri, headers: stackHeaders)
33+ .get (uri, headers: stackHeaders as Map < String , String > )
3434 .timeout (const Duration (seconds: TIMEOUT ));
35- Object bodyJson;
35+ Object ? bodyJson;
3636 try {
3737 bodyJson = jsonDecode (response.body);
3838 } on FormatException {
@@ -44,42 +44,42 @@ class HttpClient extends http.BaseClient {
4444 rethrow ;
4545 }
4646 if (response.statusCode == 200 ) {
47- final Map bodyJson = json.decode (utf8.decode (response.bodyBytes));
48- if (T == EntryModel && bodyJson.containsKey ('entry' )) {
47+ final Map ? bodyJson = json.decode (utf8.decode (response.bodyBytes));
48+ if (T == EntryModel && bodyJson! .containsKey ('entry' )) {
4949 return fromJson <T , K >(bodyJson['entry' ]);
50- } else if (K == EntryModel && bodyJson.containsKey ('entries' )) {
50+ } else if (K == EntryModel && bodyJson! .containsKey ('entries' )) {
5151 return fromJson <T , K >(bodyJson['entries' ]);
52- } else if (T == AssetModel && bodyJson.containsKey ('asset' )) {
52+ } else if (T == AssetModel && bodyJson! .containsKey ('asset' )) {
5353 return fromJson <T , K >(bodyJson['asset' ]);
54- } else if (K == AssetModel && bodyJson.containsKey ('assets' )) {
54+ } else if (K == AssetModel && bodyJson! .containsKey ('assets' )) {
5555 return fromJson <T , K >(bodyJson['assets' ]);
56- } else if (T == SyncResult && bodyJson.containsKey ('items' )) {
56+ } else if (T == SyncResult && bodyJson! .containsKey ('items' )) {
5757 return fromJson <T , K >(bodyJson);
5858 } else {
59- if (bodyJson.containsKey ('entries' )) {
60- var previewResponse = stack.livePreview[ ' entries' ] ;
59+ if (bodyJson! .containsKey ('entries' )) {
60+ var previewResponse = stack! .livePreview? . entries;
6161 if (previewResponse != null ) {
62- return fromJson <T , K >(mergeLivePreview (bodyJson, previewResponse));
62+ return fromJson <T , K >(mergeLivePreview (bodyJson, Map . fromEntries ( previewResponse) ));
6363 }
6464 }
6565 return fromJson <T , K >(bodyJson);
6666 }
6767 } else {
68- return bodyJson;
68+ return fromJson < T , K >( bodyJson) as FutureOr < T ?> ;
6969 }
7070 }
7171
72- mergeLivePreview (Map bodyJson, Map previewResponse) {}
72+ mergeLivePreview (Map ? bodyJson, Map previewResponse) {}
7373
7474 /// Generic objects as well as List of generic objects
7575 /// (from a JSON list response).
7676 /// First, you need to have a function that checks the type of the
7777 /// generic object and returns the result of the corresponding fromJson call
7878 /// code taken from:
7979 /// https://stackoverflow.com/questions/56271651/how-to-pass-a-generic-type-as-a-parameter-to-a-future-in-flutter
80- static T fromJson <T , K >(dynamic json) {
80+ static T ? fromJson <T , K >(dynamic json) {
8181 if (json is Iterable ) {
82- return _fromJsonList <K >(json) as T ;
82+ return _fromJsonList <K >(json as List < dynamic > ) as T ;
8383 } else if (T == AssetModel ) {
8484 return AssetModel .fromJson (json) as T ;
8585 } else if (T == EntryModel ) {
@@ -91,14 +91,14 @@ class HttpClient extends http.BaseClient {
9191 }
9292 }
9393
94- static List <K > _fromJsonList <K >(List jsonList) {
94+ static List <K ?> ? _fromJsonList <K >(List ? jsonList) {
9595 if (jsonList == null ) {
9696 return null ;
9797 }
9898
99- final output = < K > [];
99+ final output = < K ? > [];
100100 // ignore: prefer_final_in_for_each
101- for (Map <String , dynamic > json in jsonList) {
101+ for (Map <String , dynamic > json in jsonList as Iterable < Map < String , dynamic >> ) {
102102 output.add (fromJson (json));
103103 }
104104 return output;
0 commit comments