getSection method

Future<MBSection> getSection({
  1. required int sectionId,
  2. List<MBParameter> parameters = const [],
  3. bool includeElements = false,
})

Retrieve the sections with the specified id.

  • Parameters:
    • sectionId: The sectionId of the section.
    • parameters: An optional array of MBParameter, an empty array by default.
    • includeElements: If true of the elements in the sections of the blocks are included in the response, false by default.
  • Returns a Future that completes with the MBSection retrieved.

Implementation

Future<MBSection> getSection({
  required int sectionId,
  List<MBParameter> parameters = const [],
  bool includeElements = false,
}) async {
  Map<String, String> apiParameters = {};

  if (includeElements) {
    apiParameters['include'] = 'elements';
  }

  for (MBParameter parameter in parameters) {
    Map<String, String> representation = parameter.representation;
    if (representation.isNotEmpty) {
      apiParameters.addAll(representation);
    }
  }

  String apiName = 'api/sections/$sectionId';

  apiParameters.addAll(await defaultParameters());

  var uri = Uri.https(endpoint, apiName, apiParameters);
  var response = await http.get(uri, headers: await headers());
  Map<String, dynamic> body = MBManager.checkResponse(response.body);

  return MBSection.fromDictionary(body);
}