This commit is contained in:
unknown 2018-06-12 00:38:47 -07:00
parent 79e995828a
commit a9b9a68cd3
3 changed files with 54 additions and 19 deletions

View File

@ -1050,7 +1050,7 @@ class _$ClientEntity extends ClientEntity {
creditNumberCounter == other.creditNumberCounter && creditNumberCounter == other.creditNumberCounter &&
customValue1 == other.customValue1 && customValue1 == other.customValue1 &&
customValue2 == other.customValue2 && customValue2 == other.customValue2 &&
contacts == other.contacts && contacts == other.contactKeys &&
id == other.id && id == other.id &&
updatedAt == other.updatedAt && updatedAt == other.updatedAt &&
archivedAt == other.archivedAt && archivedAt == other.archivedAt &&

View File

@ -85,6 +85,7 @@ class _ClientEditState extends State<ClientEdit>
detailsKey: _detailsKey, detailsKey: _detailsKey,
billingAddressKey: _billingAddressKey, billingAddressKey: _billingAddressKey,
shippingAddressKey: _shippingAddressKey, shippingAddressKey: _shippingAddressKey,
contactsKey: _contactsKey,
) )
], ],
bottom: TabBar( bottom: TabBar(
@ -119,11 +120,6 @@ class _ClientEditState extends State<ClientEdit>
} }
} }
/*
abstract class EntityEditor extends StatefulWidget {
onSaveClicked(ClientEntity client);
}
*/
class SaveButton extends StatelessWidget { class SaveButton extends StatelessWidget {
final ClientEditVM viewModel; final ClientEditVM viewModel;
@ -173,6 +169,7 @@ class SaveButton extends StatelessWidget {
var detailsState = detailsKey.currentState; var detailsState = detailsKey.currentState;
var billingAddressState = billingAddressKey.currentState; var billingAddressState = billingAddressKey.currentState;
//var shippingAddressState = shippingAddressKey.currentState; //var shippingAddressState = shippingAddressKey.currentState;
var contactState = contactsKey.currentState;
ClientEntity client = viewModel.client.rebuild((b) => b ClientEntity client = viewModel.client.rebuild((b) => b
..name = detailsState.name ..name = detailsState.name
@ -180,18 +177,19 @@ class SaveButton extends StatelessWidget {
..vatNumber = detailsState.vatNumber ..vatNumber = detailsState.vatNumber
..website = detailsState.website ..website = detailsState.website
..workPhone = detailsState.phone ..workPhone = detailsState.phone
/*
..address1 = billingAddressState.address1 ..address1 = billingAddressState.address1
..address2 = billingAddressState.address2 ..address2 = billingAddressState.address2
..city = billingAddressState.city ..city = billingAddressState.city
..state = billingAddressState.state ..state = billingAddressState.state
..postalCode = billingAddressState.postalCode ..postalCode = billingAddressState.postalCode
/*
..shippingAddress1 = shippingAddressState.shippingAddress1 ..shippingAddress1 = shippingAddressState.shippingAddress1
..shippingAddress2 = shippingAddressState.shippingAddress2 ..shippingAddress2 = shippingAddressState.shippingAddress2
..shippingCity = shippingAddressState.shippingCity ..shippingCity = shippingAddressState.shippingCity
..shippingState = shippingAddressState.shippingState ..shippingState = shippingAddressState.shippingState
..shippingPostalCode = shippingAddressState.shippingPostalCode ..shippingPostalCode = shippingAddressState.shippingPostalCode
*/ */
..contacts.replace(contactState.getContacts())
); );
viewModel.onSaveClicked(context, client); viewModel.onSaveClicked(context, client);

View File

@ -1,3 +1,4 @@
import 'package:built_collection/built_collection.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:invoiceninja/data/models/models.dart'; import 'package:invoiceninja/data/models/models.dart';
@ -18,28 +19,63 @@ 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;
@override @override
bool get wantKeepAlive => true; bool get wantKeepAlive => true;
@override
void initState() {
super.initState();
contactKeys = Map.fromIterable(widget.client.contacts,
key: (contact) => contact,
value: (contact) => GlobalKey<ContactEditDetailsState>(),
);
}
List<ContactEntity> getContacts() {
List<ContactEntity> contacts = [];
contactKeys.forEach((contact, contactKey) {
contacts.add(contactKey.currentState.getContact());
});
return contacts;
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var localization = AppLocalization.of(context); var localization = AppLocalization.of(context);
var client = widget.client; var client = widget.client;
return KeyboardAwarePadding( return ListView(
child: ListView( children: client.contacts.map((contact) {
children: client.contacts return ContactEditDetails(
.map((contact) => ContactSettings(contact)) contact: contact,
.toList()), key: contactKeys[contact],
); );
}).toList());
} }
} }
class ContactSettings extends StatelessWidget { class ContactEditDetails extends StatefulWidget {
ContactSettings(this.contact); ContactEditDetails({
ContactEntity contact; Key key,
@required this.contact,
}) : super(key: key);
final ContactEntity contact;
@override
ContactEditDetailsState createState() => ContactEditDetailsState();
}
class ContactEditDetailsState extends State<ContactEditDetails> {
String _firstName;
ContactEntity getContact() {
return ContactEntity((b) => b
..firstName = _firstName);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -56,9 +92,10 @@ class ContactSettings extends StatelessWidget {
children: <Widget>[ children: <Widget>[
TextFormField( TextFormField(
autocorrect: false, autocorrect: false,
initialValue: contact.firstName, initialValue: widget.contact.firstName,
onSaved: (value) => _firstName = value.trim(),
decoration: InputDecoration( decoration: InputDecoration(
labelText: localization.website, labelText: localization.firstName,
), ),
), ),
], ],