11import 'package:flutter/material.dart' ;
2+ import 'package:diacritic/diacritic.dart' ;
23
34import 'country_code.dart' ;
45import 'country_localizations.dart' ;
@@ -50,7 +51,7 @@ class SelectionDialog extends StatefulWidget {
5051 InputDecoration searchDecoration = const InputDecoration (),
5152 this .searchStyle,
5253 this .textStyle,
53- required this .topBarPadding,
54+ required this .topBarPadding,
5455 this .headerText,
5556 this .boxDecoration,
5657 this .showFlag,
@@ -62,9 +63,12 @@ class SelectionDialog extends StatefulWidget {
6263 this .hideSearch = false ,
6364 this .hideCloseIcon = false ,
6465 this .closeIcon,
65- this .dialogItemPadding = const EdgeInsets .symmetric (horizontal: 24 , vertical: 8 ),
66+ this .dialogItemPadding =
67+ const EdgeInsets .symmetric (horizontal: 24 , vertical: 8 ),
6668 this .searchPadding = const EdgeInsets .symmetric (horizontal: 24 ),
67- }) : searchDecoration = searchDecoration.prefixIcon == null ? searchDecoration.copyWith (prefixIcon: const Icon (Icons .search)) : searchDecoration,
69+ }) : searchDecoration = searchDecoration.prefixIcon == null
70+ ? searchDecoration.copyWith (prefixIcon: const Icon (Icons .search))
71+ : searchDecoration,
6872 super (key: key);
6973
7074 @override
@@ -81,7 +85,8 @@ class _SelectionDialogState extends State<SelectionDialog> {
8185 child: Container (
8286 clipBehavior: Clip .hardEdge,
8387 width: widget.size? .width ?? MediaQuery .of (context).size.width,
84- height: widget.size? .height ?? MediaQuery .of (context).size.height * 0.85 ,
88+ height:
89+ widget.size? .height ?? MediaQuery .of (context).size.height * 0.85 ,
8590 decoration: widget.boxDecoration ??
8691 BoxDecoration (
8792 color: widget.backgroundColor ?? Colors .white,
@@ -100,7 +105,9 @@ class _SelectionDialogState extends State<SelectionDialog> {
100105 crossAxisAlignment: CrossAxisAlignment .end,
101106 children: [
102107 Padding (
103- padding: ! widget.hideHeaderText? widget.topBarPadding: EdgeInsets .zero,
108+ padding: ! widget.hideHeaderText
109+ ? widget.topBarPadding
110+ : EdgeInsets .zero,
104111 child: Row (
105112 mainAxisAlignment: widget.headerAlignment,
106113 children: [
@@ -177,11 +184,14 @@ class _SelectionDialogState extends State<SelectionDialog> {
177184 if (widget.showFlag! )
178185 Flexible (
179186 child: Container (
180- margin: Directionality .of (context) == TextDirection .ltr // Here Adding padding depending on the locale language direction
187+ margin: Directionality .of (context) ==
188+ TextDirection
189+ .ltr // Here Adding padding depending on the locale language direction
181190 ? const EdgeInsets .only (right: 16.0 )
182191 : const EdgeInsets .only (left: 16.0 ),
183192 decoration: widget.flagDecoration,
184- clipBehavior: widget.flagDecoration == null ? Clip .none : Clip .hardEdge,
193+ clipBehavior:
194+ widget.flagDecoration == null ? Clip .none : Clip .hardEdge,
185195 child: Image .asset (
186196 e.flagUri! ,
187197 package: 'country_code_picker' ,
@@ -192,7 +202,9 @@ class _SelectionDialogState extends State<SelectionDialog> {
192202 Expanded (
193203 flex: 4 ,
194204 child: Text (
195- widget.showCountryOnly! ? e.toCountryStringOnly () : e.toLongString (),
205+ widget.showCountryOnly!
206+ ? e.toCountryStringOnly ()
207+ : e.toLongString (),
196208 overflow: TextOverflow .fade,
197209 style: widget.textStyle,
198210 ),
@@ -208,7 +220,8 @@ class _SelectionDialogState extends State<SelectionDialog> {
208220 }
209221
210222 return Center (
211- child: Text (CountryLocalizations .of (context)? .translate ('no_country' ) ?? 'No country found' ),
223+ child: Text (CountryLocalizations .of (context)? .translate ('no_country' ) ??
224+ 'No country found' ),
212225 );
213226 }
214227
@@ -219,9 +232,15 @@ class _SelectionDialogState extends State<SelectionDialog> {
219232 }
220233
221234 void _filterElements (String s) {
222- s = s.toUpperCase ();
235+ final normalizedSearch = removeDiacritics ( s.toUpperCase () );
223236 setState (() {
224- filteredElements = widget.elements.where ((e) => e.code! .contains (s) || e.dialCode! .contains (s) || e.name! .toUpperCase ().contains (s)).toList ();
237+ filteredElements = widget.elements
238+ .where ((e) =>
239+ e.code! .contains (normalizedSearch) ||
240+ e.dialCode! .contains (normalizedSearch) ||
241+ removeDiacritics (e.name! .toUpperCase ())
242+ .contains (normalizedSearch))
243+ .toList ();
225244 });
226245 }
227246
0 commit comments