Add custom search InputDecoration to SelectionDialog

This commit is contained in:
Andrew Fulton
2019-04-01 22:03:06 -05:00
parent 7cec16c29d
commit b47fa559ab
2 changed files with 10 additions and 3 deletions

View File

@@ -14,6 +14,7 @@ class CountryCodePicker extends StatefulWidget {
final TextStyle textStyle; final TextStyle textStyle;
final EdgeInsetsGeometry padding; final EdgeInsetsGeometry padding;
final bool showCountryOnly; final bool showCountryOnly;
final InputDecoration searchDecoration;
CountryCodePicker({ CountryCodePicker({
this.onChanged, this.onChanged,
@@ -22,6 +23,7 @@ class CountryCodePicker extends StatefulWidget {
this.textStyle, this.textStyle,
this.padding = const EdgeInsets.all(0.0), this.padding = const EdgeInsets.all(0.0),
this.showCountryOnly = false, this.showCountryOnly = false,
this.searchDecoration,
}); });
@override @override
@@ -108,7 +110,8 @@ class _CountryCodePickerState extends State<CountryCodePicker> {
showDialog( showDialog(
context: context, context: context,
builder: (_) => new SelectionDialog(elements, favoriteElements, builder: (_) => new SelectionDialog(elements, favoriteElements,
showCountryOnly: widget.showCountryOnly), showCountryOnly: widget.showCountryOnly,
searchDecoration: widget.searchDecoration,),
).then((e) { ).then((e) {
if (e != null) { if (e != null) {
setState(() { setState(() {

View File

@@ -5,11 +5,15 @@ import 'package:flutter/material.dart';
class SelectionDialog extends StatefulWidget { class SelectionDialog extends StatefulWidget {
final List<CountryCode> elements; final List<CountryCode> elements;
final bool showCountryOnly; final bool showCountryOnly;
final InputDecoration searchDecoration;
/// elements passed as favorite /// elements passed as favorite
final List<CountryCode> favoriteElements; final List<CountryCode> 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 @override
State<StatefulWidget> createState() => new _SelectionDialogState(); State<StatefulWidget> createState() => new _SelectionDialogState();
@@ -24,7 +28,7 @@ class _SelectionDialogState extends State<SelectionDialog> {
title: new Column( title: new Column(
children: <Widget>[ children: <Widget>[
new TextField( new TextField(
decoration: new InputDecoration(prefixIcon: new Icon(Icons.search)), decoration: widget.searchDecoration,
onChanged: _filterElements, onChanged: _filterElements,
), ),
], ],