Showing
6 changed files
with
20 additions
and
19 deletions
@@ -16,7 +16,8 @@ typedef Decoder<T> = T Function(dynamic data); | @@ -16,7 +16,8 @@ typedef Decoder<T> = T Function(dynamic data); | ||
16 | 16 | ||
17 | typedef Progress = Function(double percent); | 17 | typedef Progress = Function(double percent); |
18 | 18 | ||
19 | -typedef ResponseInterceptor<T> = Future<Response<T>?> Function(Request<T> request, Type targetType, HttpClientResponse response); | 19 | +typedef ResponseInterceptor<T> = Future<Response<T>?> Function( |
20 | + Request<T> request, Type targetType, HttpClientResponse response); | ||
20 | 21 | ||
21 | class GetHttpClient { | 22 | class GetHttpClient { |
22 | String userAgent; | 23 | String userAgent; |
@@ -164,8 +165,7 @@ class GetHttpClient { | @@ -164,8 +165,7 @@ class GetHttpClient { | ||
164 | followRedirects: followRedirects, | 165 | followRedirects: followRedirects, |
165 | maxRedirects: maxRedirects, | 166 | maxRedirects: maxRedirects, |
166 | decoder: decoder, | 167 | decoder: decoder, |
167 | - responseInterceptor: responseInterceptor | ||
168 | - ); | 168 | + responseInterceptor: responseInterceptor); |
169 | } | 169 | } |
170 | 170 | ||
171 | void _setContentLenght(Map<String, String> headers, int contentLength) { | 171 | void _setContentLenght(Map<String, String> headers, int contentLength) { |
@@ -291,11 +291,14 @@ class GetHttpClient { | @@ -291,11 +291,14 @@ class GetHttpClient { | ||
291 | )); | 291 | )); |
292 | } | 292 | } |
293 | 293 | ||
294 | - ResponseInterceptor<T>? _responseInterceptor<T>(ResponseInterceptor<T>? actual) { | ||
295 | - if(actual != null) return actual; | 294 | + ResponseInterceptor<T>? _responseInterceptor<T>( |
295 | + ResponseInterceptor<T>? actual) { | ||
296 | + if (actual != null) return actual; | ||
296 | final defaultInterceptor = defaultResponseInterceptor; | 297 | final defaultInterceptor = defaultResponseInterceptor; |
297 | return defaultInterceptor != null | 298 | return defaultInterceptor != null |
298 | - ? (request, targetType, response) async => await defaultInterceptor(request, targetType, response) as Response<T>? | 299 | + ? (request, targetType, response) async => |
300 | + await defaultInterceptor(request, targetType, response) | ||
301 | + as Response<T>? | ||
299 | : null; | 302 | : null; |
300 | } | 303 | } |
301 | 304 | ||
@@ -340,6 +343,7 @@ class GetHttpClient { | @@ -340,6 +343,7 @@ class GetHttpClient { | ||
340 | responseInterceptor: _responseInterceptor(responseInterceptor), | 343 | responseInterceptor: _responseInterceptor(responseInterceptor), |
341 | ); | 344 | ); |
342 | } | 345 | } |
346 | + | ||
343 | Future<Response<T>> send<T>(Request<T> request) async { | 347 | Future<Response<T>> send<T>(Request<T> request) async { |
344 | try { | 348 | try { |
345 | var response = await _performRequest<T>(() => Future.value(request)); | 349 | var response = await _performRequest<T>(() => Future.value(request)); |
@@ -582,17 +586,16 @@ class GetHttpClient { | @@ -582,17 +586,16 @@ class GetHttpClient { | ||
582 | // return completer.future; | 586 | // return completer.future; |
583 | // } | 587 | // } |
584 | 588 | ||
585 | - Future<Response<T>> delete<T>( | ||
586 | - String url, { | ||
587 | - Map<String, String>? headers, | 589 | + Future<Response<T>> delete<T>(String url, |
590 | + {Map<String, String>? headers, | ||
588 | String? contentType, | 591 | String? contentType, |
589 | Map<String, dynamic>? query, | 592 | Map<String, dynamic>? query, |
590 | Decoder<T>? decoder, | 593 | Decoder<T>? decoder, |
591 | - ResponseInterceptor<T>? responseInterceptor | ||
592 | - }) async { | 594 | + ResponseInterceptor<T>? responseInterceptor}) async { |
593 | try { | 595 | try { |
594 | var response = await _performRequest<T>( | 596 | var response = await _performRequest<T>( |
595 | - () async => _delete<T>(url, contentType, query, decoder, responseInterceptor), | 597 | + () async => |
598 | + _delete<T>(url, contentType, query, decoder, responseInterceptor), | ||
596 | headers: headers, | 599 | headers: headers, |
597 | ); | 600 | ); |
598 | return response; | 601 | return response; |
@@ -8,7 +8,6 @@ import '../../response/response.dart'; | @@ -8,7 +8,6 @@ import '../../response/response.dart'; | ||
8 | import '../interface/request_base.dart'; | 8 | import '../interface/request_base.dart'; |
9 | import '../utils/body_decoder.dart'; | 9 | import '../utils/body_decoder.dart'; |
10 | 10 | ||
11 | - | ||
12 | /// A `dart:io` implementation of `HttpRequestBase`. | 11 | /// A `dart:io` implementation of `HttpRequestBase`. |
13 | class HttpRequestImpl extends HttpRequestBase { | 12 | class HttpRequestImpl extends HttpRequestBase { |
14 | io.HttpClient? _httpClient; | 13 | io.HttpClient? _httpClient; |
@@ -59,8 +58,9 @@ class HttpRequestImpl extends HttpRequestBase { | @@ -59,8 +58,9 @@ class HttpRequestImpl extends HttpRequestBase { | ||
59 | 58 | ||
60 | final bodyBytes = (response); | 59 | final bodyBytes = (response); |
61 | 60 | ||
62 | - final interceptionResponse = await request.responseInterceptor?.call(request, T, response); | ||
63 | - if(interceptionResponse != null) return interceptionResponse; | 61 | + final interceptionResponse = |
62 | + await request.responseInterceptor?.call(request, T, response); | ||
63 | + if (interceptionResponse != null) return interceptionResponse; | ||
64 | 64 | ||
65 | final stringBody = await bodyBytesToString(bodyBytes, headers); | 65 | final stringBody = await bodyBytesToString(bodyBytes, headers); |
66 | 66 |
1 | import 'package:flutter/widgets.dart'; | 1 | import 'package:flutter/widgets.dart'; |
2 | 2 | ||
3 | -class Engine{ | 3 | +class Engine { |
4 | static WidgetsBinding get instance { | 4 | static WidgetsBinding get instance { |
5 | return WidgetsFlutterBinding.ensureInitialized(); | 5 | return WidgetsFlutterBinding.ensureInitialized(); |
6 | } | 6 | } |
@@ -66,8 +66,7 @@ class GetModalBottomSheetRoute<T> extends PopupRoute<T> { | @@ -66,8 +66,7 @@ class GetModalBottomSheetRoute<T> extends PopupRoute<T> { | ||
66 | @override | 66 | @override |
67 | Animation<double> createAnimation() { | 67 | Animation<double> createAnimation() { |
68 | if (curve != null) { | 68 | if (curve != null) { |
69 | - return CurvedAnimation( | ||
70 | - curve: curve!, parent: _animationController!.view); | 69 | + return CurvedAnimation(curve: curve!, parent: _animationController!.view); |
71 | } | 70 | } |
72 | return _animationController!.view; | 71 | return _animationController!.view; |
73 | } | 72 | } |
-
Please register or login to post a comment