From d4e11edc4e5567f4c07b86cd81c946c9eb365ebe Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Fri, 23 Mar 2018 17:55:58 +0100 Subject: [PATCH] fix showing the flags --- lib/country_code_picker.dart | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/lib/country_code_picker.dart b/lib/country_code_picker.dart index 1b8153f..135fa59 100644 --- a/lib/country_code_picker.dart +++ b/lib/country_code_picker.dart @@ -35,25 +35,28 @@ class CountryCodePicker extends StatefulWidget { class _CountryCodePickerState extends State { List<_CElement> elements = []; - String selectedItem; + _CElement _selectedItem; _CountryCodePickerState(this.elements); @override - Widget build(BuildContext context) { - return new DropdownButton( - items: elements.map((e) => - new DropdownMenuItem( - key: new Key(e.code), - value: e.dial_code, - child: new Text("${e.flag} ${e.dial_code}"), - )).toList(), - onChanged: (v) { - setState(() { - selectedItem = v; - }); - }); - } - + Widget build(BuildContext context) => + new Container( + height: 40.0, + width: 100.0, + child: new DropdownButton<_CElement>( + value: _selectedItem ?? elements[0], + items: elements.map((e) => + new DropdownMenuItem<_CElement>( + key: new Key(e.code), + value: e, + child: new Text("${e.flag} ${e.name} ${e.dial_code}"), + )).toList(), + onChanged: (v) { + setState(() { + _selectedItem = v; + }); + }), + ); }