getQuestions static method
- OpenFoodFactsLanguage language,
- {User? user,
- int? count,
- int? page,
- List<
InsightType> ? insightTypes, - Iterable<
OpenFoodFactsCountry> ? countries, - List<
String> ? brands, - RobotoffQuestionOrder? questionOrder,
- ServerType? serverType,
- String? valueTag,
- 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)),
);
}