fix saving of stocks
This commit is contained in:
parent
e8d0f213e9
commit
efe74f9711
2 changed files with 20 additions and 4 deletions
|
|
@ -31,7 +31,7 @@ class _AddStockPageState extends State<AddStockPage> with WidgetsBindingObserver
|
||||||
final _refMedicines = RefMedicines();
|
final _refMedicines = RefMedicines();
|
||||||
final _quantityController = TextEditingController();
|
final _quantityController = TextEditingController();
|
||||||
final _dateController = TextEditingController();
|
final _dateController = TextEditingController();
|
||||||
// final _barcodeController = TextEditingController();
|
final _priceController = TextEditingController();
|
||||||
final _stocks = Stocks();
|
final _stocks = Stocks();
|
||||||
|
|
||||||
late bool _isLoading = false;
|
late bool _isLoading = false;
|
||||||
|
|
@ -94,8 +94,20 @@ class _AddStockPageState extends State<AddStockPage> with WidgetsBindingObserver
|
||||||
final stockNameUUID = await _refMedicines.getUUID(_selectedMedicine);
|
final stockNameUUID = await _refMedicines.getUUID(_selectedMedicine);
|
||||||
final stockQuantity = _quantityController.text;
|
final stockQuantity = _quantityController.text;
|
||||||
final stockExpiration = _dateController.text;
|
final stockExpiration = _dateController.text;
|
||||||
|
final price = _priceController.text;
|
||||||
|
|
||||||
await _stocks.postStock(stockNameUUID, stockExpiration, stockQuantity);
|
final success = await _stocks.postStock(stockNameUUID, stockExpiration, stockQuantity, price);
|
||||||
|
if (success) {
|
||||||
|
if (mounted) {
|
||||||
|
showNotification(context, 'Stock added successfully', true);
|
||||||
|
setState(() => _isLoading = false);
|
||||||
|
context.pop();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (mounted) {
|
||||||
|
showNotification(context, 'Error: Stock not added', false);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
showNotification(context, 'Error: No Internet Connection', false);
|
showNotification(context, 'Error: No Internet Connection', false);
|
||||||
|
|
@ -136,6 +148,7 @@ class _AddStockPageState extends State<AddStockPage> with WidgetsBindingObserver
|
||||||
_selectedMedicine = '';
|
_selectedMedicine = '';
|
||||||
_quantityController.dispose();
|
_quantityController.dispose();
|
||||||
_dateController.dispose();
|
_dateController.dispose();
|
||||||
|
_priceController.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -220,6 +233,8 @@ class _AddStockPageState extends State<AddStockPage> with WidgetsBindingObserver
|
||||||
controller: _dateController,
|
controller: _dateController,
|
||||||
value: selectedDate,
|
value: selectedDate,
|
||||||
),
|
),
|
||||||
|
const Gap(16),
|
||||||
|
InputFormWidget(label: 'Price', controller: _priceController),
|
||||||
const Gap(32),
|
const Gap(32),
|
||||||
if (_isLoading)
|
if (_isLoading)
|
||||||
const Center(child: CircularProgressIndicator(color: Colors.white))
|
const Center(child: CircularProgressIndicator(color: Colors.white))
|
||||||
|
|
|
||||||
|
|
@ -69,14 +69,15 @@ class Stocks {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> postStock(String muuid, String name, String quantity) async {
|
Future<bool> postStock(String muuid, String name, String quantity, String price) async {
|
||||||
final uuid = Uuid().v4();
|
final uuid = Uuid().v4();
|
||||||
|
|
||||||
final stock = {
|
final stock = {
|
||||||
'stock_uuid': uuid,
|
'stocks_uuid': uuid,
|
||||||
'ref_medicines_uuid': muuid,
|
'ref_medicines_uuid': muuid,
|
||||||
'expiration_date': name,
|
'expiration_date': name,
|
||||||
'quantity': quantity,
|
'quantity': quantity,
|
||||||
|
'price': price
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue