Create http_utils.dart

This commit is contained in:
Ashita Prasad
2024-12-06 04:50:40 +05:30
parent 682581c9bf
commit f63663392c
3 changed files with 47 additions and 5 deletions

View File

@ -2,8 +2,10 @@ import 'package:collection/collection.dart';
import '../consts.dart'; import '../consts.dart';
import '../models/models.dart'; import '../models/models.dart';
Map<String, String>? rowsToMap(List<NameValueModel>? kvRows, Map<String, String>? rowsToMap(
{bool isHeader = false}) { List<NameValueModel>? kvRows, {
bool isHeader = false,
}) {
if (kvRows == null) { if (kvRows == null) {
return null; return null;
} }
@ -20,7 +22,9 @@ Map<String, String>? rowsToMap(List<NameValueModel>? kvRows,
return finalMap; return finalMap;
} }
List<NameValueModel>? mapToRows(Map<String, String>? kvMap) { List<NameValueModel>? mapToRows(
Map<String, String>? kvMap,
) {
if (kvMap == null) { if (kvMap == null) {
return null; return null;
} }
@ -51,7 +55,9 @@ List<Map<String, String>>? rowsToFormDataMapList(
return finalMap; return finalMap;
} }
List<FormDataModel>? mapListToFormDataModelRows(List<Map>? kvMap) { List<FormDataModel>? mapListToFormDataModelRows(
List<Map>? kvMap,
) {
if (kvMap == null) { if (kvMap == null) {
return null; return null;
} }
@ -73,7 +79,9 @@ FormDataType getFormDataType(String? type) {
} }
List<NameValueModel>? getEnabledRows( List<NameValueModel>? getEnabledRows(
List<NameValueModel>? rows, List<bool>? isRowEnabledList) { List<NameValueModel>? rows,
List<bool>? isRowEnabledList,
) {
if (rows == null || isRowEnabledList == null) { if (rows == null || isRowEnabledList == null) {
return rows; return rows;
} }

View File

@ -0,0 +1,33 @@
import 'package:http_parser/http_parser.dart';
import '../consts.dart';
import '../extensions/extensions.dart';
ContentType? getContentTypeFromHeadersMap(
Map<String, String>? kvMap,
) {
if (kvMap != null && kvMap.hasKeyContentType()) {
var val = kvMap.getValueContentType();
if (val != null) {
return ContentType.text;
}
}
return null;
}
MediaType? getMediaTypeFromHeaders(Map? headers) {
var contentType = headers?.getValueContentType();
MediaType? mediaType = getMediaTypeFromContentType(contentType);
return mediaType;
}
MediaType? getMediaTypeFromContentType(String? contentType) {
if (contentType != null) {
try {
MediaType mediaType = MediaType.parse(contentType);
return mediaType;
} catch (e) {
return null;
}
}
return null;
}

View File

@ -1,3 +1,4 @@
export 'http_utils.dart';
export 'http_request_utils.dart'; export 'http_request_utils.dart';
export 'http_response_utils.dart'; export 'http_response_utils.dart';
export 'string_utils.dart'; export 'string_utils.dart';