This commit is contained in:
unknown 2018-05-29 03:48:43 -07:00
parent f903336b78
commit 340203528e
8 changed files with 64 additions and 65 deletions

View File

@ -10,6 +10,9 @@ The application architecture is based off these two projects:
- [Redux Sample](https://github.com/brianegan/flutter_architecture_samples/tree/master/example/redux) - [Brian Egan](https://twitter.com/brianegan) - [Redux Sample](https://github.com/brianegan/flutter_architecture_samples/tree/master/example/redux) - [Brian Egan](https://twitter.com/brianegan)
- [inKino](https://github.com/roughike/inKino) - [Iiro Krankka](https://twitter.com/koorankka) - [inKino](https://github.com/roughike/inKino) - [Iiro Krankka](https://twitter.com/koorankka)
## Developer Notes
- Run `flutter packages pub run build_runner build` to regenerate the model files
## Contributions ## Contributions
We gladly accept contributions! If you'd like to get involved with development please join our [Slack group](http://slack.invoiceninja.com/). We gladly accept contributions! If you'd like to get involved with development please join our [Slack group](http://slack.invoiceninja.com/).

View File

@ -28,11 +28,13 @@ abstract class LoginResponse implements Built<LoginResponse, LoginResponseBuilde
abstract class CompanyEntity implements Built<CompanyEntity, CompanyEntityBuilder> { abstract class CompanyEntity implements Built<CompanyEntity, CompanyEntityBuilder> {
@nullable
String get name; String get name;
//@BuiltValueField(wireName: 'account_key') //@BuiltValueField(wireName: 'account_key')
//String get companyKey; //String get companyKey;
@nullable
String get token; String get token;
@nullable @nullable
@ -42,16 +44,8 @@ abstract class CompanyEntity implements Built<CompanyEntity, CompanyEntityBuilde
@BuiltValueField(wireName: 'logo_url') @BuiltValueField(wireName: 'logo_url')
String get logoUrl; String get logoUrl;
factory CompanyEntity() {
return _$CompanyEntity._(
name: '',
token: '',
logoUrl: '',
);
}
CompanyEntity._(); CompanyEntity._();
//factory CompanyEntity([updates(CompanyEntityBuilder b)]) = _$CompanyEntity; factory CompanyEntity([updates(CompanyEntityBuilder b)]) = _$CompanyEntity;
static Serializer<CompanyEntity> get serializer => _$companyEntitySerializer; static Serializer<CompanyEntity> get serializer => _$companyEntitySerializer;
} }
@ -67,31 +61,32 @@ abstract class DashboardResponse implements Built<DashboardResponse, DashboardRe
abstract class DashboardEntity implements Built<DashboardEntity, DashboardEntityBuilder> { abstract class DashboardEntity implements Built<DashboardEntity, DashboardEntityBuilder> {
@nullable
double get paidToDate; double get paidToDate;
@nullable
int get paidToDateCurrency; int get paidToDateCurrency;
@nullable
double get balances; double get balances;
@nullable
int get balancesCurrency; int get balancesCurrency;
@nullable
double get averageInvoice; double get averageInvoice;
@nullable
int get averageInvoiceCurrency; int get averageInvoiceCurrency;
@nullable
int get invoicesSent; int get invoicesSent;
@nullable
int get activeClients; int get activeClients;
factory DashboardEntity() {
return _$DashboardEntity._(
paidToDate: 0.0,
paidToDateCurrency: 1,
balances: 0.0,
balancesCurrency: 1,
averageInvoice: 0.0,
averageInvoiceCurrency: 1,
invoicesSent: 0,
activeClients: 0,
);
}
DashboardEntity._(); DashboardEntity._();
//factory DashboardEntity([updates(DashboardEntityBuilder b)]) = _$DashboardEntity; factory DashboardEntity([updates(DashboardEntityBuilder b)]) = _$DashboardEntity;
static Serializer<DashboardEntity> get serializer => _$dashboardEntitySerializer; static Serializer<DashboardEntity> get serializer => _$dashboardEntitySerializer;
} }

View File

@ -24,11 +24,17 @@ abstract class ProductItemResponse implements Built<ProductItemResponse, Product
abstract class ProductEntity implements Built<ProductEntity, ProductEntityBuilder> { abstract class ProductEntity implements Built<ProductEntity, ProductEntityBuilder> {
@nullable
int get id; int get id;
@nullable
@BuiltValueField(wireName: 'product_key') @BuiltValueField(wireName: 'product_key')
String get productKey; String get productKey;
@nullable
String get notes; String get notes;
@nullable
double get cost; double get cost;
//@JsonKey(name: 'tax_name1') //@JsonKey(name: 'tax_name1')
@ -50,17 +56,7 @@ abstract class ProductEntity implements Built<ProductEntity, ProductEntityBuilde
//@JsonKey(name: 'is_deleted') //@JsonKey(name: 'is_deleted')
//bool isDeleted; //bool isDeleted;
factory ProductEntity() {
return _$ProductEntity._(
id: 0,
productKey: '',
notes: '',
cost: 0.0,
);
}
ProductEntity._(); ProductEntity._();
//factory ProductEntity([updates(ProductEntityBuilder b)]) = _$ProductEntity; factory ProductEntity([updates(ProductEntityBuilder b)]) = _$ProductEntity;
static Serializer<ProductEntity> get serializer => _$productEntitySerializer; static Serializer<ProductEntity> get serializer => _$productEntitySerializer;
} }

View File

@ -121,18 +121,31 @@ class _$ProductEntitySerializer implements StructuredSerializer<ProductEntity> {
@override @override
Iterable serialize(Serializers serializers, ProductEntity object, Iterable serialize(Serializers serializers, ProductEntity object,
{FullType specifiedType: FullType.unspecified}) { {FullType specifiedType: FullType.unspecified}) {
final result = <Object>[ final result = <Object>[];
'id', if (object.id != null) {
serializers.serialize(object.id, specifiedType: const FullType(int)), result
'product_key', ..add('id')
serializers.serialize(object.productKey, ..add(serializers.serialize(object.id,
specifiedType: const FullType(String)), specifiedType: const FullType(int)));
'notes', }
serializers.serialize(object.notes, if (object.productKey != null) {
specifiedType: const FullType(String)), result
'cost', ..add('product_key')
serializers.serialize(object.cost, specifiedType: const FullType(double)), ..add(serializers.serialize(object.productKey,
]; specifiedType: const FullType(String)));
}
if (object.notes != null) {
result
..add('notes')
..add(serializers.serialize(object.notes,
specifiedType: const FullType(String)));
}
if (object.cost != null) {
result
..add('cost')
..add(serializers.serialize(object.cost,
specifiedType: const FullType(double)));
}
return result; return result;
} }
@ -366,15 +379,7 @@ class _$ProductEntity extends ProductEntity {
(new ProductEntityBuilder()..update(updates)).build(); (new ProductEntityBuilder()..update(updates)).build();
_$ProductEntity._({this.id, this.productKey, this.notes, this.cost}) _$ProductEntity._({this.id, this.productKey, this.notes, this.cost})
: super._() { : super._();
if (id == null) throw new BuiltValueNullFieldError('ProductEntity', 'id');
if (productKey == null)
throw new BuiltValueNullFieldError('ProductEntity', 'productKey');
if (notes == null)
throw new BuiltValueNullFieldError('ProductEntity', 'notes');
if (cost == null)
throw new BuiltValueNullFieldError('ProductEntity', 'cost');
}
@override @override
ProductEntity rebuild(void updates(ProductEntityBuilder b)) => ProductEntity rebuild(void updates(ProductEntityBuilder b)) =>

View File

@ -35,12 +35,12 @@ class ProductsRepository {
var data = serializers.serializeWith(ProductEntity.serializer, product); var data = serializers.serializeWith(ProductEntity.serializer, product);
var response; var response;
if (product.id > 0) { if (product.id == null) {
response = await webClient.put(
auth.url + '/products/' + product.id.toString(), company.token, json.encode(data));
} else {
response = await webClient.post( response = await webClient.post(
auth.url + '/products', company.token, json.encode(data)); auth.url + '/products', company.token, json.encode(data));
} else {
response = await webClient.put(
auth.url + '/products/' + product.id.toString(), company.token, json.encode(data));
} }
ProductItemResponse productResponse = serializers.deserializeWith( ProductItemResponse productResponse = serializers.deserializeWith(

View File

@ -30,7 +30,7 @@ Middleware<AppState> _createSaveProduct(ProductsRepository repository) {
repository.saveData(store.state.selectedCompany(), store.state.authState, action.product).then( repository.saveData(store.state.selectedCompany(), store.state.authState, action.product).then(
(product) { (product) {
var message; var message;
if (action.product.id == 0) { if (action.product.id == null) {
message = AppLocalization.of(action.context).successfullyCreatedProduct; message = AppLocalization.of(action.context).successfullyCreatedProduct;
store.dispatch(AddProductSuccess(product)); store.dispatch(AddProductSuccess(product));
} else { } else {

View File

@ -22,7 +22,7 @@ class ProductDetails extends StatelessWidget {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text(viewModel.product.id > 0 ? viewModel.product.productKey : AppLocalization.of(context).newProduct), // Text(localizations.productDetails), title: Text(viewModel.product.id == null ? AppLocalization.of(context).newProduct : viewModel.product.productKey), // Text(localizations.productDetails),
actions: [ actions: [
/* /*
IconButton( IconButton(
@ -66,7 +66,7 @@ class ProductDetails extends StatelessWidget {
), ),
), ),
TextFormField( TextFormField(
initialValue: viewModel.product.cost > 0 ? viewModel.product.cost.toStringAsFixed(2) : null, initialValue: viewModel.product.cost == null ? null : viewModel.product.cost.toStringAsFixed(2),
onSaved: (value) => _cost = double.tryParse(value) ?? 0.0, onSaved: (value) => _cost = double.tryParse(value) ?? 0.0,
keyboardType: TextInputType.number, keyboardType: TextInputType.number,
decoration: InputDecoration( decoration: InputDecoration(

View File

@ -51,7 +51,7 @@ class ProductDetailsVM {
return ProductDetailsVM( return ProductDetailsVM(
isLoading: store.state.isLoading, isLoading: store.state.isLoading,
isDirty: product.id == 0, isDirty: product.id == null,
product: product, product: product,
onDelete: () => false, onDelete: () => false,
onSaveClicked: (ProductEntity product, BuildContext context) { onSaveClicked: (ProductEntity product, BuildContext context) {