getBlock method

Future<MBBlock> getBlock({
  1. required int blockId,
  2. List<MBParameter> parameters = const [],
  3. bool includeSections = false,
  4. bool includeElements = false,
})

Retrieve the block of the project with the specified id.

  • Parameters:
    • blockId: The blockId of the block.
    • parameters: An optional array of MBParameter used to sort, an empty array by default.
    • includeSections: If true the sections of the block are included in the response, false by default.
    • includeElements: If true the elements in the sections of the blocks are included in the response, false by default.
  • Returns a Future that completes with a MBBlock which is the block retrieved.

Implementation

Future<MBBlock> getBlock({
  required int blockId,
  List<MBParameter> parameters = const [],
  bool includeSections = false,
  bool includeElements = false,
}) async {
  Map<String, String> apiParameters = {};

  if (includeSections) {
    apiParameters['include'] =
        includeElements ? 'sections.elements' : 'sections';
  }

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

  String apiName = 'api/blocks/$blockId';

  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);
  MBBlock block = MBBlock.fromDictionary(body);

  return block;
}