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: Filterable text: ensure to remove accents when comparing #4394

Merged
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
@@ -1,3 +1,4 @@
import 'package:diacritic/diacritic.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
Expand Down Expand Up @@ -145,19 +146,19 @@ class LanguageSelector extends StatelessWidget {
prefixIcon: const Icon(Icons.search),
controller: languageSelectorController,
onChanged: (String? query) {
query = query?.trim().toLowerCase();
query = removeDiacritics(query!.trim().toLowerCase());

setState(
() {
filteredList = leftovers
.where((OpenFoodFactsLanguage item) =>
_languages
.getNameInEnglish(item)
.toLowerCase()
removeDiacritics(_languages
.getNameInEnglish(item)
.toLowerCase())
.contains(query!.toLowerCase()) ||
_languages
.getNameInLanguage(item)
.toLowerCase()
removeDiacritics(_languages
.getNameInLanguage(item)
.toLowerCase())
.contains(query.toLowerCase()) ||
item.code.contains(query))
.toList();
Expand Down
19 changes: 12 additions & 7 deletions packages/smooth_app/lib/pages/onboarding/country_selector.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:diacritic/diacritic.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
Expand Down Expand Up @@ -95,19 +96,23 @@ class _CountrySelectorState extends State<CountrySelector> {
prefixIcon: const Icon(Icons.search),
controller: _countryController,
onChanged: (String? query) {
query = query?.trim().toLowerCase();
query = removeDiacritics(query!.trim().toLowerCase());

setState(
() {
filteredList = _countryList
.where(
(Country item) =>
item.name.toLowerCase().contains(
query!,
) ||
item.countryCode.toLowerCase().contains(
query,
),
removeDiacritics(
item.name.toLowerCase())
.contains(
query!,
) ||
removeDiacritics(
item.countryCode.toLowerCase())
.contains(
query,
),
)
.toList(growable: false);
},
Expand Down
5 changes: 3 additions & 2 deletions packages/smooth_app/lib/widgets/smooth_text.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:diacritic/diacritic.dart';
import 'package:flutter/material.dart';

/// An extension on [TextStyle] that allows to have "well spaced" variant
Expand Down Expand Up @@ -86,8 +87,8 @@ class TextHighlighter extends StatelessWidget {
required TextStyle? highlightedStyle,
}) {
final Iterable<RegExpMatch> highlightedParts =
RegExp(filter.toLowerCase().trim()).allMatches(
text.toLowerCase(),
RegExp(removeDiacritics(filter).toLowerCase().trim()).allMatches(
removeDiacritics(text).toLowerCase(),
);

final List<(String, TextStyle?)> parts = <(String, TextStyle?)>[];
Expand Down
Loading