editSection method
Future<void>
editSection(
- int sectionId,
- List<
MBUploadableElement> elements, { - MBAdminPushSettings? pushSettings,
- MBAdminVisibilitySettings? visibilitySettings,
Edits a section, this API will change only the elements passed, elements that are not passed will remain untouched.
- Parameters:
sectionId
: The id of the section that needs to be edited.elements
: The elements of the section that will be created.visibilitySettings
: This property will tell MBurger the visibility settings for the section.pushSettings
: This property will tell MBurger if it should send a push notification when the section is published.
- Returns a Future that completes when the section is edited correctly.
Implementation
Future<void> editSection(
int sectionId,
List<MBUploadableElement> elements, {
MBAdminPushSettings? pushSettings,
MBAdminVisibilitySettings? visibilitySettings,
}) async {
String apiName = 'api/sections/$sectionId/update';
var uri = Uri.https(manager.endpoint, apiName);
var request = http.MultipartRequest('POST', uri);
for (MBUploadableElement element in elements) {
List<MBMultipartForm>? forms = element.toForm();
await _addMultipartFormsToRequest(request, forms);
}
if (pushSettings != null) {
List<MBMultipartForm>? pushForms = pushSettings.toForm();
await _addMultipartFormsToRequest(request, pushForms);
}
if (visibilitySettings != null) {
List<MBMultipartForm>? visibilityForms = visibilitySettings.toForm();
await _addMultipartFormsToRequest(request, visibilityForms);
}
request.headers.addAll(await manager.headers());
http.StreamedResponse response = await request.send();
final responseString = await response.stream.bytesToString();
MBManager.checkResponse(responseString, checkBody: false);
}