From a92ca3bad53629e018d5373c40c444cead237e4c Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 15 Jul 2019 14:03:45 +0300 Subject: [PATCH] Working on products --- lib/ui/product/edit/product_edit_vm.dart | 32 +++++++++++---- lib/ui/product/view/product_view.dart | 52 ++++++++++++++++++++++-- 2 files changed, 74 insertions(+), 10 deletions(-) diff --git a/lib/ui/product/edit/product_edit_vm.dart b/lib/ui/product/edit/product_edit_vm.dart index 3060330f1..e1fcccc21 100644 --- a/lib/ui/product/edit/product_edit_vm.dart +++ b/lib/ui/product/edit/product_edit_vm.dart @@ -1,8 +1,12 @@ +import 'dart:async'; + import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_redux/flutter_redux.dart'; import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart'; +import 'package:invoiceninja_flutter/ui/app/dialogs/error_dialog.dart'; import 'package:invoiceninja_flutter/ui/product/product_screen.dart'; +import 'package:invoiceninja_flutter/ui/product/view/product_view_vm.dart'; import 'package:invoiceninja_flutter/utils/completers.dart'; import 'package:invoiceninja_flutter/utils/localization.dart'; import 'package:redux/redux.dart'; @@ -63,13 +67,27 @@ class ProductEditVM { } }, onSavePressed: (BuildContext context) { - store.dispatch(SaveProductRequest( - completer: snackBarCompleter( - context, - product.isNew - ? AppLocalization.of(context).createdProduct - : AppLocalization.of(context).updatedProduct), - product: product)); + final Completer completer = + new Completer(); + store.dispatch( + SaveProductRequest(completer: completer, product: product)); + return completer.future.then((_) { + return completer.future.then((savedProduct) { + store.dispatch(UpdateCurrentRoute(ProductViewScreen.route)); + if (product.isNew) { + Navigator.of(context) + .pushReplacementNamed(ProductViewScreen.route); + } else { + Navigator.of(context).pop(savedProduct); + } + }).catchError((Object error) { + showDialog( + context: context, + builder: (BuildContext context) { + return ErrorDialog(error); + }); + }); + }); }, onEntityAction: (BuildContext context, EntityAction action) { // TODO Add view page for products diff --git a/lib/ui/product/view/product_view.dart b/lib/ui/product/view/product_view.dart index 726e2aa4a..2b3185fef 100644 --- a/lib/ui/product/view/product_view.dart +++ b/lib/ui/product/view/product_view.dart @@ -1,10 +1,14 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_redux/flutter_redux.dart'; +import 'package:invoiceninja_flutter/data/models/entities.dart'; import 'package:invoiceninja_flutter/redux/app/app_state.dart'; +import 'package:invoiceninja_flutter/ui/app/FieldGrid.dart'; import 'package:invoiceninja_flutter/ui/app/actions_menu_button.dart'; import 'package:invoiceninja_flutter/ui/app/buttons/edit_icon_button.dart'; +import 'package:invoiceninja_flutter/ui/app/one_value_header.dart'; import 'package:invoiceninja_flutter/ui/product/view/product_view_vm.dart'; +import 'package:invoiceninja_flutter/utils/formatting.dart'; import 'package:invoiceninja_flutter/utils/localization.dart'; class ProductView extends StatefulWidget { @@ -38,11 +42,38 @@ class _ProductViewState extends State @override Widget build(BuildContext context) { final localization = AppLocalization.of(context); - final store = StoreProvider.of(context); final viewModel = widget.viewModel; final product = viewModel.product; final company = viewModel.company; - final user = company.user; + + String tax = ''; + if (product.taxName1.isNotEmpty) { + tax += formatNumber(product.taxRate1, context, + formatNumberType: FormatNumberType.percent) + + ' ' + + product.taxName1; + } + if (product.taxName2.isNotEmpty) { + tax += ' ' + + formatNumber(product.taxRate2, context, + formatNumberType: FormatNumberType.percent) + + ' ' + + product.taxName2; + } + + final fields = { + localization.tax: tax, + }; + + if (product.customValue1.isNotEmpty) { + final label1 = company.getCustomFieldLabel(CustomFieldType.product1); + fields[label1] = product.customValue1; + } + + if (product.customValue2.isNotEmpty) { + final label2 = company.getCustomFieldLabel(CustomFieldType.product2); + fields[label2] = product.customValue2; + } return WillPopScope( onWillPop: () async { @@ -53,7 +84,22 @@ class _ProductViewState extends State appBar: _CustomAppBar( viewModel: viewModel, ), - body: Text('test'), + body: ListView( + children: [ + OneValueHeader( + label: localization.cost, + value: formatNumber(product.cost, context), + ), + FieldGrid(fields), + Divider( + height: 1.0, + ), + Padding( + padding: EdgeInsets.all(16), + child: Text(product.notes), + ), + ], + ), ), ); }