diff --git a/lib/widget/dialogs.dart b/lib/widget/dialogs.dart index 2ee883ed..dd37ed65 100644 --- a/lib/widget/dialogs.dart +++ b/lib/widget/dialogs.dart @@ -141,24 +141,30 @@ Future showTimeoutError(BuildContext context) async { await showServerError(I18N.of(context).timeout, I18N.of(context).noResponse); } -void showFormDialog(String title, {GlobalKey key, List fields, List actions, Function callback}) { +void showFormDialog(String title, {String acceptText, String cancelText, GlobalKey key, List fields, List actions, Function callback}) { BuildContext dialogContext; + if (acceptText == null) { + acceptText = I18N.of(OneContext().context).save; + } + + if (cancelText == null) { + cancelText = I18N.of(OneContext().context).cancel; + } + // Undefined actions = OK + Cancel if (actions == null) { actions = [ FlatButton( - child: Text(I18N.of(OneContext().context).cancel), + child: Text(cancelText), onPressed: () { - - print("cancel and close the dialog"); // Close the form Navigator.pop(dialogContext); } ), FlatButton( - child: Text(I18N.of(OneContext().context).save), + child: Text(acceptText), onPressed: () { if (key.currentState.validate()) { key.currentState.save(); diff --git a/lib/widget/stock_detail.dart b/lib/widget/stock_detail.dart index b260c220..40275aab 100644 --- a/lib/widget/stock_detail.dart +++ b/lib/widget/stock_detail.dart @@ -101,8 +101,6 @@ class _StockItemDisplayState extends RefreshableState { void _addStock() async { - Navigator.of(context).pop(); - double quantity = double.parse(_quantityController.text); _quantityController.clear(); @@ -121,14 +119,9 @@ class _StockItemDisplayState extends RefreshableState { showFormDialog( I18N.of(context).addStock, key: _addStockKey, - actions: [ - FlatButton( - child: Text(I18N.of(context).add), - onPressed: () { - if (_addStockKey.currentState.validate()) _addStock(); - }, - ) - ], + callback: () { + _addStock(); + }, fields: [ Text("Current stock: ${item.quantity}"), QuantityField( @@ -154,7 +147,6 @@ class _StockItemDisplayState extends RefreshableState { } void _removeStock() async { - Navigator.of(context).pop(); double quantity = double.parse(_quantityController.text); _quantityController.clear(); @@ -174,14 +166,9 @@ class _StockItemDisplayState extends RefreshableState { showFormDialog(I18N.of(context).removeStock, key: _removeStockKey, - actions: [ - FlatButton( - child: Text(I18N.of(context).remove), - onPressed: () { - if (_removeStockKey.currentState.validate()) _removeStock(); - }, - ) - ], + callback: () { + _removeStock(); + }, fields: [ Text("Current stock: ${item.quantity}"), QuantityField( @@ -201,8 +188,6 @@ class _StockItemDisplayState extends RefreshableState { void _countStock() async { - Navigator.of(context).pop(); - double quantity = double.parse(_quantityController.text); _quantityController.clear(); @@ -220,14 +205,10 @@ class _StockItemDisplayState extends RefreshableState { showFormDialog(I18N.of(context).countStock, key: _countStockKey, - actions: [ - FlatButton( - child: Text(I18N.of(context).count), - onPressed: () { - if (_countStockKey.currentState.validate()) _countStock(); - }, - ) - ], + callback: () { + _countStock(); + }, + acceptText: I18N.of(context).count, fields: [ QuantityField( label: I18N.of(context).countStock,