Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: ProductQuery.getLanguage() is now not nullable #3896

Merged
merged 1 commit into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class _AddBasicDetailsPageState extends State<AddBasicDetailsPage> {
}
}
if (_names.isNotEmpty) {
final OpenFoodFactsLanguage language = ProductQuery.getLanguage()!;
final OpenFoodFactsLanguage language = ProductQuery.getLanguage();
if (_names.containsKey(language)) {
// best choice
_currentLanguage = language;
Expand Down
2 changes: 1 addition & 1 deletion packages/smooth_app/lib/pages/product/ocr_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ abstract class OcrHelper {
bool hasAddExtraPhotoButton();

@protected
OpenFoodFactsLanguage getLanguage() => ProductQuery.getLanguage()!;
OpenFoodFactsLanguage getLanguage() => ProductQuery.getLanguage();

@protected
User getUser() => ProductQuery.getUser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class OrderedNutrientsCache {
Future<OrderedNutrients> _download() async {
final String string = await OpenFoodAPIClient.getOrderedNutrientsJsonString(
country: ProductQuery.getCountry()!,
language: ProductQuery.getLanguage()!,
language: ProductQuery.getLanguage(),
);
final OrderedNutrients result = OrderedNutrients.fromJson(
jsonDecode(string) as Map<String, dynamic>,
Expand All @@ -73,7 +73,7 @@ class OrderedNutrientsCache {
/// Database key.
String _getKey() {
final OpenFoodFactsCountry country = ProductQuery.getCountry()!;
final OpenFoodFactsLanguage language = ProductQuery.getLanguage()!;
final OpenFoodFactsLanguage language = ProductQuery.getLanguage();
return 'nutrients.pl'
'/${country.offTag}'
'/${language.code}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ abstract class AbstractSimpleInputPageHelper extends ChangeNotifier {

/// Returns the current language.
@protected
OpenFoodFactsLanguage getLanguage() => ProductQuery.getLanguage()!;
OpenFoodFactsLanguage getLanguage() => ProductQuery.getLanguage();

/// Adds all the non-already existing items from the controller.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SimpleInputTextField extends StatelessWidget {
Widget build(BuildContext context) {
final SuggestionManager manager = SuggestionManager(
tagType!,
language: ProductQuery.getLanguage()!,
language: ProductQuery.getLanguage(),
country: ProductQuery.getCountry(),
categories: categories,
shape: shapeProvider?.call(),
Expand Down
2 changes: 1 addition & 1 deletion packages/smooth_app/lib/pages/product/summary_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class _SummaryCardState extends State<SummaryCard> {
String? categoryTag;
String? categoryLabel;
final List<String>? labels =
_product.categoriesTagsInLanguages?[ProductQuery.getLanguage()!];
_product.categoriesTagsInLanguages?[ProductQuery.getLanguage()];
final List<String>? tags = _product.categoriesTags;
if (tags != null &&
labels != null &&
Expand Down
2 changes: 1 addition & 1 deletion packages/smooth_app/lib/query/paged_product_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract class PagedProductQuery {

int get pageNumber => _pageNumber;

final OpenFoodFactsLanguage? language = ProductQuery.getLanguage();
final OpenFoodFactsLanguage language = ProductQuery.getLanguage();
OpenFoodFactsCountry? get country => world ? null : ProductQuery.getCountry();

/// Is that the world mode (true), or the standard country mode (false).
Expand Down
8 changes: 4 additions & 4 deletions packages/smooth_app/lib/query/product_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ abstract class ProductQuery {

static OpenFoodFactsCountry? _country;

// TODO(monsieurtanuki): make it non-nullable
/// Returns the global language for API queries.
static OpenFoodFactsLanguage? getLanguage() {
static OpenFoodFactsLanguage getLanguage() {
final List<OpenFoodFactsLanguage> languages =
OpenFoodAPIConfiguration.globalLanguages ?? <OpenFoodFactsLanguage>[];
if (languages.isEmpty) {
return null;
// very very unlikely
return OpenFoodFactsLanguage.UNDEFINED;
}
return languages[0];
}
Expand Down Expand Up @@ -58,7 +58,7 @@ abstract class ProductQuery {
}

/// Returns the global locale string (e.g. 'pt_BR')
static String getLocaleString() => '${getLanguage()!.code}'
static String getLocaleString() => '${getLanguage().code}'
'_'
'${getCountry()!.offTag.toUpperCase()}';

Expand Down
2 changes: 1 addition & 1 deletion packages/smooth_app/lib/query/product_questions_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ProductQuestionsQuery {
final RobotoffQuestionResult result =
await RobotoffAPIClient.getProductQuestions(
_barcode,
ProductQuery.getLanguage()!,
ProductQuery.getLanguage(),
count: 3,
);
return result.questions ?? <RobotoffQuestion>[];
Expand Down
2 changes: 1 addition & 1 deletion packages/smooth_app/lib/query/questions_query.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class QuestionsQuery {
Future<List<RobotoffQuestion>> getQuestions() async {
final RobotoffQuestionResult result =
await RobotoffAPIClient.getRandomQuestions(
ProductQuery.getLanguage()!,
ProductQuery.getLanguage(),
OpenFoodAPIConfiguration.globalUser,
count: 3,
);
Expand Down