getQuestions static method

Future<RobotoffQuestionResult> getQuestions(
  1. OpenFoodFactsLanguage language,
  2. {User? user,
  3. int? count,
  4. int? page,
  5. List<InsightType>? insightTypes,
  6. Iterable<OpenFoodFactsCountry>? countries,
  7. List<String>? brands,
  8. RobotoffQuestionOrder? questionOrder,
  9. ServerType? serverType,
  10. String? valueTag,
  11. UriHelper uriHelper = uriHelperRobotoffProd}
)

cf. https://openfoodfacts.github.io/robotoff/references/api/#tag/Questions/paths/~1questions/get

Implementation

static Future<RobotoffQuestionResult> getQuestions(
  OpenFoodFactsLanguage language, {
  User? user,
  int? count,
  int? page,
  List<InsightType>? insightTypes,
  Iterable<OpenFoodFactsCountry>? countries,
  List<String>? brands,
  RobotoffQuestionOrder? questionOrder,
  ServerType? serverType,
  String? valueTag,
  final UriHelper uriHelper = uriHelperRobotoffProd,
}) async {
  final List<String> insightValues = [];
  if (insightTypes != null) {
    for (final InsightType insightType in insightTypes) {
      insightValues.add(insightType.offTag);
    }
  }

  final Map<String, String> parameters = <String, String>{
    'lang': language.code,
    if (count != null) 'count': count.toString(),
    if (page != null) 'page': page.toString(),
    if (serverType != null) 'server_type': serverType.offTag,
    if (insightValues.isNotEmpty) 'insight_types': insightValues.join(','),
    if (brands?.isNotEmpty == true) 'brands': brands!.join(','),
    if (questionOrder != null) 'order_by': questionOrder.offTag,
    if (countries?.isNotEmpty == true)
      'countries': _getCountryList(countries!),
    if (valueTag != null) 'value_tag': valueTag,
  };

  var robotoffQuestionUri = uriHelper.getUri(
    path: 'api/v1/questions',
    queryParameters: parameters,
  );

  final Response response = await HttpHelper().doGetRequest(
    robotoffQuestionUri,
    user: user,
    uriHelper: uriHelper,
  );
  return RobotoffQuestionResult.fromJson(
    HttpHelper().jsonDecode(utf8.decode(response.bodyBytes)),
  );
}