mirror of
https://github.com/foss42/apidash.git
synced 2025-12-11 07:41:14 +08:00
Update http_request_utils.dart
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import 'package:better_networking/better_networking.dart';
|
import 'package:better_networking/better_networking.dart';
|
||||||
import 'package:json5/json5.dart' as json5;
|
import 'package:json5/json5.dart' as json5;
|
||||||
|
|
||||||
@@ -22,9 +21,7 @@ Map<String, String>? rowsToMap(
|
|||||||
return finalMap;
|
return finalMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<NameValueModel>? mapToRows(
|
List<NameValueModel>? mapToRows(Map<String, String>? kvMap) {
|
||||||
Map<String, String>? kvMap,
|
|
||||||
) {
|
|
||||||
if (kvMap == null) {
|
if (kvMap == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -35,47 +32,45 @@ List<NameValueModel>? mapToRows(
|
|||||||
return finalRows;
|
return finalRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Map<String, String>>? rowsToFormDataMapList(
|
List<Map<String, String>>? rowsToFormDataMapList(List<FormDataModel>? kvRows) {
|
||||||
List<FormDataModel>? kvRows,
|
|
||||||
) {
|
|
||||||
if (kvRows == null) {
|
if (kvRows == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
List<Map<String, String>> finalMap = kvRows
|
List<Map<String, String>> finalMap = kvRows
|
||||||
.map((FormDataModel formData) =>
|
.map(
|
||||||
(formData.name.trim().isEmpty && formData.value.trim().isEmpty)
|
(FormDataModel formData) =>
|
||||||
? null
|
(formData.name.trim().isEmpty && formData.value.trim().isEmpty)
|
||||||
: {
|
? null
|
||||||
"name": formData.name,
|
: {
|
||||||
"value": formData.value,
|
"name": formData.name,
|
||||||
"type": formData.type.name,
|
"value": formData.value,
|
||||||
})
|
"type": formData.type.name,
|
||||||
|
},
|
||||||
|
)
|
||||||
.nonNulls
|
.nonNulls
|
||||||
.toList();
|
.toList();
|
||||||
return finalMap;
|
return finalMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<FormDataModel>? mapListToFormDataModelRows(
|
List<FormDataModel>? mapListToFormDataModelRows(List<Map>? kvMap) {
|
||||||
List<Map>? kvMap,
|
|
||||||
) {
|
|
||||||
if (kvMap == null) {
|
if (kvMap == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
List<FormDataModel> finalRows = kvMap.map(
|
List<FormDataModel> finalRows = kvMap.map((formData) {
|
||||||
(formData) {
|
return FormDataModel(
|
||||||
return FormDataModel(
|
name: formData["name"],
|
||||||
name: formData["name"],
|
value: formData["value"],
|
||||||
value: formData["value"],
|
type: getFormDataType(formData["type"]),
|
||||||
type: getFormDataType(formData["type"]),
|
);
|
||||||
);
|
}).toList();
|
||||||
},
|
|
||||||
).toList();
|
|
||||||
return finalRows;
|
return finalRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
FormDataType getFormDataType(String? type) {
|
FormDataType getFormDataType(String? type) {
|
||||||
return FormDataType.values.firstWhere((element) => element.name == type,
|
return FormDataType.values.firstWhere(
|
||||||
orElse: () => FormDataType.text);
|
(element) => element.name == type,
|
||||||
|
orElse: () => FormDataType.text,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<NameValueModel>? getEnabledRows(
|
List<NameValueModel>? getEnabledRows(
|
||||||
@@ -85,8 +80,9 @@ List<NameValueModel>? getEnabledRows(
|
|||||||
if (rows == null || isRowEnabledList == null) {
|
if (rows == null || isRowEnabledList == null) {
|
||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
List<NameValueModel> finalRows =
|
List<NameValueModel> finalRows = rows
|
||||||
rows.where((element) => isRowEnabledList[rows.indexOf(element)]).toList();
|
.where((element) => isRowEnabledList[rows.indexOf(element)])
|
||||||
|
.toList();
|
||||||
return finalRows == [] ? null : finalRows;
|
return finalRows == [] ? null : finalRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,4 +105,4 @@ String? removeJsonComments(String? json) {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user