enable custom view widgets;
This commit is contained in:
@@ -17,6 +17,7 @@ class CountryCodePicker extends StatefulWidget {
|
|||||||
final InputDecoration searchDecoration;
|
final InputDecoration searchDecoration;
|
||||||
final TextStyle searchStyle;
|
final TextStyle searchStyle;
|
||||||
final WidgetBuilder emptySearchBuilder;
|
final WidgetBuilder emptySearchBuilder;
|
||||||
|
final Widget customWidget;
|
||||||
|
|
||||||
/// shows the name of the country instead of the dialcode
|
/// shows the name of the country instead of the dialcode
|
||||||
final bool showOnlyCountryWhenClosed;
|
final bool showOnlyCountryWhenClosed;
|
||||||
@@ -43,7 +44,8 @@ class CountryCodePicker extends StatefulWidget {
|
|||||||
this.emptySearchBuilder,
|
this.emptySearchBuilder,
|
||||||
this.showOnlyCountryWhenClosed = false,
|
this.showOnlyCountryWhenClosed = false,
|
||||||
this.alignLeft = false,
|
this.alignLeft = false,
|
||||||
this.showFlag = true
|
this.showFlag = true,
|
||||||
|
this.customWidget,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -71,39 +73,49 @@ class _CountryCodePickerState extends State<CountryCodePicker> {
|
|||||||
_CountryCodePickerState(this.elements);
|
_CountryCodePickerState(this.elements);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => FlatButton(
|
Widget build(BuildContext context) {
|
||||||
child: Flex(
|
Widget _widget;
|
||||||
direction: Axis.horizontal,
|
if (widget.customWidget != null)
|
||||||
mainAxisSize: MainAxisSize.min,
|
_widget = widget.customWidget;
|
||||||
children: <Widget>[
|
else {
|
||||||
widget.showFlag ? Flexible(
|
_widget = Flex(
|
||||||
flex: widget.alignLeft ? 0 : 1,
|
direction: Axis.horizontal,
|
||||||
fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose,
|
mainAxisSize: MainAxisSize.min,
|
||||||
child: Padding(
|
children: <Widget>[
|
||||||
padding: widget.alignLeft
|
widget.showFlag
|
||||||
? const EdgeInsets.only(right: 16.0, left: 8.0)
|
? Flexible(
|
||||||
: const EdgeInsets.only(right: 16.0),
|
flex: widget.alignLeft ? 0 : 1,
|
||||||
child: Image.asset(
|
fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose,
|
||||||
selectedItem.flagUri,
|
child: Padding(
|
||||||
package: 'country_code_picker',
|
padding: widget.alignLeft
|
||||||
width: 32.0,
|
? const EdgeInsets.only(right: 16.0, left: 8.0)
|
||||||
),
|
: const EdgeInsets.only(right: 16.0),
|
||||||
),
|
child: Image.asset(
|
||||||
) : Container(),
|
selectedItem.flagUri,
|
||||||
Flexible(
|
package: 'country_code_picker',
|
||||||
fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose,
|
width: 32.0,
|
||||||
child: Text(
|
),
|
||||||
widget.showOnlyCountryWhenClosed
|
),
|
||||||
? selectedItem.toCountryStringOnly()
|
)
|
||||||
: selectedItem.toString(),
|
: Container(),
|
||||||
style: widget.textStyle ?? Theme.of(context).textTheme.button,
|
Flexible(
|
||||||
),
|
fit: widget.alignLeft ? FlexFit.tight : FlexFit.loose,
|
||||||
|
child: Text(
|
||||||
|
widget.showOnlyCountryWhenClosed
|
||||||
|
? selectedItem.toCountryStringOnly()
|
||||||
|
: selectedItem.toString(),
|
||||||
|
style: widget.textStyle ?? Theme.of(context).textTheme.button,
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
],
|
||||||
padding: widget.padding,
|
|
||||||
onPressed: _showSelectionDialog,
|
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
return FlatButton(
|
||||||
|
child: _widget,
|
||||||
|
padding: widget.padding,
|
||||||
|
onPressed: _showSelectionDialog,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
initState() {
|
initState() {
|
||||||
@@ -130,16 +142,12 @@ class _CountryCodePickerState extends State<CountryCodePicker> {
|
|||||||
void _showSelectionDialog() {
|
void _showSelectionDialog() {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (_) =>
|
builder: (_) => SelectionDialog(elements, favoriteElements,
|
||||||
SelectionDialog(
|
|
||||||
elements,
|
|
||||||
favoriteElements,
|
|
||||||
showCountryOnly: widget.showCountryOnly,
|
showCountryOnly: widget.showCountryOnly,
|
||||||
emptySearchBuilder: widget.emptySearchBuilder,
|
emptySearchBuilder: widget.emptySearchBuilder,
|
||||||
searchDecoration: widget.searchDecoration,
|
searchDecoration: widget.searchDecoration,
|
||||||
searchStyle: widget.searchStyle,
|
searchStyle: widget.searchStyle,
|
||||||
showFlag: widget.showFlag
|
showFlag: widget.showFlag),
|
||||||
),
|
|
||||||
).then((e) {
|
).then((e) {
|
||||||
if (e != null) {
|
if (e != null) {
|
||||||
setState(() {
|
setState(() {
|
||||||
|
|||||||
Reference in New Issue
Block a user