Refactor
This commit is contained in:
parent
48426f1a94
commit
841509719a
|
|
@ -0,0 +1,34 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:invoiceninja/utils/localization.dart';
|
||||
|
||||
class SaveIconButton extends StatelessWidget {
|
||||
|
||||
SaveIconButton({this.isLoading, this.onPressed});
|
||||
final bool isLoading;
|
||||
final Function onPressed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var localization = AppLocalization.of(context);
|
||||
|
||||
if (isLoading) {
|
||||
return IconButton(
|
||||
onPressed: null,
|
||||
icon: SizedBox(
|
||||
child: CircularProgressIndicator(
|
||||
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return IconButton(
|
||||
onPressed: onPressed,
|
||||
tooltip: localization.save,
|
||||
icon: Icon(
|
||||
Icons.cloud_upload,
|
||||
color: Colors.white,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ import 'package:invoiceninja/ui/client/edit/client_edit_details.dart';
|
|||
import 'package:invoiceninja/ui/client/edit/client_edit_vm.dart';
|
||||
import 'package:invoiceninja/utils/localization.dart';
|
||||
|
||||
import '../../app/save_icon_button.dart';
|
||||
import 'client_edit_billing_address.dart';
|
||||
import 'client_edit_contacts.dart';
|
||||
import 'client_edit_shipping_address.dart';
|
||||
|
|
@ -78,14 +79,43 @@ class _ClientEditState extends State<ClientEdit>
|
|||
? localization.newClient
|
||||
: client.displayName), // Text(localizations.clientDetails),
|
||||
actions: <Widget>[
|
||||
SaveButton(
|
||||
viewModel: widget.viewModel,
|
||||
editors: editors,
|
||||
formKey: _formKey,
|
||||
detailsKey: _detailsKey,
|
||||
billingAddressKey: _billingAddressKey,
|
||||
shippingAddressKey: _shippingAddressKey,
|
||||
contactsKey: _contactsKey,
|
||||
SaveIconButton(
|
||||
isLoading: widget.viewModel.isLoading,
|
||||
onPressed: () {
|
||||
if (! _formKey.currentState.validate()) {
|
||||
return;
|
||||
}
|
||||
|
||||
_formKey.currentState.save();
|
||||
|
||||
var detailsState = _detailsKey.currentState;
|
||||
var billingAddressState = _billingAddressKey.currentState;
|
||||
//var shippingAddressState = _shippingAddressKey.currentState;
|
||||
var contactState = _contactsKey.currentState;
|
||||
|
||||
ClientEntity client = widget.viewModel.client.rebuild((b) => b
|
||||
..name = detailsState.name
|
||||
..idNumber = detailsState.idNumber
|
||||
..vatNumber = detailsState.vatNumber
|
||||
..website = detailsState.website
|
||||
..workPhone = detailsState.phone
|
||||
/*
|
||||
..address1 = billingAddressState.address1
|
||||
..address2 = billingAddressState.address2
|
||||
..city = billingAddressState.city
|
||||
..state = billingAddressState.state
|
||||
..postalCode = billingAddressState.postalCode
|
||||
..shippingAddress1 = shippingAddressState.shippingAddress1
|
||||
..shippingAddress2 = shippingAddressState.shippingAddress2
|
||||
..shippingCity = shippingAddressState.shippingCity
|
||||
..shippingState = shippingAddressState.shippingState
|
||||
..shippingPostalCode = shippingAddressState.shippingPostalCode
|
||||
*/
|
||||
..contacts.replace(
|
||||
contactState?.getContacts() ?? widget.viewModel.client.contacts));
|
||||
|
||||
widget.viewModel.onSaveClicked(context, client);
|
||||
},
|
||||
)
|
||||
],
|
||||
bottom: TabBar(
|
||||
|
|
@ -118,85 +148,4 @@ class _ClientEditState extends State<ClientEdit>
|
|||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SaveButton extends StatelessWidget {
|
||||
final ClientEditVM viewModel;
|
||||
final List<Widget> editors;
|
||||
final GlobalKey<FormState> formKey;
|
||||
final GlobalKey<ClientEditDetailsState> detailsKey;
|
||||
final GlobalKey<ClientEditContactsState> contactsKey;
|
||||
final GlobalKey<ClientEditBillingAddressState> billingAddressKey;
|
||||
final GlobalKey<ClientEditShippingAddressState> shippingAddressKey;
|
||||
|
||||
SaveButton({
|
||||
this.viewModel,
|
||||
this.editors,
|
||||
this.formKey,
|
||||
this.detailsKey,
|
||||
this.contactsKey,
|
||||
this.billingAddressKey,
|
||||
this.shippingAddressKey,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var localization = AppLocalization.of(context);
|
||||
var client = viewModel.client;
|
||||
|
||||
if (viewModel.isLoading) {
|
||||
return IconButton(
|
||||
onPressed: null,
|
||||
icon: SizedBox(
|
||||
//width: 28.0,
|
||||
child: CircularProgressIndicator(
|
||||
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
||||
//strokeWidth: 2.0,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return IconButton(
|
||||
onPressed: () {
|
||||
if (!formKey.currentState.validate()) {
|
||||
return;
|
||||
}
|
||||
|
||||
formKey.currentState.save();
|
||||
|
||||
var detailsState = detailsKey.currentState;
|
||||
var billingAddressState = billingAddressKey.currentState;
|
||||
//var shippingAddressState = shippingAddressKey.currentState;
|
||||
var contactState = contactsKey.currentState;
|
||||
|
||||
ClientEntity client = viewModel.client.rebuild((b) => b
|
||||
..name = detailsState.name
|
||||
..idNumber = detailsState.idNumber
|
||||
..vatNumber = detailsState.vatNumber
|
||||
..website = detailsState.website
|
||||
..workPhone = detailsState.phone
|
||||
/*
|
||||
..address1 = billingAddressState.address1
|
||||
..address2 = billingAddressState.address2
|
||||
..city = billingAddressState.city
|
||||
..state = billingAddressState.state
|
||||
..postalCode = billingAddressState.postalCode
|
||||
..shippingAddress1 = shippingAddressState.shippingAddress1
|
||||
..shippingAddress2 = shippingAddressState.shippingAddress2
|
||||
..shippingCity = shippingAddressState.shippingCity
|
||||
..shippingState = shippingAddressState.shippingState
|
||||
..shippingPostalCode = shippingAddressState.shippingPostalCode
|
||||
*/
|
||||
..contacts.replace(contactState?.getContacts() ?? viewModel.client.contacts));
|
||||
|
||||
viewModel.onSaveClicked(context, client);
|
||||
},
|
||||
tooltip: localization.save,
|
||||
icon: Icon(
|
||||
Icons.cloud_upload,
|
||||
color: Colors.white,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,11 @@
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:invoiceninja/ui/app/actions_menu_button.dart';
|
||||
import 'package:invoiceninja/ui/app/form_card.dart';
|
||||
import 'package:invoiceninja/ui/app/progress_button.dart';
|
||||
import 'package:invoiceninja/ui/product/product_edit_vm.dart';
|
||||
import 'package:invoiceninja/ui/product/edit/product_edit_vm.dart';
|
||||
import 'package:invoiceninja/utils/localization.dart';
|
||||
|
||||
import '../app/form_card.dart';
|
||||
|
||||
class ProductEdit extends StatefulWidget {
|
||||
final ProductEditVM viewModel;
|
||||
static final GlobalKey<FormState> formKey = GlobalKey<FormState>();
|
||||
|
|
@ -34,7 +33,7 @@ class _ProductEditState extends State<ProductEdit> {
|
|||
title: Text(viewModel.product.id == null
|
||||
? AppLocalization.of(context).newProduct
|
||||
: viewModel
|
||||
.product.productKey), // Text(localizations.productDetails),
|
||||
.product.productKey),
|
||||
actions: viewModel.product.id == null
|
||||
? []
|
||||
: [
|
||||
|
|
@ -6,7 +6,7 @@ import 'package:invoiceninja/utils/localization.dart';
|
|||
import 'package:redux/redux.dart';
|
||||
import 'package:invoiceninja/redux/product/product_actions.dart';
|
||||
import 'package:invoiceninja/data/models/models.dart';
|
||||
import 'package:invoiceninja/ui/product/product_edit.dart';
|
||||
import 'package:invoiceninja/ui/product/edit/product_edit.dart';
|
||||
import 'package:invoiceninja/redux/app/app_state.dart';
|
||||
import 'package:invoiceninja/ui/app/snackbar_row.dart';
|
||||
|
||||
|
|
@ -12,7 +12,7 @@ import 'package:invoiceninja/data/models/models.dart';
|
|||
import 'package:invoiceninja/ui/product/product_list.dart';
|
||||
import 'package:invoiceninja/redux/app/app_state.dart';
|
||||
import 'package:invoiceninja/redux/product/product_actions.dart';
|
||||
import 'package:invoiceninja/ui/product/product_edit_vm.dart';
|
||||
import 'package:invoiceninja/ui/product/edit/product_edit_vm.dart';
|
||||
|
||||
class ProductListBuilder extends StatelessWidget {
|
||||
ProductListBuilder({Key key}) : super(key: key);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import 'package:invoiceninja/ui/app/app_search.dart';
|
||||
import 'package:invoiceninja/ui/app/app_search_button.dart';
|
||||
import 'package:invoiceninja/ui/product/edit/product_edit_vm.dart';
|
||||
import 'package:invoiceninja/utils/localization.dart';
|
||||
import 'package:invoiceninja/redux/app/app_state.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:invoiceninja/data/models/models.dart';
|
||||
import 'package:invoiceninja/ui/product/product_list_vm.dart';
|
||||
import 'package:invoiceninja/ui/product/product_edit_vm.dart';
|
||||
import 'package:flutter_redux/flutter_redux.dart';
|
||||
import 'package:invoiceninja/redux/product/product_actions.dart';
|
||||
import 'package:invoiceninja/ui/app/app_drawer_vm.dart';
|
||||
|
|
|
|||
Loading…
Reference in New Issue