Skip to content

Add empty placeholder when no country was found #181

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions lib/country_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ void showCountryPicker({
List<String>? countryFilter,
bool showPhoneCode = false,
CustomFlagBuilder? customFlagBuilder,
WidgetBuilder? emptySearchPlaceholderBuilder,
CountryListThemeData? countryListTheme,
bool searchAutofocus = false,
bool showWorldWide = false,
Expand Down Expand Up @@ -87,5 +88,6 @@ void showCountryPicker({
useSafeArea: useSafeArea,
useRootNavigator: useRootNavigator,
moveAlongWithKeyboard: moveAlongWithKeyboard,
emptySearchPlaceholderBuilder: emptySearchPlaceholderBuilder,
);
}
4 changes: 4 additions & 0 deletions lib/src/country_list_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ void showCountryListBottomSheet({
List<String>? countryFilter,
bool showPhoneCode = false,
CustomFlagBuilder? customFlagBuilder,
WidgetBuilder? emptySearchPlaceholderBuilder,
CountryListThemeData? countryListTheme,
bool searchAutofocus = false,
bool showWorldWide = false,
Expand Down Expand Up @@ -40,6 +41,7 @@ void showCountryListBottomSheet({
showSearch,
moveAlongWithKeyboard,
customFlagBuilder,
emptySearchPlaceholderBuilder,
),
).whenComplete(() {
if (onClosed != null) onClosed();
Expand All @@ -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;
Expand Down Expand Up @@ -103,6 +106,7 @@ Widget _builder(
showWorldWide: showWorldWide,
showSearch: showSearch,
customFlagBuilder: customFlagBuilder,
emptySearchPlaceholderBuilder: emptySearchPlaceholderBuilder,
),
),
);
Expand Down
23 changes: 23 additions & 0 deletions lib/src/country_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand Down Expand Up @@ -166,13 +170,32 @@ class _CountryListViewState extends State<CountryListView> {
..._filteredList
.map<Widget>((country) => _listRow(country))
.toList(),
if(_filteredList.isEmpty)
widget.emptySearchPlaceholderBuilder?.call(context) ?? _defaultEmptySearchPlaceholder(context)
],
),
),
],
);
}

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;
Expand Down
1 change: 1 addition & 0 deletions lib/src/res/strings/ar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> ar = {
"ZM": "زامبيا",
"ZW": "زيمبابوي",
"search": "بحث",
"noCountryFound": "لم يتم العثور على أي بلد.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/bg.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> bg = {
"ZM": "Замбия",
"ZW": "Зимбабве",
"search": "Търсене",
"noCountryFound": "Няма намерена държава.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/ca.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> ca = {
"ZM": "Zàmbia",
"ZW": "Zimbabwe",
"search": "Cerca",
"noCountryFound": "No s'ha trobat cap país.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/cn.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> cn = {
"ZM": "赞比亚",
"ZW": "津巴布韦",
"search": "查询",
"noCountryFound": "未找到任何国家。",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/cs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> cs = {
"ZM": "Zambie",
"ZW": "Zimbabwe",
"search": "Hledat",
"noCountryFound": "Nebyla nalezena žádná země.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/da.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> da = {
"ZM": "Zambia",
"ZW": "Zimbabwe",
"search": "Søg",
"noCountryFound": "Intet land fundet.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/de.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> de = {
"ZM": "Sambia",
"ZW": "Simbabwe",
"search": "Suchen",
"noCountryFound": "Kein Land gefunden.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> en = {
"ZM": "Zambia",
"ZW": "Zimbabwe",
"search": "Search",
"noCountryFound": "No country found.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/es.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> es = {
"ZM": "Zambia",
"ZW": "Zimbabue",
"search": "Buscar",
"noCountryFound": "No se encontró ningún país.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/et.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> et = {
"WW": "Kogu Maailmas",
"ZW": "Zimbabwe",
"search": "Otsi",
"noCountryFound": "Ühtegi riiki ei leitud.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/fa.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> fa = {
"ZM": "زامبیا",
"ZW": "زیمبابوه",
"search": "جستجو",
"noCountryFound": "کشوری پیدا نشد",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/fr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,5 @@ Map<String, String> fr = {
"ZM": "Zambie",
"ZW": "Zimbabwe",
"search": "Chercher",
"noCountryFound": "Aucun pays trouvé.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/gr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> gr = {
"ZM": "Ζάμπια",
"ZW": "Ζιμπάμπουε",
"search": "Αναζήτηση",
"noCountryFound": "Δεν βρέθηκε χώρα.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/he.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> he = {
"ZM": "זמביה",
"ZW": "זימבבואה",
// "search": "Suchen",
"noCountryFound": "לא נמצאה מדינה.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/hr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> hr = {
"ZM": "Zambija",
"ZW": "Zimbabve",
"search": "Pretraži",
"noCountryFound": "Nije pronađena nijedna država.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/ht.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> ht = {
"ZM": "Zanbi",
"ZW": "Zimbabwe",
"search": "Chèche",
"noCountryFound": "Pa gen peyi jwenn.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> id = {
"ZM": 'Zambia',
"ZW": 'Zimbabwe',
"search": 'Mencari',
"noCountryFound": "Tidak ada negara yang ditemukan.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/it.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> it = {
"ZM": "Zambia",
"ZW": "Zimbabwe",
"search": "Cerca",
"noCountryFound": "Nessun paese trovato.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/ja.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> ja = {
"ZM": "ザンビア",
"ZW": "ジンバブエ",
"search": "検索",
"noCountryFound": "国が見つかりません。",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/ko.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> ko = {
"ZM": "잠비아",
"ZW": "짐바브웨",
"search": "검색",
"noCountryFound": "국가를 찾을 수 없습니다.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/ku.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,5 @@ Map<String, String> ku = {
"ZM": "زامبیا",
"ZW": "زیمبابوێ",
"search": "گەڕان",
"noCountryFound": "هیچ وڵاتێک نەدۆزراوەتەوە.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/lt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> lt = {
"ZM": "Zambija",
"ZW": "Zimbabvė",
"search": "Paieška",
"noCountryFound": "Nessun paese trovato.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/lv.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> lv = {
"ZM": "Zambija",
"ZW": "Zimbabve",
"search": "Meklēt",
"noCountryFound": "Nav atrasta neviena valsts.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/nb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> nb = {
"ZM": "Zambia",
"ZW": "Zimbabwe",
"search": "Søk",
"noCountryFound": "Ingen land funnet.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/nl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> nl = {
"ZM": "Zambia",
"ZW": "Zimbabwe",
"search": "Zoeken",
"noCountryFound": "Geen land gevonden.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/nn.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> nn = {
"ZM": "Zambia",
"ZW": "Zimbabwe",
"search": "Søk",
"noCountryFound": "Inget land funne.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/np.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> np = {
"ZM": "जाम्बिया",
"ZW": "जिम्बावे",
"search": "खोजें",
"noCountryFound": "कुनै देश भेटिएन।",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/pl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> pl = {
"ZM": "Zambia",
"ZW": "Zimbabwe",
"search": "Szukaj",
"noCountryFound": "Nie znaleziono kraju.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/pt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> pt = {
"ZM": "Zâmbia",
"ZW": "Zimbábue",
"search": "Procurar",
"noCountryFound": "Nenhum país encontrado.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/ro.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> ro = {
"ZM": "Zambia",
"ZW": "Zimbabwe",
"search": "Căutare",
"noCountryFound": "Nu a fost găsită nicio țară.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/ru.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> ru = {
"ZM": "Замбия",
"ZW": "Зимбабве",
"search": "Поиск",
"noCountryFound": "Страна не найдена.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/sk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> sk = {
"ZM": "Zambia",
"ZW": "Zimbabwe",
"search": "Hľadať",
"noCountryFound": "Nenašla sa žiadna krajina.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/tr.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> tr = {
"ZM": "Zambiya",
"ZW": "Zimbabve",
"search": "Arama",
"noCountryFound": "Ülke bulunamadı.",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/tw.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> tw = {
"ZM": "尚比亞",
"ZW": "辛巴威",
"search": "搜索",
"noCountryFound": "找不到國家。",
};
1 change: 1 addition & 0 deletions lib/src/res/strings/uk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,5 @@ Map<String, String> uk = {
"ZM": "Замбія",
"ZW": "Зімбабве",
"search": "Шукати",
"noCountryFound": "Країна не знайдена.",
};
Loading