From 12edc3ff90302de9d0fd6026bf90be1d7326d682 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Sun, 5 Apr 2020 11:56:06 +0200 Subject: [PATCH] refs #63: add hideSearch property --- example/lib/main.dart | 1 + lib/country_code_picker.dart | 7 ++++++- lib/selection_dialog.dart | 17 ++++++++++------- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index fe90dc3..5bf6834 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -52,6 +52,7 @@ class _MyAppState extends State { child: CountryCodePicker( onChanged: print, initialSelection: 'TF', + hideSearch: true, showCountryOnly: true, showOnlyCountryWhenClosed: true, alignLeft: true, diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index 42cd306..9a2eb54 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -51,6 +51,9 @@ class CountryCodePicker extends StatefulWidget { /// Use this property to change the order of the options final Comparator comparator; + /// Set to true if you want to hide the search part + final bool hideSearch; + CountryCodePicker({ this.onChanged, this.onInit, @@ -73,6 +76,7 @@ class CountryCodePicker extends StatefulWidget { this.textOverflow = TextOverflow.ellipsis, this.comparator, this.countryFilter, + this.hideSearch = false, this.dialogSize, Key key, }) : super(key: key); @@ -181,6 +185,7 @@ class CountryCodePickerState extends State { @override void initState() { + super.initState(); if (widget.initialSelection != null) { selectedItem = elements.firstWhere( (e) => @@ -198,7 +203,6 @@ class CountryCodePickerState extends State { orElse: () => null) != null) .toList(); - super.initState(); } void showCountryCodePickerDialog() { @@ -214,6 +218,7 @@ class CountryCodePickerState extends State { showFlag: widget.showFlag || (widget.showFlagDialog == true), flagWidth: widget.flagWidth, size: widget.dialogSize, + hideSearch: widget.hideSearch, ), ).then((e) { if (e != null) { diff --git a/lib/selection_dialog.dart b/lib/selection_dialog.dart index 15d0a65..60e429e 100644 --- a/lib/selection_dialog.dart +++ b/lib/selection_dialog.dart @@ -11,6 +11,7 @@ class SelectionDialog extends StatefulWidget { final bool showFlag; final double flagWidth; final Size size; + final bool hideSearch; /// elements passed as favorite final List favoriteElements; @@ -26,6 +27,7 @@ class SelectionDialog extends StatefulWidget { this.showFlag, this.flagWidth = 32, this.size, + this.hideSearch = false, }) : assert(searchDecoration != null, 'searchDecoration must not be null!'), this.searchDecoration = searchDecoration.copyWith(prefixIcon: Icon(Icons.search)), @@ -54,14 +56,15 @@ class _SelectionDialogState extends State { ), onPressed: () => Navigator.pop(context), ), - Padding( - padding: const EdgeInsets.symmetric(horizontal: 24), - child: TextField( - style: widget.searchStyle, - decoration: widget.searchDecoration, - onChanged: _filterElements, + if (!widget.hideSearch) + Padding( + padding: const EdgeInsets.symmetric(horizontal: 24), + child: TextField( + style: widget.searchStyle, + decoration: widget.searchDecoration, + onChanged: _filterElements, + ), ), - ), ], ), children: [