refs #60: expose state to let use a key to open the dialog

This commit is contained in:
Salvatore Giordano
2020-04-04 16:25:19 +02:00
parent bb7d3c75c8
commit c74dcf43ca
2 changed files with 9 additions and 12 deletions

View File

@@ -11,11 +11,6 @@ class MyApp extends StatefulWidget {
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return new MaterialApp(
@@ -38,6 +33,7 @@ class _MyAppState extends State<MyApp> {
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
CountryCodePicker(
key: key,
onChanged: print,
// Initial selection and favorite can be one of code ('IT') OR dial_code('+39')
initialSelection: 'IT',

View File

@@ -78,7 +78,8 @@ class CountryCodePicker extends StatefulWidget {
this.comparator,
this.customList,
this.dialogSize,
});
Key key,
}) : super(key: key);
@override
State<StatefulWidget> createState() {
@@ -104,29 +105,29 @@ class CountryCodePicker extends StatefulWidget {
elements = elements.where((c) => countryFilter.contains(c.code)).toList();
}
return _CountryCodePickerState(elements);
return CountryCodePickerState(elements);
}
}
class _CountryCodePickerState extends State<CountryCodePicker> {
class CountryCodePickerState extends State<CountryCodePicker> {
CountryCode selectedItem;
List<CountryCode> elements = [];
List<CountryCode> favoriteElements = [];
_CountryCodePickerState(this.elements);
CountryCodePickerState(this.elements);
@override
Widget build(BuildContext context) {
Widget _widget;
if (widget.builder != null)
_widget = InkWell(
onTap: _showSelectionDialog,
onTap: showCountryCodePickerDialog,
child: widget.builder(selectedItem.localize(context)),
);
else {
_widget = FlatButton(
padding: widget.padding,
onPressed: widget.enabled ? _showSelectionDialog : null,
onPressed: widget.enabled ? showCountryCodePickerDialog : null,
child: Flex(
direction: Axis.horizontal,
mainAxisSize: MainAxisSize.min,
@@ -205,7 +206,7 @@ class _CountryCodePickerState extends State<CountryCodePicker> {
super.initState();
}
void _showSelectionDialog() {
void showCountryCodePickerDialog() {
showDialog(
context: context,
builder: (_) => SelectionDialog(