Skip to content

Commit 9f8a745

Browse files
committed
fixes: form data & curl
1 parent 09c572c commit 9f8a745

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

lib/codegen/others/curl.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class cURLCodeGen {
5858
} else if (requestModel.hasFormData) {
5959
for (var formData in requestModel.formDataList) {
6060
var templateFormData = jj.Template(kTemplateFormData);
61-
if (formData.name.isNotEmpty && formData.value.isNotEmpty) {
61+
if (formData.name.isNotEmpty) {
6262
result += templateFormData.render({
6363
"name": formData.name,
6464
"value":

lib/models/request_model.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ class RequestModel {
8080
bool get hasFormData =>
8181
kMethodsWithBody.contains(method) &&
8282
hasFormDataContentType &&
83-
(requestFormDataList ?? <FormDataModel>[]).isNotEmpty;
83+
formDataMapList.isNotEmpty;
8484
List<FormDataModel> get formDataList =>
8585
requestFormDataList ?? <FormDataModel>[];
86-
List<Map<String, dynamic>> get formDataMapList =>
86+
List<Map<String, String>> get formDataMapList =>
8787
rowsToFormDataMapList(requestFormDataList) ?? [];
8888
bool get hasFileInFormData => formDataList
8989
.map((e) => e.type == FormDataType.file)
@@ -137,6 +137,7 @@ class RequestModel {
137137
var params = requestParams ?? this.requestParams;
138138
var enabledHeaders = isHeaderEnabledList ?? this.isHeaderEnabledList;
139139
var enabledParams = isParamEnabledList ?? this.isParamEnabledList;
140+
var formDataList = requestFormDataList ?? this.requestFormDataList;
140141
return RequestModel(
141142
id: id ?? this.id,
142143
method: method ?? this.method,
@@ -151,7 +152,7 @@ class RequestModel {
151152
requestBodyContentType:
152153
requestBodyContentType ?? this.requestBodyContentType,
153154
requestBody: requestBody ?? this.requestBody,
154-
requestFormDataList: requestFormDataList ?? this.requestFormDataList,
155+
requestFormDataList: formDataList != null ? [...formDataList] : null,
155156
responseStatus: responseStatus ?? this.responseStatus,
156157
message: message ?? this.message,
157158
responseModel: responseModel ?? this.responseModel,

lib/utils/convert_utils.dart

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:typed_data';
22
import 'dart:convert';
3+
import 'package:collection/collection.dart';
34
import '../models/models.dart';
45
import '../consts.dart';
56
import 'package:http/http.dart' as http;
@@ -90,18 +91,22 @@ List<NameValueModel>? mapToRows(Map<String, String>? kvMap) {
9091
return finalRows;
9192
}
9293

93-
List<Map<String, dynamic>>? rowsToFormDataMapList(
94+
List<Map<String, String>>? rowsToFormDataMapList(
9495
List<FormDataModel>? kvRows,
9596
) {
9697
if (kvRows == null) {
9798
return null;
9899
}
99-
List<Map<String, dynamic>> finalMap = kvRows
100-
.map((FormDataModel formData) => {
101-
"name": formData.name,
102-
"value": formData.value,
103-
"type": formData.type.name,
104-
})
100+
List<Map<String, String>> finalMap = kvRows
101+
.map((FormDataModel formData) =>
102+
(formData.name.trim().isEmpty && formData.value.trim().isEmpty)
103+
? null
104+
: {
105+
"name": formData.name,
106+
"value": formData.value,
107+
"type": formData.type.name,
108+
})
109+
.whereNotNull()
105110
.toList();
106111
return finalMap;
107112
}

lib/utils/file_utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ String getShortPath(String path) {
5050

5151
String getFilenameFromPath(String path) {
5252
var f = p.split(path);
53-
return f.last;
53+
return f.lastOrNull ?? "";
5454
}
5555

5656
String getTempFileName() {

0 commit comments

Comments
 (0)