addSectionToBlock method

Future<void> addSectionToBlock(
  1. int blockId,
  2. List<MBUploadableElement> elements, {
  3. MBAdminPushSettings? pushSettings,
  4. MBAdminVisibilitySettings? visibilitySettings,
})

Adds a section to a block.

  • Parameters:
    • blockId: The id of the block to add a section.
    • 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 created correctly.

Implementation

Future<void> addSectionToBlock(
  int blockId,
  List<MBUploadableElement> elements, {
  MBAdminPushSettings? pushSettings,
  MBAdminVisibilitySettings? visibilitySettings,
}) async {
  String apiName = 'api/blocks/$blockId/sections';

  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);
}