getProductTagWithSubKeys static method

Future<Map<String, ProductTag>> getProductTagWithSubKeys({
  1. required String barcode,
  2. required String key,
  3. QueryType? queryType,
})

Returns all the ProductTags for this product, with their subkeys.

The key of the returned map is the key.

Implementation

static Future<Map<String, ProductTag>> getProductTagWithSubKeys({
  required final String barcode,
  required final String key,
  final QueryType? queryType,
}) async {
  final Map<String, String> parameters = <String, String>{};
  /* TODO
  if (owner != null) {
    parameters['owner'] = owner;
  }
   */
  final Response response = await HttpHelper().doGetRequest(
    UriHelper.getFolksonomyUri(
      path: 'product/$barcode/$key*', // look at the star!
      queryParameters: parameters,
      queryType: queryType,
    ),
    queryType: queryType,
  );
  _checkResponse(response);
  final Map<String, ProductTag> result = <String, ProductTag>{};
  if (response.body == 'null') {
    // not found
    return result;
  }
  final List<dynamic> json = jsonDecode(response.body) as List<dynamic>;
  for (var element in json) {
    final ProductTag productTag = ProductTag.fromJson(element);
    result[productTag.key] = productTag;
  }
  return result;
}