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

feat: #2503 - language selector now in "App Settings" (for all users) #2658

Merged
merged 1 commit into from
Jul 25, 2022
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
23 changes: 17 additions & 6 deletions packages/smooth_app/lib/generic_lib/widgets/language_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,24 @@ class LanguageSelectorSettings extends StatelessWidget {
// The languages that are supported by flutter widget
final String currentLanguageCode = userPreferences.appLanguageCode ??
Localizations.localeOf(context).toString();
final String nameInLanguage =
final OpenFoodFactsLanguage language =
LanguageHelper.fromJson(currentLanguageCode);
final String nameInEnglish =
_languages.getLanguageNameInEnglishFromOpenFoodFactsLanguage(
LanguageHelper.fromJson(currentLanguageCode));
language,
);
final String nameInLanguage =
_languages.getLanguageNameInLanguageFromOpenFoodFactsLanguage(
language,
);
return ListTile(
leading: const Icon(Icons.language),
title: Text(
appLocalizations.choose_app_language,
),
subtitle: Text(
'$nameInLanguage ($currentLanguageCode)',
'$nameInLanguage ($nameInEnglish)',
softWrap: false,
overflow: TextOverflow.fade,
),
trailing: const Icon(Icons.arrow_drop_down),
onTap: () async {
final List<OpenFoodFactsLanguage> leftovers =
_languages.getSupportedLanguagesNameInEnglish();
Expand Down Expand Up @@ -69,12 +74,18 @@ class LanguageSelectorSettings extends StatelessWidget {
item)
.toLowerCase()
.contains(query.toLowerCase()) ||
_languages
.getLanguageNameInLanguageFromOpenFoodFactsLanguage(
item)
.toLowerCase()
.contains(query.toLowerCase()) ||
item.code.contains(query))
.toList();
},
);
},
),
// TODO(monsieurtanuki): an optimization would be not to generate all tiles and use something like a ListView.builder instead
...List<ListTile>.generate(
filteredList.length,
(int index) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:smooth_app/data_models/user_preferences.dart';
import 'package:smooth_app/database/dao_product_list.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/generic_lib/dialogs/smooth_alert_dialog.dart';
import 'package:smooth_app/generic_lib/widgets/language_selector.dart';
import 'package:smooth_app/helpers/data_importer/product_list_import_export.dart';
import 'package:smooth_app/helpers/data_importer/smooth_app_data_importer.dart';
import 'package:smooth_app/pages/onboarding/onboarding_flow_navigator.dart';
Expand Down Expand Up @@ -333,10 +332,6 @@ class UserPreferencesDevMode extends AbstractUserPreferences {
setState(() {});
},
),
LanguageSelectorSettings(
userPreferences: userPreferences,
appLocalizations: appLocalizations,
),
ListTile(
// Do not translate
title: const Text('Reset App Language'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:matomo_tracker/matomo_tracker.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/data_models/user_preferences.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/widgets/language_selector.dart';
import 'package:smooth_app/helpers/analytics_helper.dart';
import 'package:smooth_app/helpers/camera_helper.dart';
import 'package:smooth_app/knowledge_panel/knowledge_panels/knowledge_panel_card.dart';
Expand Down Expand Up @@ -66,6 +67,7 @@ class _ApplicationSettings extends StatelessWidget {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
final ThemeProvider themeProvider = context.watch<ThemeProvider>();
final ThemeData themeData = Theme.of(context);
final UserPreferences userPreferences = context.watch<UserPreferences>();

return Column(
children: <Widget>[
Expand Down Expand Up @@ -111,6 +113,17 @@ class _ApplicationSettings extends StatelessWidget {
const UserPreferencesListItemDivider(),
const _CountryPickerSetting(),
const UserPreferencesListItemDivider(),
ListTile(
title: Text(
appLocalizations.choose_app_language,
style: Theme.of(context).textTheme.headline4,
),
subtitle: LanguageSelectorSettings(
userPreferences: userPreferences,
appLocalizations: appLocalizations,
),
),
const UserPreferencesListItemDivider(),
],
);
}
Expand Down