feat :
1 - search location and conditions 2 - parse list in isolate
This commit is contained in:
@@ -57,3 +57,5 @@ export 'utils/map_utils.dart';
|
||||
export 'utils/network/network.dart';
|
||||
export 'utils/route_utils.dart';
|
||||
export 'utils/separator_input_formatter.dart';
|
||||
|
||||
export 'utils/utils.dart';
|
||||
|
||||
@@ -37,6 +37,7 @@ class DioRemote implements IHttpClient {
|
||||
ProgressCallback? onReceiveProgress,
|
||||
T Function(Map<String, dynamic> json)? fromJson,
|
||||
T Function(List<dynamic> json)? fromJsonList,
|
||||
Future<T> Function(List<dynamic> json)? fromJsonListAsync,
|
||||
}) async {
|
||||
final response = await dio.get(
|
||||
path,
|
||||
@@ -45,6 +46,10 @@ class DioRemote implements IHttpClient {
|
||||
onReceiveProgress: onReceiveProgress,
|
||||
cancelToken: ApiHandler.globalCancelToken,
|
||||
);
|
||||
if (fromJsonListAsync != null && response.data is List) {
|
||||
response.data = await fromJsonListAsync(response.data);
|
||||
return DioResponse<T>(response);
|
||||
}
|
||||
if (fromJsonList != null && response.data is List) {
|
||||
response.data = fromJsonList(response.data);
|
||||
return DioResponse<T>(response);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
|
||||
import 'dart:typed_data';
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import 'i_form_data.dart';
|
||||
import 'i_http_response.dart';
|
||||
|
||||
@@ -8,12 +7,14 @@ abstract class IHttpClient {
|
||||
Future<void> init();
|
||||
|
||||
Future<IHttpResponse<T>> get<T>(
|
||||
String path, {
|
||||
Map<String, dynamic>? queryParameters,
|
||||
Map<String, String>? headers,
|
||||
ProgressCallback? onReceiveProgress,
|
||||
});
|
||||
|
||||
String path, {
|
||||
Map<String, dynamic>? queryParameters,
|
||||
Map<String, String>? headers,
|
||||
ProgressCallback? onReceiveProgress,
|
||||
T Function(Map<String, dynamic> json)? fromJson,
|
||||
T Function(List<dynamic> json)? fromJsonList,
|
||||
Future<T> Function(List<dynamic> json)? fromJsonListAsync,
|
||||
});
|
||||
|
||||
Future<IHttpResponse<T>> post<T>(
|
||||
String path, {
|
||||
@@ -40,10 +41,7 @@ abstract class IHttpClient {
|
||||
Map<String, String>? headers,
|
||||
});
|
||||
|
||||
Future<IHttpResponse<T>> download<T>(
|
||||
String url, {
|
||||
ProgressCallback? onReceiveProgress,
|
||||
});
|
||||
Future<IHttpResponse<T>> download<T>(String url, {ProgressCallback? onReceiveProgress});
|
||||
|
||||
Future<IHttpResponse<T>> upload<T>(
|
||||
String path, {
|
||||
|
||||
16
packages/core/lib/utils/parser.dart
Normal file
16
packages/core/lib/utils/parser.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
List<T> _parserList<T>(Map<String, dynamic> args) {
|
||||
final list = args['list'] as List<dynamic>;
|
||||
final T Function(Map<String, dynamic>) fromJson =
|
||||
args['fromJson'] as T Function(Map<String, dynamic>);
|
||||
|
||||
return list.map<T>((e) => fromJson(e as Map<String, dynamic>)).toList();
|
||||
}
|
||||
|
||||
Future<List<T>> parseListInIsolate<T>(
|
||||
List<dynamic> list,
|
||||
T Function(Map<String, dynamic>) fromJson,
|
||||
) async {
|
||||
return compute(_parserList<T>, {'list': list, 'fromJson': fromJson});
|
||||
}
|
||||
@@ -1,17 +1,12 @@
|
||||
export 'mixins/pagination_controller_mixin.dart';
|
||||
|
||||
export 'network/network.dart';
|
||||
|
||||
export 'apk_updater.dart';
|
||||
export 'extension/date_time_utils.dart';
|
||||
export 'extension/num_utils.dart';
|
||||
export 'extension/string_utils.dart';
|
||||
|
||||
export 'apk_updater.dart';
|
||||
export 'local/local_utils.dart';
|
||||
export 'logger_utils.dart';
|
||||
export 'map_utils.dart';
|
||||
export 'mixins/pagination_controller_mixin.dart';
|
||||
export 'network/network.dart';
|
||||
export 'parser.dart';
|
||||
export 'route_utils.dart';
|
||||
export 'separator_input_formatter.dart';
|
||||
|
||||
|
||||
export 'local/local_utils.dart';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user