getIngredientSpellingCorrection static method

  1. @Deprecated('Unstable version, do not use and wait for the next version')
Future<SpellingCorrection?> getIngredientSpellingCorrection({
  1. String? ingredientName,
  2. Product? product,
  3. User? user,
  4. QueryType? queryType,
})

Implementation

@Deprecated('Unstable version, do not use and wait for the next version')
static Future<SpellingCorrection?> getIngredientSpellingCorrection({
  String? ingredientName,
  Product? product,
  User? user,
  QueryType? queryType,
}) async {
  Map<String, String> spellingCorrectionParam;

  if (ingredientName != null) {
    spellingCorrectionParam = {
      'text': ingredientName,
    };
  } else if (product != null && product.barcode != null) {
    spellingCorrectionParam = {
      'barcode': product.barcode!,
    };
  } else {
    return null;
  }

  var spellingCorrectionUri = UriHelper.getRobotoffUri(
    path: 'api/v1/predict/ingredients/spellcheck',
    queryType: queryType,
  );

  Response response = await HttpHelper().doPostRequest(
    spellingCorrectionUri,
    spellingCorrectionParam,
    user,
    queryType: queryType,
    addCredentialsToBody: false,
    addCredentialsToHeader: true,
  );
  SpellingCorrection result = SpellingCorrection.fromJson(
      json.decode(utf8.decode(response.bodyBytes)));

  return result;
}