getBlock method
Future<MBBlock>
getBlock({
- required int blockId,
- List<
MBParameter> parameters = const [], - bool includeSections = false,
- bool includeElements = false,
Retrieve the block of the project with the specified id.
- Parameters:
blockId
: TheblockId
of the block.parameters
: An optional array of MBParameter used to sort, an empty array by default.includeSections
: Iftrue
the sections of the block are included in the response,false
by default.includeElements
: Iftrue
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;
}