getDefinition method

Future<Definition> getDefinition(
  1. String sourceText, {
  2. String from = autoLanguage,
  3. String to = autoLanguage,
})

Implementation

Future<Definition> getDefinition(
  String sourceText, {
  String from = autoLanguage,
  String to = autoLanguage,
}) async {
  final HttpResponseData httpResponseData = await _getData(
    sourceText,
    from,
    to: to,
    dataType: 'md',
  );

  final jsonData = httpResponseData.jsonData;
  final Map<String, List<String>> definitionsMap = <String, List<String>>{};
  try {
    final indexedData = jsonData[_map[RequestType.definition]];
    for (final i in indexedData) {
      final String title = i[0] as String;
      final List<String> definitions = [];
      final List inList = i[1] as List;
      for (final n in inList) {
        definitions.add(n[0] as String);
      }
      definitionsMap[title] = definitions;
    }
  } catch (e) {
    _throwBadDataException(
      RequestType.definition,
      httpResponseData,
      innerException: e,
    );
  }
  return Definition(
    definitionsMap,
    source: sourceText,
    sourceLanguage: _languageList[from],
    targetLanguage: _languageList[to],
  );
}