From b47fa559ab6a068c97f840e47f2fb579b0ee3256 Mon Sep 17 00:00:00 2001 From: Andrew Fulton Date: Mon, 1 Apr 2019 22:03:06 -0500 Subject: [PATCH 1/3] Add custom search InputDecoration to SelectionDialog --- lib/country_code_picker.dart | 5 ++++- lib/selection_dialog.dart | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index 9b02493..fa9d6c5 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -14,6 +14,7 @@ class CountryCodePicker extends StatefulWidget { final TextStyle textStyle; final EdgeInsetsGeometry padding; final bool showCountryOnly; + final InputDecoration searchDecoration; CountryCodePicker({ this.onChanged, @@ -22,6 +23,7 @@ class CountryCodePicker extends StatefulWidget { this.textStyle, this.padding = const EdgeInsets.all(0.0), this.showCountryOnly = false, + this.searchDecoration, }); @override @@ -108,7 +110,8 @@ class _CountryCodePickerState extends State { showDialog( context: context, builder: (_) => new SelectionDialog(elements, favoriteElements, - showCountryOnly: widget.showCountryOnly), + showCountryOnly: widget.showCountryOnly, + searchDecoration: widget.searchDecoration,), ).then((e) { if (e != null) { setState(() { diff --git a/lib/selection_dialog.dart b/lib/selection_dialog.dart index c5da25b..feceafd 100644 --- a/lib/selection_dialog.dart +++ b/lib/selection_dialog.dart @@ -5,11 +5,15 @@ import 'package:flutter/material.dart'; class SelectionDialog extends StatefulWidget { final List elements; final bool showCountryOnly; + final InputDecoration searchDecoration; /// elements passed as favorite final List favoriteElements; - SelectionDialog(this.elements, this.favoriteElements, {this.showCountryOnly}); + SelectionDialog(this.elements, this.favoriteElements, { + this.showCountryOnly, + InputDecoration searchDecoration = const InputDecoration(), + }) : this.searchDecoration = searchDecoration.copyWith(prefixIcon: Icon(Icons.search)); @override State createState() => new _SelectionDialogState(); @@ -24,7 +28,7 @@ class _SelectionDialogState extends State { title: new Column( children: [ new TextField( - decoration: new InputDecoration(prefixIcon: new Icon(Icons.search)), + decoration: widget.searchDecoration, onChanged: _filterElements, ), ], From b3dff1e3d95c6572017ed7b219ed0cd7f47aadda Mon Sep 17 00:00:00 2001 From: Andrew Fulton Date: Mon, 1 Apr 2019 22:28:31 -0500 Subject: [PATCH 2/3] Add search TextStyle property --- lib/country_code_picker.dart | 3 +++ lib/selection_dialog.dart | 3 +++ 2 files changed, 6 insertions(+) diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index e62cdbb..f395ec5 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -15,6 +15,7 @@ class CountryCodePicker extends StatefulWidget { final EdgeInsetsGeometry padding; final bool showCountryOnly; final InputDecoration searchDecoration; + final TextStyle searchStyle; final WidgetBuilder emptySearchBuilder; CountryCodePicker({ @@ -25,6 +26,7 @@ class CountryCodePicker extends StatefulWidget { this.padding = const EdgeInsets.all(0.0), this.showCountryOnly = false, this.searchDecoration, + this.searchStyle, this.emptySearchBuilder, }); @@ -118,6 +120,7 @@ class _CountryCodePickerState extends State { showCountryOnly: widget.showCountryOnly, emptySearchBuilder: widget.emptySearchBuilder, searchDecoration: widget.searchDecoration, + searchStyle: widget.searchStyle, ), ).then((e) { if (e != null) { diff --git a/lib/selection_dialog.dart b/lib/selection_dialog.dart index a786f80..19513cb 100644 --- a/lib/selection_dialog.dart +++ b/lib/selection_dialog.dart @@ -6,6 +6,7 @@ class SelectionDialog extends StatefulWidget { final List elements; final bool showCountryOnly; final InputDecoration searchDecoration; + final TextStyle searchStyle; final WidgetBuilder emptySearchBuilder; /// elements passed as favorite @@ -16,6 +17,7 @@ class SelectionDialog extends StatefulWidget { this.showCountryOnly, this.emptySearchBuilder, InputDecoration searchDecoration = const InputDecoration(), + this.searchStyle, }) : this.searchDecoration = searchDecoration.copyWith(prefixIcon: Icon(Icons.search)), super(key: key); @@ -33,6 +35,7 @@ class _SelectionDialogState extends State { title: Column( children: [ TextField( + style: widget.searchStyle, decoration: widget.searchDecoration, onChanged: _filterElements, ), From 0ad5e79ea2faa03bd0faba38b5e7a4b29267911d Mon Sep 17 00:00:00 2001 From: Andrew Fulton Date: Mon, 1 Apr 2019 22:44:12 -0500 Subject: [PATCH 3/3] [Fix] searchDecoration parameter was null --- lib/country_code_picker.dart | 2 +- lib/selection_dialog.dart | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index f395ec5..3727b61 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -25,7 +25,7 @@ class CountryCodePicker extends StatefulWidget { this.textStyle, this.padding = const EdgeInsets.all(0.0), this.showCountryOnly = false, - this.searchDecoration, + this.searchDecoration = const InputDecoration(), this.searchStyle, this.emptySearchBuilder, }); diff --git a/lib/selection_dialog.dart b/lib/selection_dialog.dart index 19513cb..0f38ecf 100644 --- a/lib/selection_dialog.dart +++ b/lib/selection_dialog.dart @@ -19,6 +19,7 @@ class SelectionDialog extends StatefulWidget { InputDecoration searchDecoration = const InputDecoration(), this.searchStyle, }) : + assert(searchDecoration != null, 'searchDecoration must not be null!'), this.searchDecoration = searchDecoration.copyWith(prefixIcon: Icon(Icons.search)), super(key: key);