getParametersMap method

Map<String, String> getParametersMap()

Returns the corresponding API URI parameter map, including additionalParameters.

Implementation

Map<String, String> getParametersMap() {
  final Map<String, String> result = {};

  result['tagtype'] = tagType.offTag;
  if (_isRootConfiguration) {
    result['include_root_entries'] = '1';
  } else {
    if (tags.isNotEmpty) {
      result['tags'] = tags.join(',');
    }
  }
  result['include_children'] = includeChildren ? '1' : '0';

  if (languages.isNotEmpty) {
    result.putIfAbsent('lc',
        () => languages.map<String>((language) => language.offTag).join(','));
  }

  result.putIfAbsent('cc',
      () => OpenFoodAPIConfiguration.computeCountryCode(country, null)!);

  if (fields.isNotEmpty) {
    final Iterable<String> fieldsStrings = convertFieldsToStrings(fields);
    result.putIfAbsent('fields', () => fieldsStrings.join(','));
  }

  for (final parameter in additionalParameters) {
    result.putIfAbsent(parameter.getName(), () => parameter.getValue());
  }
  return result;
}