Skip to content

refactor: migrate from iso_countries to l10n_countries #6541

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

Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
997aed0
refactor: migrate from iso_countries to l10n_countries
pavaniroid Apr 10, 2025
380e83b
fix: apply reviewer suggestions.
pavaniroid Apr 12, 2025
f058bcb
fix: apply monsieurtanuki feedback.
pavaniroid Apr 14, 2025
d4f7dfe
fix: apply monsieurtanuki feedback.
pavaniroid Apr 14, 2025
c11ab2e
fix: finalize logic based on reviewer feedback
pavaniroid Apr 15, 2025
d2d4583
fix: apply reviewer feedback
pavaniroid Apr 16, 2025
335b3f2
fix: create LocalizedCountry class
pavaniroid Apr 20, 2025
73d1bd5
refactor: apply reviewer feedback to LocalizedCountry
pavanlashkari Apr 22, 2025
ea22089
fix: design promo (#6563)
teolemon Apr 25, 2025
f943f18
ci: Update xcversion in fastfile
teolemon Apr 26, 2025
d23b07a
ci: Update android-release-to-org-openfoodfacts-scanner.yml
teolemon Apr 26, 2025
a0917eb
docs: Update config.yaml
teolemon Apr 26, 2025
15d374d
ci: Update config.yaml
teolemon Apr 26, 2025
4cf4c65
fix: Update .gitignore with kaa.arb
teolemon Apr 26, 2025
1d895ff
fix: Update plural formatting in localization files for Greek and Dut…
PrimaelQuemerais Apr 26, 2025
f6284e0
feat: Adding Robotoff Questions to product edition (#6407)
PrimaelQuemerais Apr 26, 2025
8ca9d82
ci: dartdoc + mkdocs (#5717)
teolemon Apr 27, 2025
df0343e
fix: Update dartdoc.yml
teolemon Apr 27, 2025
cdd93b9
fix: Update dartdoc.yml
teolemon Apr 27, 2025
4049d8f
fix: Update dartdoc.yml
teolemon Apr 27, 2025
aca2b47
fix: Update dartdoc.yml
teolemon Apr 27, 2025
7897374
fix: Update README.md
teolemon Apr 27, 2025
dcf31fa
fix: Update dartdoc.yml
teolemon Apr 27, 2025
913d888
fix: Update dartdoc.yml
teolemon Apr 27, 2025
943db63
ci: Update mkdocs.yml by adding edit button
teolemon Apr 30, 2025
11bf06d
fix: Move Hunger Games to a real view instead of overlay (#4681) (#6555)
LorenzoMascia Apr 30, 2025
8ed470b
chore: New translations to review and merge (#6534)
openfoodfacts-bot Apr 30, 2025
b94a8e9
ci: Update dartdoc.yml
teolemon May 2, 2025
1ad9e9f
fix: Update dartdoc.yml
teolemon May 2, 2025
c68b4d1
ci: Update mkdocs.yml
teolemon May 2, 2025
44e4e5a
fix: Removed the option to add an item through barcode from Add a Pri…
Abhishek-P0207 May 2, 2025
832cc79
refactor: apply minor changes
pavanlashkari May 3, 2025
d1ba3f8
fix: dark mode issue in feedback page (#6576)
AshutoshKhadse23 May 4, 2025
f0340fc
fix: UI padding for better layout (#6509)
vinay769 May 4, 2025
9a23a8c
feat: add properties (Folksonomy Engine) button to navbar (#6505)
cherish2003 May 4, 2025
a031602
feat: add packaging photo access in packaging components screen (#6452)
cherish2003 May 5, 2025
453ccf5
feat: Improvements for Robotoff questions in Edit mode (#6579)
g123k May 5, 2025
6ca6a0b
chore(deps): bump fastlane in /packages/smooth_app/ios (#6582)
dependabot[bot] May 6, 2025
2b558dc
UI improvements (#6581)
g123k May 6, 2025
0e8aecb
ci: Create one-check.yml (#6570)
teolemon May 6, 2025
bed4d8b
fix: 6560 - explicit readyForPriceTagValidation parameter for proof u…
monsieurtanuki May 6, 2025
23c4abd
chore(deps): bump fastlane in /packages/smooth_app/android (#6583)
dependabot[bot] May 6, 2025
6450b6d
chore: UI/UX for Robotoff suggestions improved (#6585)
g123k May 7, 2025
f1820a8
chore(deps): bump actions/checkout from 3 to 4 (#6584)
dependabot[bot] May 7, 2025
3e91178
feat: Add infinite scrolling to the various Open Prices ListViews. (#…
AshutoshKhadse23 May 8, 2025
5d1279c
fix Languages sort order (#6592)
g123k May 15, 2025
994f202
Add price: swipe gesture available on iOS without changes (#6590)
g123k May 15, 2025
798a8d5
chore: New translations to review and merge (#6569)
openfoodfacts-bot May 15, 2025
6d40452
chore(develop): release 4.20.0 (#6442)
github-actions[bot] May 15, 2025
1f9fb2b
Update README.md (#6594)
g123k May 15, 2025
db036a4
fix: New UI for the food preferences (#6466)
chetanr25 May 16, 2025
aa568d0
refactor: migrate from iso_countries to l10n_countries
pavaniroid Apr 10, 2025
9b91b63
fix: apply reviewer suggestions.
pavaniroid Apr 12, 2025
e670034
fix: apply monsieurtanuki feedback.
pavaniroid Apr 14, 2025
f20a918
fix: apply monsieurtanuki feedback.
pavaniroid Apr 14, 2025
c5e8884
fix: finalize logic based on reviewer feedback
pavaniroid Apr 15, 2025
c63ce17
fix: apply reviewer feedback
pavaniroid Apr 16, 2025
ed89401
fix: create LocalizedCountry class
pavaniroid Apr 20, 2025
2655330
refactor: apply reviewer feedback to LocalizedCountry
pavanlashkari Apr 22, 2025
f33d84c
refactor: apply minor changes
pavanlashkari May 3, 2025
2b1dcbb
fix: solves conflicts
pavanlashkari May 16, 2025
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
@@ -1,17 +1,15 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart' hide Listener;
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:iso_countries/iso_countries.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/data_models/preferences/user_preferences.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';
import 'package:smooth_app/helpers/provider_helper.dart';
import 'package:smooth_app/pages/prices/emoji_helper.dart';
import 'package:smooth_app/services/smooth_services.dart';
import 'package:smooth_app/pages/preferences/country_selector/openfoodfacts_country_emoji_extension.dart';
import 'package:smooth_app/pages/preferences/country_selector/openfoodfacts_country_name_extension.dart';
import 'package:smooth_app/query/product_query.dart';
import 'package:smooth_app/widgets/selector_screen/smooth_screen_list_choice.dart';
import 'package:smooth_app/widgets/selector_screen/smooth_screen_selector_provider.dart';
import 'package:smooth_app/widgets/smooth_text.dart';
Expand Down Expand Up @@ -50,13 +48,14 @@ class CountrySelector extends StatelessWidget {
child: Consumer<_CountrySelectorProvider>(
builder: (BuildContext context, _CountrySelectorProvider provider, _) {
return switch (provider.value) {
PreferencesSelectorLoadingState<Country> _ => SizedBox(
PreferencesSelectorLoadingState<OpenFoodFactsCountry> _ => SizedBox(
height: loadingHeight,
child: const Center(
child: CircularProgressIndicator.adaptive(),
),
),
PreferencesSelectorLoadedState<Country> _ => _CountrySelectorButton(
PreferencesSelectorLoadedState<OpenFoodFactsCountry> _ =>
_CountrySelectorButton(
icon: icon,
innerPadding: padding ?? EdgeInsets.zero,
textStyle: textStyle,
Expand Down Expand Up @@ -100,19 +99,24 @@ class _CountrySelectorButton extends StatelessWidget {
child: ConstrainedBox(
constraints: const BoxConstraints(minHeight: 40.0),
child: ConsumerValueNotifierFilter<_CountrySelectorProvider,
PreferencesSelectorState<Country>>(
buildWhen: (PreferencesSelectorState<Country>? previousValue,
PreferencesSelectorState<Country> currentValue) =>
previousValue != null &&
currentValue is! PreferencesSelectorEditingState &&
(currentValue as PreferencesSelectorLoadedState<Country>)
.selectedItem !=
(previousValue as PreferencesSelectorLoadedState<Country>)
.selectedItem,
builder: (_, PreferencesSelectorState<Country> value, __) {
final Country? country =
(value as PreferencesSelectorLoadedState<Country>)
.selectedItem;
PreferencesSelectorState<OpenFoodFactsCountry>>(
buildWhen:
(PreferencesSelectorState<OpenFoodFactsCountry>? previousValue,
PreferencesSelectorState<OpenFoodFactsCountry>
currentValue) =>
previousValue != null &&
currentValue is! PreferencesSelectorEditingState &&
(currentValue as PreferencesSelectorLoadedState<
OpenFoodFactsCountry>)
.selectedItem !=
(previousValue as PreferencesSelectorLoadedState<
OpenFoodFactsCountry>)
.selectedItem,
builder:
(_, PreferencesSelectorState<OpenFoodFactsCountry> value, __) {
final OpenFoodFactsCountry? country = (value
as PreferencesSelectorLoadedState<OpenFoodFactsCountry>)
.selectedItem;

return Padding(
padding: innerPadding,
Expand All @@ -122,8 +126,7 @@ class _CountrySelectorButton extends StatelessWidget {
SizedBox(
width: IconTheme.of(context).size! + LARGE_SPACE,
child: AutoSizeText(
EmojiHelper.getEmojiByCountryCode(
country.countryCode)!,
country.emoji,
textAlign: TextAlign.center,
style:
TextStyle(fontSize: IconTheme.of(context).size),
Expand Down Expand Up @@ -191,20 +194,18 @@ class _CountrySelectorButton extends StatelessWidget {
/// (eg: the user uses the Android back button).
if (newCountry == null) {
context.read<_CountrySelectorProvider>().dismissSelectedItem();
} else if (newCountry is Country) {
} else if (newCountry is OpenFoodFactsCountry) {
_changeCurrencyIfRelevant(context, newCountry);
}
}

// TODO(g123k): move this to a dedicated Provider
Future<void> _changeCurrencyIfRelevant(
final BuildContext context,
final Country country,
final OpenFoodFactsCountry country,
) async {
final UserPreferences userPreferences = context.read<UserPreferences>();
final OpenFoodFactsCountry? offCountry =
OpenFoodFactsCountry.fromOffTag(country.countryCode);
final String? possibleCurrencyCode = offCountry?.currency?.name;
final String? possibleCurrencyCode = country.currency?.name;

if (possibleCurrencyCode == null) {
return;
Expand Down Expand Up @@ -259,12 +260,12 @@ class _CountrySelectorScreen extends StatelessWidget {
Widget build(BuildContext context) {
final AppLocalizations appLocalizations = AppLocalizations.of(context);

return SmoothSelectorScreen<Country>(
return SmoothSelectorScreen<OpenFoodFactsCountry>(
provider: provider,
title: appLocalizations.country_selector_title,
itemBuilder: (
BuildContext context,
Country country,
OpenFoodFactsCountry country,
bool selected,
String filter,
) {
Expand All @@ -273,14 +274,14 @@ class _CountrySelectorScreen extends StatelessWidget {
Expanded(
flex: 1,
child: Text(
EmojiHelper.getEmojiByCountryCode(country.countryCode) ?? '',
country.emoji,
style: const TextStyle(fontSize: 25.0),
),
),
Expanded(
flex: 2,
child: Text(
country.countryCode.toUpperCase(),
country.offTag.toUpperCase(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same UK potential issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use iso2 instead.

textAlign: TextAlign.center,
maxLines: 1,
overflow: TextOverflow.ellipsis,
Expand All @@ -289,7 +290,9 @@ class _CountrySelectorScreen extends StatelessWidget {
Expanded(
flex: 7,
child: TextHighlighter(
text: country.name,
text:
country.getLocalizedName(ProductQuery.getLanguage().code) ??
'',
filter: filter,
textStyle: const TextStyle(
fontWeight: FontWeight.w600,
Expand All @@ -299,35 +302,35 @@ class _CountrySelectorScreen extends StatelessWidget {
],
);
},
itemsFilter: (List<Country> list, Country? selectedItem,
Country? selectedItemOverride, String filter) =>
itemsFilter: (List<OpenFoodFactsCountry> list,
OpenFoodFactsCountry? selectedItem,
OpenFoodFactsCountry? selectedItemOverride,
String filter) =>
_filterCountries(
list,
selectedItem,
selectedItemOverride,
filter,
),
list, selectedItem, selectedItemOverride, filter, context),
);
}

Iterable<Country> _filterCountries(
List<Country> countries,
Country? userCountry,
Country? selectedCountry,
String? filter,
) {
Iterable<OpenFoodFactsCountry> _filterCountries(
List<OpenFoodFactsCountry> countries,
OpenFoodFactsCountry? userCountry,
OpenFoodFactsCountry? selectedCountry,
String? filter,
BuildContext context) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
BuildContext context) {
) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove context as we don't need it.

if (filter == null || filter.isEmpty) {
return countries;
}

return countries.where(
(Country country) =>
(OpenFoodFactsCountry country) =>
country == userCountry ||
country == selectedCountry ||
country.name.toLowerCase().contains(
filter.toLowerCase(),
) ||
country.countryCode.toLowerCase().contains(
(country
.getLocalizedName(ProductQuery.getLanguage().code)
?.toLowerCase()
.contains(filter.toLowerCase()) ??
false) ||
country.offTag.toLowerCase().contains(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

offTag or iso2code? Or both?

filter.toLowerCase(),
),
);
Expand Down
Loading