From 04113eac287cc97704bd84dc2ce4a0d9cfca9a7a Mon Sep 17 00:00:00 2001 From: GnuaAruht Date: Sat, 22 Feb 2025 14:20:01 +0630 Subject: [PATCH] Add empty placeholder when no country was found --- lib/country_picker.dart | 2 ++ lib/src/country_list_bottom_sheet.dart | 4 ++++ lib/src/country_list_view.dart | 23 ++++++++++++++++++ lib/src/res/strings/ar.dart | 1 + lib/src/res/strings/bg.dart | 1 + lib/src/res/strings/ca.dart | 1 + lib/src/res/strings/cn.dart | 1 + lib/src/res/strings/cs.dart | 1 + lib/src/res/strings/da.dart | 1 + lib/src/res/strings/de.dart | 1 + lib/src/res/strings/en.dart | 1 + lib/src/res/strings/es.dart | 1 + lib/src/res/strings/et.dart | 1 + lib/src/res/strings/fa.dart | 1 + lib/src/res/strings/fr.dart | 1 + lib/src/res/strings/gr.dart | 1 + lib/src/res/strings/he.dart | 1 + lib/src/res/strings/hr.dart | 1 + lib/src/res/strings/ht.dart | 1 + lib/src/res/strings/id.dart | 1 + lib/src/res/strings/it.dart | 1 + lib/src/res/strings/ja.dart | 1 + lib/src/res/strings/ko.dart | 1 + lib/src/res/strings/ku.dart | 1 + lib/src/res/strings/lt.dart | 1 + lib/src/res/strings/lv.dart | 1 + lib/src/res/strings/nb.dart | 1 + lib/src/res/strings/nl.dart | 1 + lib/src/res/strings/nn.dart | 1 + lib/src/res/strings/np.dart | 1 + lib/src/res/strings/pl.dart | 1 + lib/src/res/strings/pt.dart | 1 + lib/src/res/strings/ro.dart | 1 + lib/src/res/strings/ru.dart | 1 + lib/src/res/strings/sk.dart | 1 + lib/src/res/strings/tr.dart | 1 + lib/src/res/strings/tw.dart | 1 + lib/src/res/strings/uk.dart | 1 + pubspec.lock | 32 +++++++++++++------------- 39 files changed, 80 insertions(+), 16 deletions(-) diff --git a/lib/country_picker.dart b/lib/country_picker.dart index 15082962..8267575c 100644 --- a/lib/country_picker.dart +++ b/lib/country_picker.dart @@ -59,6 +59,7 @@ void showCountryPicker({ List? countryFilter, bool showPhoneCode = false, CustomFlagBuilder? customFlagBuilder, + WidgetBuilder? emptySearchPlaceholderBuilder, CountryListThemeData? countryListTheme, bool searchAutofocus = false, bool showWorldWide = false, @@ -87,5 +88,6 @@ void showCountryPicker({ useSafeArea: useSafeArea, useRootNavigator: useRootNavigator, moveAlongWithKeyboard: moveAlongWithKeyboard, + emptySearchPlaceholderBuilder: emptySearchPlaceholderBuilder, ); } diff --git a/lib/src/country_list_bottom_sheet.dart b/lib/src/country_list_bottom_sheet.dart index cf37c240..293970f4 100644 --- a/lib/src/country_list_bottom_sheet.dart +++ b/lib/src/country_list_bottom_sheet.dart @@ -13,6 +13,7 @@ void showCountryListBottomSheet({ List? countryFilter, bool showPhoneCode = false, CustomFlagBuilder? customFlagBuilder, + WidgetBuilder? emptySearchPlaceholderBuilder, CountryListThemeData? countryListTheme, bool searchAutofocus = false, bool showWorldWide = false, @@ -40,6 +41,7 @@ void showCountryListBottomSheet({ showSearch, moveAlongWithKeyboard, customFlagBuilder, + emptySearchPlaceholderBuilder, ), ).whenComplete(() { if (onClosed != null) onClosed(); @@ -59,6 +61,7 @@ Widget _builder( bool showSearch, bool moveAlongWithKeyboard, CustomFlagBuilder? customFlagBuilder, + WidgetBuilder? emptySearchPlaceholderBuilder, ) { final device = MediaQuery.of(context).size.height; final statusBarHeight = MediaQuery.of(context).padding.top; @@ -103,6 +106,7 @@ Widget _builder( showWorldWide: showWorldWide, showSearch: showSearch, customFlagBuilder: customFlagBuilder, + emptySearchPlaceholderBuilder: emptySearchPlaceholderBuilder, ), ), ); diff --git a/lib/src/country_list_view.dart b/lib/src/country_list_view.dart index def7bc02..3bf2bec6 100644 --- a/lib/src/country_list_view.dart +++ b/lib/src/country_list_view.dart @@ -48,6 +48,9 @@ class CountryListView extends StatefulWidget { /// Custom builder function for flag widget final CustomFlagBuilder? customFlagBuilder; + /// Custom empty search placeholder when no country is found + final WidgetBuilder? emptySearchPlaceholderBuilder; + const CountryListView({ Key? key, required this.onSelect, @@ -60,6 +63,7 @@ class CountryListView extends StatefulWidget { this.showWorldWide = false, this.showSearch = true, this.customFlagBuilder, + this.emptySearchPlaceholderBuilder, }) : assert( exclude == null || countryFilter == null, 'Cannot provide both exclude and countryFilter', @@ -166,6 +170,8 @@ class _CountryListViewState extends State { ..._filteredList .map((country) => _listRow(country)) .toList(), + if(_filteredList.isEmpty) + widget.emptySearchPlaceholderBuilder?.call(context) ?? _defaultEmptySearchPlaceholder(context) ], ), ), @@ -173,6 +179,23 @@ class _CountryListViewState extends State { ); } + Widget _defaultEmptySearchPlaceholder(BuildContext context) { + return Container( + height: 200.0, + width: double.infinity, + alignment: Alignment.center, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Icon(Icons.search_off,size: 50.0), + const SizedBox(height: 10.0), + Text(CountryLocalizations.of(context) + ?.countryName(countryCode: "noCountryFound") ?? "No country found."), + ], + ), + ); + } + Widget _listRow(Country country) { final TextStyle _textStyle = widget.countryListTheme?.textStyle ?? _defaultTextStyle; diff --git a/lib/src/res/strings/ar.dart b/lib/src/res/strings/ar.dart index bb65d2b4..238035bc 100644 --- a/lib/src/res/strings/ar.dart +++ b/lib/src/res/strings/ar.dart @@ -247,4 +247,5 @@ Map ar = { "ZM": "زامبيا", "ZW": "زيمبابوي", "search": "بحث", + "noCountryFound": "لم يتم العثور على أي بلد.", }; diff --git a/lib/src/res/strings/bg.dart b/lib/src/res/strings/bg.dart index 5ab031be..0fb595c7 100644 --- a/lib/src/res/strings/bg.dart +++ b/lib/src/res/strings/bg.dart @@ -247,4 +247,5 @@ Map bg = { "ZM": "Замбия", "ZW": "Зимбабве", "search": "Търсене", + "noCountryFound": "Няма намерена държава.", }; diff --git a/lib/src/res/strings/ca.dart b/lib/src/res/strings/ca.dart index 67e2c396..72508af2 100644 --- a/lib/src/res/strings/ca.dart +++ b/lib/src/res/strings/ca.dart @@ -247,4 +247,5 @@ Map ca = { "ZM": "Zàmbia", "ZW": "Zimbabwe", "search": "Cerca", + "noCountryFound": "No s'ha trobat cap país.", }; diff --git a/lib/src/res/strings/cn.dart b/lib/src/res/strings/cn.dart index 7ff57763..87f14d41 100644 --- a/lib/src/res/strings/cn.dart +++ b/lib/src/res/strings/cn.dart @@ -247,4 +247,5 @@ Map cn = { "ZM": "赞比亚", "ZW": "津巴布韦", "search": "查询", + "noCountryFound": "未找到任何国家。", }; diff --git a/lib/src/res/strings/cs.dart b/lib/src/res/strings/cs.dart index 954a38e9..dc675b2d 100644 --- a/lib/src/res/strings/cs.dart +++ b/lib/src/res/strings/cs.dart @@ -247,4 +247,5 @@ Map cs = { "ZM": "Zambie", "ZW": "Zimbabwe", "search": "Hledat", + "noCountryFound": "Nebyla nalezena žádná země.", }; diff --git a/lib/src/res/strings/da.dart b/lib/src/res/strings/da.dart index 67562138..d0f1e3e4 100644 --- a/lib/src/res/strings/da.dart +++ b/lib/src/res/strings/da.dart @@ -247,4 +247,5 @@ Map da = { "ZM": "Zambia", "ZW": "Zimbabwe", "search": "Søg", + "noCountryFound": "Intet land fundet.", }; diff --git a/lib/src/res/strings/de.dart b/lib/src/res/strings/de.dart index 4bb5345c..259e6ecc 100644 --- a/lib/src/res/strings/de.dart +++ b/lib/src/res/strings/de.dart @@ -247,4 +247,5 @@ Map de = { "ZM": "Sambia", "ZW": "Simbabwe", "search": "Suchen", + "noCountryFound": "Kein Land gefunden.", }; diff --git a/lib/src/res/strings/en.dart b/lib/src/res/strings/en.dart index 11f9e78f..36299381 100644 --- a/lib/src/res/strings/en.dart +++ b/lib/src/res/strings/en.dart @@ -247,4 +247,5 @@ Map en = { "ZM": "Zambia", "ZW": "Zimbabwe", "search": "Search", + "noCountryFound": "No country found.", }; diff --git a/lib/src/res/strings/es.dart b/lib/src/res/strings/es.dart index 322d2ec7..79df6567 100644 --- a/lib/src/res/strings/es.dart +++ b/lib/src/res/strings/es.dart @@ -247,4 +247,5 @@ Map es = { "ZM": "Zambia", "ZW": "Zimbabue", "search": "Buscar", + "noCountryFound": "No se encontró ningún país.", }; diff --git a/lib/src/res/strings/et.dart b/lib/src/res/strings/et.dart index a3fdda0e..2cbf32c4 100644 --- a/lib/src/res/strings/et.dart +++ b/lib/src/res/strings/et.dart @@ -247,4 +247,5 @@ Map et = { "WW": "Kogu Maailmas", "ZW": "Zimbabwe", "search": "Otsi", + "noCountryFound": "Ühtegi riiki ei leitud.", }; diff --git a/lib/src/res/strings/fa.dart b/lib/src/res/strings/fa.dart index 78e449ea..3d62af28 100644 --- a/lib/src/res/strings/fa.dart +++ b/lib/src/res/strings/fa.dart @@ -247,4 +247,5 @@ Map fa = { "ZM": "زامبیا", "ZW": "زیمبابوه", "search": "جستجو", + "noCountryFound": "کشوری پیدا نشد", }; diff --git a/lib/src/res/strings/fr.dart b/lib/src/res/strings/fr.dart index 0e27035a..2592745d 100644 --- a/lib/src/res/strings/fr.dart +++ b/lib/src/res/strings/fr.dart @@ -246,4 +246,5 @@ Map fr = { "ZM": "Zambie", "ZW": "Zimbabwe", "search": "Chercher", + "noCountryFound": "Aucun pays trouvé.", }; diff --git a/lib/src/res/strings/gr.dart b/lib/src/res/strings/gr.dart index 3cdbf0a1..e671f080 100644 --- a/lib/src/res/strings/gr.dart +++ b/lib/src/res/strings/gr.dart @@ -247,4 +247,5 @@ Map gr = { "ZM": "Ζάμπια", "ZW": "Ζιμπάμπουε", "search": "Αναζήτηση", + "noCountryFound": "Δεν βρέθηκε χώρα.", }; diff --git a/lib/src/res/strings/he.dart b/lib/src/res/strings/he.dart index b83cf4ee..17fd31e0 100644 --- a/lib/src/res/strings/he.dart +++ b/lib/src/res/strings/he.dart @@ -247,4 +247,5 @@ Map he = { "ZM": "זמביה", "ZW": "זימבבואה", // "search": "Suchen", + "noCountryFound": "לא נמצאה מדינה.", }; diff --git a/lib/src/res/strings/hr.dart b/lib/src/res/strings/hr.dart index 994c1045..a4c0f950 100644 --- a/lib/src/res/strings/hr.dart +++ b/lib/src/res/strings/hr.dart @@ -247,4 +247,5 @@ Map hr = { "ZM": "Zambija", "ZW": "Zimbabve", "search": "Pretraži", + "noCountryFound": "Nije pronađena nijedna država.", }; diff --git a/lib/src/res/strings/ht.dart b/lib/src/res/strings/ht.dart index 561f199b..f9aa2810 100644 --- a/lib/src/res/strings/ht.dart +++ b/lib/src/res/strings/ht.dart @@ -247,4 +247,5 @@ Map ht = { "ZM": "Zanbi", "ZW": "Zimbabwe", "search": "Chèche", + "noCountryFound": "Pa gen peyi jwenn.", }; diff --git a/lib/src/res/strings/id.dart b/lib/src/res/strings/id.dart index c1179bbe..532d5e23 100644 --- a/lib/src/res/strings/id.dart +++ b/lib/src/res/strings/id.dart @@ -247,4 +247,5 @@ Map id = { "ZM": 'Zambia', "ZW": 'Zimbabwe', "search": 'Mencari', + "noCountryFound": "Tidak ada negara yang ditemukan.", }; diff --git a/lib/src/res/strings/it.dart b/lib/src/res/strings/it.dart index 17f64fbd..116047ef 100644 --- a/lib/src/res/strings/it.dart +++ b/lib/src/res/strings/it.dart @@ -247,4 +247,5 @@ Map it = { "ZM": "Zambia", "ZW": "Zimbabwe", "search": "Cerca", + "noCountryFound": "Nessun paese trovato.", }; diff --git a/lib/src/res/strings/ja.dart b/lib/src/res/strings/ja.dart index 929ebcbd..320e232e 100644 --- a/lib/src/res/strings/ja.dart +++ b/lib/src/res/strings/ja.dart @@ -247,4 +247,5 @@ Map ja = { "ZM": "ザンビア", "ZW": "ジンバブエ", "search": "検索", + "noCountryFound": "国が見つかりません。", }; diff --git a/lib/src/res/strings/ko.dart b/lib/src/res/strings/ko.dart index de20ae23..d5e6c383 100644 --- a/lib/src/res/strings/ko.dart +++ b/lib/src/res/strings/ko.dart @@ -247,4 +247,5 @@ Map ko = { "ZM": "잠비아", "ZW": "짐바브웨", "search": "검색", + "noCountryFound": "국가를 찾을 수 없습니다.", }; diff --git a/lib/src/res/strings/ku.dart b/lib/src/res/strings/ku.dart index 37542114..64b573ca 100644 --- a/lib/src/res/strings/ku.dart +++ b/lib/src/res/strings/ku.dart @@ -246,4 +246,5 @@ Map ku = { "ZM": "زامبیا", "ZW": "زیمبابوێ", "search": "گەڕان", + "noCountryFound": "هیچ وڵاتێک نەدۆزراوەتەوە.", }; diff --git a/lib/src/res/strings/lt.dart b/lib/src/res/strings/lt.dart index bc6eb9f5..93acfc52 100644 --- a/lib/src/res/strings/lt.dart +++ b/lib/src/res/strings/lt.dart @@ -247,4 +247,5 @@ Map lt = { "ZM": "Zambija", "ZW": "Zimbabvė", "search": "Paieška", + "noCountryFound": "Nessun paese trovato.", }; diff --git a/lib/src/res/strings/lv.dart b/lib/src/res/strings/lv.dart index 31f36b3d..b7cc2358 100644 --- a/lib/src/res/strings/lv.dart +++ b/lib/src/res/strings/lv.dart @@ -247,4 +247,5 @@ Map lv = { "ZM": "Zambija", "ZW": "Zimbabve", "search": "Meklēt", + "noCountryFound": "Nav atrasta neviena valsts.", }; diff --git a/lib/src/res/strings/nb.dart b/lib/src/res/strings/nb.dart index ece93b44..0450766d 100644 --- a/lib/src/res/strings/nb.dart +++ b/lib/src/res/strings/nb.dart @@ -247,4 +247,5 @@ Map nb = { "ZM": "Zambia", "ZW": "Zimbabwe", "search": "Søk", + "noCountryFound": "Ingen land funnet.", }; diff --git a/lib/src/res/strings/nl.dart b/lib/src/res/strings/nl.dart index 40e43d11..25c900a3 100644 --- a/lib/src/res/strings/nl.dart +++ b/lib/src/res/strings/nl.dart @@ -247,4 +247,5 @@ Map nl = { "ZM": "Zambia", "ZW": "Zimbabwe", "search": "Zoeken", + "noCountryFound": "Geen land gevonden.", }; diff --git a/lib/src/res/strings/nn.dart b/lib/src/res/strings/nn.dart index 484336bd..bc8aab45 100644 --- a/lib/src/res/strings/nn.dart +++ b/lib/src/res/strings/nn.dart @@ -247,4 +247,5 @@ Map nn = { "ZM": "Zambia", "ZW": "Zimbabwe", "search": "Søk", + "noCountryFound": "Inget land funne.", }; diff --git a/lib/src/res/strings/np.dart b/lib/src/res/strings/np.dart index 368bda7e..b94da286 100644 --- a/lib/src/res/strings/np.dart +++ b/lib/src/res/strings/np.dart @@ -247,4 +247,5 @@ Map np = { "ZM": "जाम्बिया", "ZW": "जिम्बावे", "search": "खोजें", + "noCountryFound": "कुनै देश भेटिएन।", }; diff --git a/lib/src/res/strings/pl.dart b/lib/src/res/strings/pl.dart index 4399906b..5ae4f048 100644 --- a/lib/src/res/strings/pl.dart +++ b/lib/src/res/strings/pl.dart @@ -247,4 +247,5 @@ Map pl = { "ZM": "Zambia", "ZW": "Zimbabwe", "search": "Szukaj", + "noCountryFound": "Nie znaleziono kraju.", }; diff --git a/lib/src/res/strings/pt.dart b/lib/src/res/strings/pt.dart index fd6bf412..8f166e04 100644 --- a/lib/src/res/strings/pt.dart +++ b/lib/src/res/strings/pt.dart @@ -247,4 +247,5 @@ Map pt = { "ZM": "Zâmbia", "ZW": "Zimbábue", "search": "Procurar", + "noCountryFound": "Nenhum país encontrado.", }; diff --git a/lib/src/res/strings/ro.dart b/lib/src/res/strings/ro.dart index a9948846..e0b9ac3f 100644 --- a/lib/src/res/strings/ro.dart +++ b/lib/src/res/strings/ro.dart @@ -247,4 +247,5 @@ Map ro = { "ZM": "Zambia", "ZW": "Zimbabwe", "search": "Căutare", + "noCountryFound": "Nu a fost găsită nicio țară.", }; diff --git a/lib/src/res/strings/ru.dart b/lib/src/res/strings/ru.dart index ef305027..3ec4e072 100644 --- a/lib/src/res/strings/ru.dart +++ b/lib/src/res/strings/ru.dart @@ -247,4 +247,5 @@ Map ru = { "ZM": "Замбия", "ZW": "Зимбабве", "search": "Поиск", + "noCountryFound": "Страна не найдена.", }; diff --git a/lib/src/res/strings/sk.dart b/lib/src/res/strings/sk.dart index 7c1e645c..13f3ac8d 100644 --- a/lib/src/res/strings/sk.dart +++ b/lib/src/res/strings/sk.dart @@ -247,4 +247,5 @@ Map sk = { "ZM": "Zambia", "ZW": "Zimbabwe", "search": "Hľadať", + "noCountryFound": "Nenašla sa žiadna krajina.", }; diff --git a/lib/src/res/strings/tr.dart b/lib/src/res/strings/tr.dart index b4376e36..6d9df269 100644 --- a/lib/src/res/strings/tr.dart +++ b/lib/src/res/strings/tr.dart @@ -247,4 +247,5 @@ Map tr = { "ZM": "Zambiya", "ZW": "Zimbabve", "search": "Arama", + "noCountryFound": "Ülke bulunamadı.", }; diff --git a/lib/src/res/strings/tw.dart b/lib/src/res/strings/tw.dart index 18e06739..5b27c705 100644 --- a/lib/src/res/strings/tw.dart +++ b/lib/src/res/strings/tw.dart @@ -247,4 +247,5 @@ Map tw = { "ZM": "尚比亞", "ZW": "辛巴威", "search": "搜索", + "noCountryFound": "找不到國家。", }; diff --git a/lib/src/res/strings/uk.dart b/lib/src/res/strings/uk.dart index bbc2dc21..81296565 100644 --- a/lib/src/res/strings/uk.dart +++ b/lib/src/res/strings/uk.dart @@ -247,4 +247,5 @@ Map uk = { "ZM": "Замбія", "ZW": "Зімбабве", "search": "Шукати", + "noCountryFound": "Країна не знайдена.", }; diff --git a/pubspec.lock b/pubspec.lock index a9b0d4d6..65be8fc8 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -37,10 +37,10 @@ packages: dependency: "direct main" description: name: collection - sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + sha256: a1ace0a119f20aabc852d165077c036cd864315bd99b7eaa10a60100341941bf url: "https://pub.dev" source: hosted - version: "1.18.0" + version: "1.19.0" fake_async: dependency: transitive description: @@ -63,18 +63,18 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" + sha256: "7bb2830ebd849694d1ec25bf1f44582d6ac531a57a365a803a6034ff751d2d06" url: "https://pub.dev" source: hosted - version: "10.0.5" + version: "10.0.7" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" + sha256: "9491a714cca3667b60b5c420da8217e6de0d1ba7a5ec322fab01758f6998f379" url: "https://pub.dev" source: hosted - version: "3.0.5" + version: "3.0.8" leak_tracker_testing: dependency: transitive description: @@ -127,7 +127,7 @@ packages: dependency: transitive description: flutter source: sdk - version: "0.0.99" + version: "0.0.0" source_span: dependency: transitive description: @@ -140,10 +140,10 @@ packages: dependency: transitive description: name: stack_trace - sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + sha256: "9f47fd3630d76be3ab26f0ee06d213679aa425996925ff3feffdec504931c377" url: "https://pub.dev" source: hosted - version: "1.11.1" + version: "1.12.0" stream_channel: dependency: transitive description: @@ -156,10 +156,10 @@ packages: dependency: transitive description: name: string_scanner - sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + sha256: "688af5ed3402a4bde5b3a6c15fd768dbf2621a614950b17f04626c431ab3c4c3" url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.3.0" term_glyph: dependency: transitive description: @@ -172,10 +172,10 @@ packages: dependency: transitive description: name: test_api - sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" + sha256: "664d3a9a64782fcdeb83ce9c6b39e78fd2971d4e37827b9b06c3aa1edc5e760c" url: "https://pub.dev" source: hosted - version: "0.7.2" + version: "0.7.3" typed_data: dependency: transitive description: @@ -204,10 +204,10 @@ packages: dependency: transitive description: name: vm_service - sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" + sha256: f6be3ed8bd01289b34d679c2b62226f63c0e69f9fd2e50a6b3c1c729a961041b url: "https://pub.dev" source: hosted - version: "14.2.5" + version: "14.3.0" sdks: - dart: ">=3.3.0 <4.0.0" + dart: ">=3.4.0 <4.0.0" flutter: ">=3.18.0-18.0.pre.54"