submitForm method
Submits formData
against link
headers
will be added in addition to ApptiveGridClient.defaultHeaders
if this returns a http.Response
with a http.Response.statusCode
>= 400 it means that the Item was saved in options.cache
throws Response
if the request fails
Implementation
Future<http.Response?> submitForm(
ApptiveLink link,
FormData formData, {
bool saveToPendingItems = true,
Map<String, String> headers = const {},
}) async {
final eventWithResponse = await submitFormWithProgress(
link,
formData,
saveToPendingItems: false, // Saving is handled below
headers: headers,
)
.firstWhere(
(element) =>
element is SubmitCompleteProgressEvent ||
element is ErrorProgressEvent,
)
.catchError((error) {
throw error;
});
if (eventWithResponse is SubmitCompleteProgressEvent) {
return eventWithResponse.response;
} else if (eventWithResponse is ErrorProgressEvent) {
final error = eventWithResponse.error;
return _handleActionError(
error,
actionItem: ActionItem(link: link, data: formData),
saveToPendingItems: saveToPendingItems,
);
} else {
return null;
}
}