Changed CElement with CountryCode and fix error on favorite null

This commit is contained in:
Salvatore Giordano
2018-11-23 00:51:01 +01:00
parent 7006dab8ef
commit a9b91ba851
6 changed files with 97 additions and 79 deletions

View File

@@ -1,12 +1,12 @@
import 'package:country_code_picker/celement.dart';
import 'package:country_code_picker/country_code.dart';
import 'package:flutter/material.dart';
/// selection dialog used for selection of the country code
class SelectionDialog extends StatefulWidget {
final List<CElement> elements;
final List<CountryCode> elements;
/// elements passed as favorite
final List<CElement> favoriteElements;
final List<CountryCode> favoriteElements;
SelectionDialog(this.elements, this.favoriteElements);
@@ -16,7 +16,7 @@ class SelectionDialog extends StatefulWidget {
class _SelectionDialogState extends State<SelectionDialog> {
/// this is useful for filtering purpose
List<CElement> showedElements = [];
List<CountryCode> showedElements = [];
@override
Widget build(BuildContext context) => new SimpleDialog(
@@ -34,63 +34,70 @@ class _SelectionDialogState extends State<SelectionDialog> {
: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[]
..addAll(widget.favoriteElements.map((f) {
return new SimpleDialogOption(
child: Flex(
direction: Axis.horizontal,
children: <Widget>[
Flexible(
child: Padding(
padding: const EdgeInsets.only(right: 16.0),
child: Image.asset(
f.flagUri,
package: 'country_code_picker',
width: 32.0,
),
..addAll(widget.favoriteElements
.map(
(f) => new SimpleDialogOption(
child: Flex(
direction: Axis.horizontal,
children: <Widget>[
Flexible(
child: Padding(
padding:
const EdgeInsets.only(right: 16.0),
child: Image.asset(
f.flagUri,
package: 'country_code_picker',
width: 32.0,
),
),
),
Flexible(
fit: FlexFit.tight,
child: new Text(
f.toLongString(),
overflow: TextOverflow.fade,
),
),
],
),
onPressed: () {
_selectItem(f);
},
),
Flexible(
fit: FlexFit.tight,
child: new Text(
f.toLongString(),
overflow: TextOverflow.fade,
),
),
],
),
onPressed: () {
_selectItem(f);
});
}).toList())
)
.toList())
..add(new Divider())),
]..addAll(showedElements
.map((e) => new SimpleDialogOption(
key: Key(e.toLongString()),
child: Flex(
direction: Axis.horizontal,
children: <Widget>[
Flexible(
child: Padding(
padding: const EdgeInsets.only(right: 16.0),
child: Image.asset(
e.flagUri,
package: 'country_code_picker',
width: 32.0,
.map(
(e) => new SimpleDialogOption(
key: Key(e.toLongString()),
child: Flex(
direction: Axis.horizontal,
children: <Widget>[
Flexible(
child: Padding(
padding: const EdgeInsets.only(right: 16.0),
child: Image.asset(
e.flagUri,
package: 'country_code_picker',
width: 32.0,
),
),
),
),
Flexible(
fit: FlexFit.tight,
child: Text(
e.toLongString(),
overflow: TextOverflow.fade,
),
),
],
),
Flexible(
fit: FlexFit.tight,
child: Text(
e.toLongString(),
overflow: TextOverflow.fade,
),
),
],
),
onPressed: () {
_selectItem(e);
}))
onPressed: () {
_selectItem(e);
},
),
)
.toList()));
@override
@@ -111,7 +118,7 @@ class _SelectionDialogState extends State<SelectionDialog> {
});
}
void _selectItem(CElement e) {
void _selectItem(CountryCode e) {
Navigator.pop(context, e);
}
}