fixing accent removal
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import 'package:collection/collection.dart' show IterableExtension;
|
||||
import 'package:diacritic/diacritic.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart' show kDebugMode;
|
||||
|
||||
@@ -45,7 +44,9 @@ class CountryCode {
|
||||
try {
|
||||
return CountryCode.fromCountryCode(countryCode);
|
||||
} catch (e) {
|
||||
if (kDebugMode) print('Failed to recognize country from countryCode: $countryCode');
|
||||
if (kDebugMode) {
|
||||
print('Failed to recognize country from countryCode: $countryCode');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -61,20 +62,21 @@ class CountryCode {
|
||||
try {
|
||||
return CountryCode.fromDialCode(dialCode);
|
||||
} catch (e) {
|
||||
if (kDebugMode) print('Failed to recognize country from dialCode: $dialCode');
|
||||
if (kDebugMode) {
|
||||
print('Failed to recognize country from dialCode: $dialCode');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
CountryCode localize(BuildContext context) {
|
||||
final nam = CountryLocalizations.of(context)?.translate(code) ?? name;
|
||||
return this
|
||||
..name = nam == null? name : removeDiacritics(nam);
|
||||
return this..name = nam ?? name;
|
||||
}
|
||||
|
||||
factory CountryCode.fromJson(Map<String, dynamic> json) {
|
||||
return CountryCode(
|
||||
name: removeDiacritics(json['name']),
|
||||
name: json['name'],
|
||||
code: json['code'],
|
||||
dialCode: json['dial_code'],
|
||||
flagUri: 'flags/${json['code'].toLowerCase()}.png',
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:diacritic/diacritic.dart';
|
||||
|
||||
import 'country_code.dart';
|
||||
import 'country_localizations.dart';
|
||||
@@ -50,7 +51,7 @@ class SelectionDialog extends StatefulWidget {
|
||||
InputDecoration searchDecoration = const InputDecoration(),
|
||||
this.searchStyle,
|
||||
this.textStyle,
|
||||
required this.topBarPadding,
|
||||
required this.topBarPadding,
|
||||
this.headerText,
|
||||
this.boxDecoration,
|
||||
this.showFlag,
|
||||
@@ -62,9 +63,12 @@ class SelectionDialog extends StatefulWidget {
|
||||
this.hideSearch = false,
|
||||
this.hideCloseIcon = false,
|
||||
this.closeIcon,
|
||||
this.dialogItemPadding = const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
|
||||
this.dialogItemPadding =
|
||||
const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
|
||||
this.searchPadding = const EdgeInsets.symmetric(horizontal: 24),
|
||||
}) : searchDecoration = searchDecoration.prefixIcon == null ? searchDecoration.copyWith(prefixIcon: const Icon(Icons.search)) : searchDecoration,
|
||||
}) : searchDecoration = searchDecoration.prefixIcon == null
|
||||
? searchDecoration.copyWith(prefixIcon: const Icon(Icons.search))
|
||||
: searchDecoration,
|
||||
super(key: key);
|
||||
|
||||
@override
|
||||
@@ -81,7 +85,8 @@ class _SelectionDialogState extends State<SelectionDialog> {
|
||||
child: Container(
|
||||
clipBehavior: Clip.hardEdge,
|
||||
width: widget.size?.width ?? MediaQuery.of(context).size.width,
|
||||
height: widget.size?.height ?? MediaQuery.of(context).size.height * 0.85,
|
||||
height:
|
||||
widget.size?.height ?? MediaQuery.of(context).size.height * 0.85,
|
||||
decoration: widget.boxDecoration ??
|
||||
BoxDecoration(
|
||||
color: widget.backgroundColor ?? Colors.white,
|
||||
@@ -100,7 +105,9 @@ class _SelectionDialogState extends State<SelectionDialog> {
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Padding(
|
||||
padding:!widget.hideHeaderText? widget.topBarPadding: EdgeInsets.zero,
|
||||
padding: !widget.hideHeaderText
|
||||
? widget.topBarPadding
|
||||
: EdgeInsets.zero,
|
||||
child: Row(
|
||||
mainAxisAlignment: widget.headerAlignment,
|
||||
children: [
|
||||
@@ -177,11 +184,14 @@ class _SelectionDialogState extends State<SelectionDialog> {
|
||||
if (widget.showFlag!)
|
||||
Flexible(
|
||||
child: Container(
|
||||
margin: Directionality.of(context) == TextDirection.ltr // Here Adding padding depending on the locale language direction
|
||||
margin: Directionality.of(context) ==
|
||||
TextDirection
|
||||
.ltr // Here Adding padding depending on the locale language direction
|
||||
? const EdgeInsets.only(right: 16.0)
|
||||
: const EdgeInsets.only(left: 16.0),
|
||||
decoration: widget.flagDecoration,
|
||||
clipBehavior: widget.flagDecoration == null ? Clip.none : Clip.hardEdge,
|
||||
clipBehavior:
|
||||
widget.flagDecoration == null ? Clip.none : Clip.hardEdge,
|
||||
child: Image.asset(
|
||||
e.flagUri!,
|
||||
package: 'country_code_picker',
|
||||
@@ -192,7 +202,9 @@ class _SelectionDialogState extends State<SelectionDialog> {
|
||||
Expanded(
|
||||
flex: 4,
|
||||
child: Text(
|
||||
widget.showCountryOnly! ? e.toCountryStringOnly() : e.toLongString(),
|
||||
widget.showCountryOnly!
|
||||
? e.toCountryStringOnly()
|
||||
: e.toLongString(),
|
||||
overflow: TextOverflow.fade,
|
||||
style: widget.textStyle,
|
||||
),
|
||||
@@ -208,7 +220,8 @@ class _SelectionDialogState extends State<SelectionDialog> {
|
||||
}
|
||||
|
||||
return Center(
|
||||
child: Text(CountryLocalizations.of(context)?.translate('no_country') ?? 'No country found'),
|
||||
child: Text(CountryLocalizations.of(context)?.translate('no_country') ??
|
||||
'No country found'),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -219,9 +232,15 @@ class _SelectionDialogState extends State<SelectionDialog> {
|
||||
}
|
||||
|
||||
void _filterElements(String s) {
|
||||
s = s.toUpperCase();
|
||||
final normalizedSearch = removeDiacritics(s.toUpperCase());
|
||||
setState(() {
|
||||
filteredElements = widget.elements.where((e) => e.code!.contains(s) || e.dialCode!.contains(s) || e.name!.toUpperCase().contains(s)).toList();
|
||||
filteredElements = widget.elements
|
||||
.where((e) =>
|
||||
e.code!.contains(normalizedSearch) ||
|
||||
e.dialCode!.contains(normalizedSearch) ||
|
||||
removeDiacritics(e.name!.toUpperCase())
|
||||
.contains(normalizedSearch))
|
||||
.toList();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user