getSectionWithSlug method
Future<MBSection>
getSectionWithSlug({
- required String slug,
- List<
MBParameter> parameters = const [], - bool includeElements = false,
Retrieve the sections with the specified slug.
- Parameters:
slug
: Theslug
of the section.parameters
: An optional array of MBParameter, an empty array by default.includeElements
: Iftrue
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';
}
for (MBParameter parameter in parameters) {
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);
}