removeMore method
Implementation
Future<void> removeMore(String componentName, int index) async {
deletingIndices.add(index);
notifyListeners();
try {
final requestAction = formDefinitions[componentName]?.requestAction;
if (requestAction == null || requestAction.endpoint == null) return;
// Check for deleteKey and skip API call if values are missing
if (requestAction.deleteKey != null) {
final shouldSkip = replacePayloadValues(
requestAction.deleteKey,
index,
values,
) ==
null;
if (shouldSkip) {
handleRemoveMore(componentName, index);
return;
}
}
// Replace variables in payload
final payload = replacePayloadValues(
requestAction.payload,
index,
values,
);
if (hasNullValue(payload)) {
handleRemoveMore(componentName, index);
return;
}
try {
final response = await httpClient!.delete(
requestAction.endpoint!,
data: payload,
);
if (response.statusCode == 200) {
handleRemoveMore(componentName, index);
}
} catch (e) {
debugPrint('removeMore error: $e');
}
} finally {
deletingIndices.remove(index);
notifyListeners();
}
}