Contacts
This commit is contained in:
parent
a9b9a68cd3
commit
75e39b89c1
|
|
@ -19,8 +19,8 @@ class ClientEditContacts extends StatefulWidget {
|
||||||
|
|
||||||
class ClientEditContactsState extends State<ClientEditContacts>
|
class ClientEditContactsState extends State<ClientEditContacts>
|
||||||
with AutomaticKeepAliveClientMixin {
|
with AutomaticKeepAliveClientMixin {
|
||||||
|
List<ContactEntity> contacts;
|
||||||
Map<ContactEntity, GlobalKey<ContactEditDetailsState>> contactKeys;
|
List<GlobalKey<ContactEditDetailsState>> contactKeys;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get wantKeepAlive => true;
|
bool get wantKeepAlive => true;
|
||||||
|
|
@ -28,32 +28,56 @@ class ClientEditContactsState extends State<ClientEditContacts>
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
contactKeys = Map.fromIterable(widget.client.contacts,
|
var client = widget.client;
|
||||||
key: (contact) => contact,
|
contacts = client.contacts.toList();
|
||||||
value: (contact) => GlobalKey<ContactEditDetailsState>(),
|
contactKeys = client.contacts
|
||||||
);
|
.map((contact) => GlobalKey<ContactEditDetailsState>())
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
// Add initial blank contact
|
||||||
|
_onAddPressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ContactEntity> getContacts() {
|
List<ContactEntity> getContacts() {
|
||||||
List<ContactEntity> contacts = [];
|
List<ContactEntity> contacts = [];
|
||||||
contactKeys.forEach((contact, contactKey) {
|
contactKeys.forEach((contactKey) {
|
||||||
contacts.add(contactKey.currentState.getContact());
|
contacts.add(contactKey.currentState.getContact());
|
||||||
});
|
});
|
||||||
return contacts;
|
return contacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onAddPressed() {
|
||||||
|
print('onAddPressed..');
|
||||||
|
setState(() {
|
||||||
|
contacts.add(ContactEntity());
|
||||||
|
contactKeys.add(GlobalKey<ContactEditDetailsState>());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
var localization = AppLocalization.of(context);
|
var localization = AppLocalization.of(context);
|
||||||
var client = widget.client;
|
|
||||||
|
List<Widget> items = [];
|
||||||
|
|
||||||
|
for (var i=0; i<contacts.length; i++) {
|
||||||
|
var contact = contacts[i];
|
||||||
|
var contactKey = contactKeys[i];
|
||||||
|
items.add(ContactEditDetails(
|
||||||
|
contact: contact,
|
||||||
|
key: contactKey,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
items.add(RaisedButton(
|
||||||
|
elevation: 4.0,
|
||||||
|
child: Text(localization.add),
|
||||||
|
onPressed: _onAddPressed,
|
||||||
|
));
|
||||||
|
|
||||||
return ListView(
|
return ListView(
|
||||||
children: client.contacts.map((contact) {
|
children: items,
|
||||||
return ContactEditDetails(
|
);
|
||||||
contact: contact,
|
|
||||||
key: contactKeys[contact],
|
|
||||||
);
|
|
||||||
}).toList());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,8 +97,7 @@ class ContactEditDetailsState extends State<ContactEditDetails> {
|
||||||
String _firstName;
|
String _firstName;
|
||||||
|
|
||||||
ContactEntity getContact() {
|
ContactEntity getContact() {
|
||||||
return ContactEntity((b) => b
|
return ContactEntity((b) => b..firstName = _firstName);
|
||||||
..firstName = _firstName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,8 @@ class AppLocalization {
|
||||||
'additional': 'Additional',
|
'additional': 'Additional',
|
||||||
'first_name': 'First Name',
|
'first_name': 'First Name',
|
||||||
'last_name': 'Last Name',
|
'last_name': 'Last Name',
|
||||||
|
'add': 'Add',
|
||||||
|
|
||||||
'product': 'Product',
|
'product': 'Product',
|
||||||
'products': 'Products',
|
'products': 'Products',
|
||||||
'new_product': 'New Product',
|
'new_product': 'New Product',
|
||||||
|
|
@ -147,6 +149,7 @@ class AppLocalization {
|
||||||
String get additional => _localizedValues[locale.languageCode]['additional'];
|
String get additional => _localizedValues[locale.languageCode]['additional'];
|
||||||
String get firstName => _localizedValues[locale.languageCode]['first_name'];
|
String get firstName => _localizedValues[locale.languageCode]['first_name'];
|
||||||
String get lastName => _localizedValues[locale.languageCode]['last_name'];
|
String get lastName => _localizedValues[locale.languageCode]['last_name'];
|
||||||
|
String get add => _localizedValues[locale.languageCode]['add'];
|
||||||
|
|
||||||
String get product => _localizedValues[locale.languageCode]['product'];
|
String get product => _localizedValues[locale.languageCode]['product'];
|
||||||
String get products => _localizedValues[locale.languageCode]['products'];
|
String get products => _localizedValues[locale.languageCode]['products'];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue