getSectionWithSlug method Null safety

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

Retrieve the sections with the specified slug.

  • Parameters:
    • slug: The slug 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> getSectionWithSlug({
  required String slug,
  List<MBParameter> parameters = const [],
  bool includeElements = false,
}) async {
  Map<String, String> apiParameters = {};

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

  parameters.forEach((parameter) {
    Map<String, String> representation = parameter.representation;
    apiParameters.addAll(representation);
  });

  String apiName = 'api/sections/' + slug;

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