refs #63: add hideSearch property

This commit is contained in:
Salvatore Giordano
2020-04-05 11:56:06 +02:00
parent 8e6e9a3f62
commit 12edc3ff90
3 changed files with 17 additions and 8 deletions

View File

@@ -52,6 +52,7 @@ class _MyAppState extends State<MyApp> {
child: CountryCodePicker( child: CountryCodePicker(
onChanged: print, onChanged: print,
initialSelection: 'TF', initialSelection: 'TF',
hideSearch: true,
showCountryOnly: true, showCountryOnly: true,
showOnlyCountryWhenClosed: true, showOnlyCountryWhenClosed: true,
alignLeft: true, alignLeft: true,

View File

@@ -51,6 +51,9 @@ class CountryCodePicker extends StatefulWidget {
/// Use this property to change the order of the options /// Use this property to change the order of the options
final Comparator<CountryCode> comparator; final Comparator<CountryCode> comparator;
/// Set to true if you want to hide the search part
final bool hideSearch;
CountryCodePicker({ CountryCodePicker({
this.onChanged, this.onChanged,
this.onInit, this.onInit,
@@ -73,6 +76,7 @@ class CountryCodePicker extends StatefulWidget {
this.textOverflow = TextOverflow.ellipsis, this.textOverflow = TextOverflow.ellipsis,
this.comparator, this.comparator,
this.countryFilter, this.countryFilter,
this.hideSearch = false,
this.dialogSize, this.dialogSize,
Key key, Key key,
}) : super(key: key); }) : super(key: key);
@@ -181,6 +185,7 @@ class CountryCodePickerState extends State<CountryCodePicker> {
@override @override
void initState() { void initState() {
super.initState();
if (widget.initialSelection != null) { if (widget.initialSelection != null) {
selectedItem = elements.firstWhere( selectedItem = elements.firstWhere(
(e) => (e) =>
@@ -198,7 +203,6 @@ class CountryCodePickerState extends State<CountryCodePicker> {
orElse: () => null) != orElse: () => null) !=
null) null)
.toList(); .toList();
super.initState();
} }
void showCountryCodePickerDialog() { void showCountryCodePickerDialog() {
@@ -214,6 +218,7 @@ class CountryCodePickerState extends State<CountryCodePicker> {
showFlag: widget.showFlag || (widget.showFlagDialog == true), showFlag: widget.showFlag || (widget.showFlagDialog == true),
flagWidth: widget.flagWidth, flagWidth: widget.flagWidth,
size: widget.dialogSize, size: widget.dialogSize,
hideSearch: widget.hideSearch,
), ),
).then((e) { ).then((e) {
if (e != null) { if (e != null) {

View File

@@ -11,6 +11,7 @@ class SelectionDialog extends StatefulWidget {
final bool showFlag; final bool showFlag;
final double flagWidth; final double flagWidth;
final Size size; final Size size;
final bool hideSearch;
/// elements passed as favorite /// elements passed as favorite
final List<CountryCode> favoriteElements; final List<CountryCode> favoriteElements;
@@ -26,6 +27,7 @@ class SelectionDialog extends StatefulWidget {
this.showFlag, this.showFlag,
this.flagWidth = 32, this.flagWidth = 32,
this.size, this.size,
this.hideSearch = false,
}) : assert(searchDecoration != null, 'searchDecoration must not be null!'), }) : assert(searchDecoration != null, 'searchDecoration must not be null!'),
this.searchDecoration = this.searchDecoration =
searchDecoration.copyWith(prefixIcon: Icon(Icons.search)), searchDecoration.copyWith(prefixIcon: Icon(Icons.search)),
@@ -54,14 +56,15 @@ class _SelectionDialogState extends State<SelectionDialog> {
), ),
onPressed: () => Navigator.pop(context), onPressed: () => Navigator.pop(context),
), ),
Padding( if (!widget.hideSearch)
padding: const EdgeInsets.symmetric(horizontal: 24), Padding(
child: TextField( padding: const EdgeInsets.symmetric(horizontal: 24),
style: widget.searchStyle, child: TextField(
decoration: widget.searchDecoration, style: widget.searchStyle,
onChanged: _filterElements, decoration: widget.searchDecoration,
onChanged: _filterElements,
),
), ),
),
], ],
), ),
children: [ children: [