getRandomRobotoffQuestion static method

Future<RobotoffQuestionResult> getRandomRobotoffQuestion(
  1. String lang,
  2. User user, {
  3. int? count,
  4. List<InsightType>? types,
  5. QueryType? queryType,
})

Implementation

static Future<RobotoffQuestionResult> getRandomRobotoffQuestion(
  String lang,
  User user, {
  int? count,
  List<InsightType>? types,
  QueryType? queryType,
}) async {
  if (count == null || count <= 0) {
    count = 1;
  }

  final List<String> typesValues = [];
  if (types != null) {
    for (final InsightType t in types) {
      final String? value = t.value;
      if (value != null) {
        typesValues.add(value);
      }
    }
  }

  final Map<String, String> parameters = <String, String>{
    'lang': lang,
    'count': count.toString(),
    if (typesValues.isNotEmpty) 'insight_types': typesValues.join(',')
  };

  var robotoffQuestionUri = UriHelper.getRobotoffUri(
    path: 'api/v1/questions/random',
    queryParameters: parameters,
    queryType: queryType,
  );

  Response response = await HttpHelper().doGetRequest(
    robotoffQuestionUri,
    user: user,
    queryType: queryType,
  );
  var result = RobotoffQuestionResult.fromJson(
      json.decode(utf8.decode(response.bodyBytes)));

  return result;
}