Working on products
This commit is contained in:
parent
6698c5f097
commit
a92ca3bad5
|
|
@ -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<ProductEntity> completer =
|
||||
new Completer<ProductEntity>();
|
||||
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<ErrorDialog>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return ErrorDialog(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
onEntityAction: (BuildContext context, EntityAction action) {
|
||||
// TODO Add view page for products
|
||||
|
|
|
|||
|
|
@ -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<ProductView>
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final localization = AppLocalization.of(context);
|
||||
final store = StoreProvider.of<AppState>(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 = <String, String>{
|
||||
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<ProductView>
|
|||
appBar: _CustomAppBar(
|
||||
viewModel: viewModel,
|
||||
),
|
||||
body: Text('test'),
|
||||
body: ListView(
|
||||
children: <Widget>[
|
||||
OneValueHeader(
|
||||
label: localization.cost,
|
||||
value: formatNumber(product.cost, context),
|
||||
),
|
||||
FieldGrid(fields),
|
||||
Divider(
|
||||
height: 1.0,
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Text(product.notes),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue