Showing
6 changed files
with
37 additions
and
36 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; | 
| @@ -156,16 +157,15 @@ class GetHttpClient { | @@ -156,16 +157,15 @@ class GetHttpClient { | ||
| 156 | 157 | ||
| 157 | final uri = _createUri(url, query); | 158 | final uri = _createUri(url, query); | 
| 158 | return Request<T>( | 159 | return Request<T>( | 
| 159 | - method: method, | ||
| 160 | - url: uri, | ||
| 161 | - headers: headers, | ||
| 162 | - bodyBytes: bodyStream, | ||
| 163 | - contentLength: bodyBytes?.length ?? 0, | ||
| 164 | - followRedirects: followRedirects, | ||
| 165 | - maxRedirects: maxRedirects, | ||
| 166 | - decoder: decoder, | ||
| 167 | - responseInterceptor: responseInterceptor | ||
| 168 | - ); | 160 | + method: method, | 
| 161 | + url: uri, | ||
| 162 | + headers: headers, | ||
| 163 | + bodyBytes: bodyStream, | ||
| 164 | + contentLength: bodyBytes?.length ?? 0, | ||
| 165 | + followRedirects: followRedirects, | ||
| 166 | + maxRedirects: maxRedirects, | ||
| 167 | + decoder: decoder, | ||
| 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, | ||
| 588 | - String? contentType, | ||
| 589 | - Map<String, dynamic>? query, | ||
| 590 | - Decoder<T>? decoder, | ||
| 591 | - ResponseInterceptor<T>? responseInterceptor | ||
| 592 | - }) async { | 589 | + Future<Response<T>> delete<T>(String url, | 
| 590 | + {Map<String, String>? headers, | ||
| 591 | + String? contentType, | ||
| 592 | + Map<String, dynamic>? query, | ||
| 593 | + Decoder<T>? decoder, | ||
| 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; | 
| @@ -58,10 +57,11 @@ class HttpRequestImpl extends HttpRequestBase { | @@ -58,10 +57,11 @@ class HttpRequestImpl extends HttpRequestBase { | ||
| 58 | }); | 57 | }); | 
| 59 | 58 | ||
| 60 | final bodyBytes = (response); | 59 | final bodyBytes = (response); | 
| 61 | - | ||
| 62 | - final interceptionResponse = await request.responseInterceptor?.call(request, T, response); | ||
| 63 | - if(interceptionResponse != null) return interceptionResponse; | ||
| 64 | - | 60 | + | 
| 61 | + final interceptionResponse = | ||
| 62 | + await request.responseInterceptor?.call(request, T, response); | ||
| 63 | + if (interceptionResponse != null) return interceptionResponse; | ||
| 64 | + | ||
| 65 | final stringBody = await bodyBytesToString(bodyBytes, headers); | 65 | final stringBody = await bodyBytesToString(bodyBytes, headers); | 
| 66 | 66 | ||
| 67 | final body = bodyDecoded<T>( | 67 | final body = bodyDecoded<T>( | 
| 1 | import 'package:flutter/widgets.dart'; | 1 | import 'package:flutter/widgets.dart'; | 
| 2 | 2 | ||
| 3 | -class Engine{ | ||
| 4 | - static WidgetsBinding get instance { | 3 | +class Engine { | 
| 4 | + static WidgetsBinding get instance { | ||
| 5 | return WidgetsFlutterBinding.ensureInitialized(); | 5 | return WidgetsFlutterBinding.ensureInitialized(); | 
| 6 | } | 6 | } | 
| 7 | -} | ||
| 7 | +} | 
| @@ -66,12 +66,11 @@ class GetModalBottomSheetRoute<T> extends PopupRoute<T> { | @@ -66,12 +66,11 @@ 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 | } | 
| 74 | - | 73 | + | 
| 75 | @override | 74 | @override | 
| 76 | AnimationController createAnimationController() { | 75 | AnimationController createAnimationController() { | 
| 77 | assert(_animationController == null); | 76 | assert(_animationController == null); | 
| @@ -71,7 +71,7 @@ mixin StateMixin<T> on ListNotifier { | @@ -71,7 +71,7 @@ mixin StateMixin<T> on ListNotifier { | ||
| 71 | } | 71 | } | 
| 72 | } | 72 | } | 
| 73 | 73 | ||
| 74 | - void futurize(Future<T> Function() body, | 74 | + void futurize(Future<T> Function() body, | 
| 75 | {T? initialData, String? errorMessage, bool useEmpty = true}) { | 75 | {T? initialData, String? errorMessage, bool useEmpty = true}) { | 
| 76 | final compute = body; | 76 | final compute = body; | 
| 77 | _value ??= initialData; | 77 | _value ??= initialData; | 
- 
Please register or login to post a comment