Files
smooth-app/packages/smooth_app/lib/query/random_questions_query.dart
monsieurtanuki 2b49c87daf chore: upgrade to off-dart 3.0.0 (#4686)
Impacted files:
* `background_task.dart`: minor refactoring
* `background_task_crop.dart`: added the `UriProductHelper` parameter
* `background_task_details.dart`: added the `UriProductHelper` parameter
* `background_task_download_products.dart`: added the `UriProductHelper` parameter
* `background_task_image.dart`: added the `UriProductHelper` parameter
* `background_task_top_barcodes.dart`: added the `UriProductHelper` parameter
* `background_task_unselect.dart`: added the `UriProductHelper` parameter
* `forgot_password_page.dart`: added the `UriProductHelper` parameter
* `ocr_ingredients_helper.dart`: added the `UriProductHelper` parameter
* `ocr_packaging_helper.dart`: added the `UriProductHelper` parameter
* `onboarding_data_product.dart`: added the `UriProductHelper` parameter
* `ordered_nutrients_cache.dart`: added the `UriProductHelper` parameter
* `paged_product_query.dart`: added the `UriProductHelper` parameter
* `product_cards_helper.dart`: now using an off-dart method
* `product_image_server_button.dart`: added the `UriProductHelper` parameter
* `product_list_import_export.dart`: added the `UriProductHelper` parameter
* `product_list_page.dart`: added the `UriProductHelper` parameter
* `product_query.dart`: added a static `UriProductHelper` that more or less replaces the `QueryType`; minor refactoring
* `product_refresher.dart`: added the `UriProductHelper` parameter
* `pubspec.lock`: wtf
* `pubspec.yaml`: upgraded off-dart to 3.0.0
* `random_questions_query.dart`: `countries` instead of `country`
* `sign_up_page.dart`: added the `UriProductHelper` parameter
* `temp_product_list_share_helper.dart`: now using a `UriProductHelper`
* `user_management_provider.dart`: added the `UriProductHelper` parameter
* `user_preferences_account.dart`: added the `UriProductHelper` parameter
* `user_preferences_dev_debug_info.dart`: minor refactoring
* `user_preferences_dev_mode.dart`: minor refactoring
2023-10-04 07:37:29 +02:00

38 lines
1.3 KiB
Dart

import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/pages/product/common/product_refresher.dart';
import 'package:smooth_app/query/product_query.dart';
import 'package:smooth_app/query/questions_query.dart';
/// Robotoff questions helper, for random product questions.
class RandomQuestionsQuery extends QuestionsQuery {
@override
Future<List<RobotoffQuestion>> getQuestions(
final LocalDatabase localDatabase,
final int count,
) async {
final RobotoffQuestionResult result = await RobotoffAPIClient.getQuestions(
ProductQuery.getLanguage(),
user: ProductQuery.getUser(),
countries: <OpenFoodFactsCountry>[ProductQuery.getCountry()],
count: count,
questionOrder: RobotoffQuestionOrder.random,
);
if (result.questions?.isNotEmpty != true) {
return <RobotoffQuestion>[];
}
final List<String> barcodes = <String>[];
for (final RobotoffQuestion question in result.questions!) {
if (question.barcode != null) {
barcodes.add(question.barcode!);
}
}
await ProductRefresher().silentFetchAndRefreshList(
barcodes: barcodes,
localDatabase: localDatabase,
);
return result.questions ?? <RobotoffQuestion>[];
}
}