getTools method

Future<List<Tool>> getTools({
  1. required String courseId,
})

Returns the Course tools for a specific Course (i.e. the left menu). It works in the same way as the regular menu, i.e. if the User logged in is an instructor it returns 2 additional groups of tools (inactive and management).

Implementation

Future<List<Tool>> getTools({required String courseId}) async {
  List<Tool> tools = [];
  Tool tool;
  final response = await _client.post(
    Uri.https(
      'eclass.$instituteId.gr',
      '/modules/mobile/mtools.php',
    ),
    body: {
      'token': _token ?? '',
      'course': courseId,
    },
  );
  if (response.statusCode != 200 ||
      response.body == 'EXPIRED' ||
      response.body == 'FAILED') {
    throw Exception("Failed to get course's tools.");
  }
  final decodedResponse = XmlDocument.parse(response.body);
  final nodes = decodedResponse.findAllElements('tool');
  for (final node in nodes) {
    tool = Tool(
      name: node.attributes[0].value,
      link: node.attributes[1].value,
      redirect: node.attributes[2].value,
      type: node.attributes[3].value,
      active: node.attributes[4].value,
    );
    tools.add(tool);
  }
  return tools;
}