fix cache error

This commit is contained in:
Patrick Alvin Alcala 2025-04-08 14:07:42 +08:00
parent efe74f9711
commit 5283e7a6c6
2 changed files with 21 additions and 9 deletions

View file

@ -7,6 +7,7 @@ import 'package:pharmacy_mobile/functions/checkresult_function.dart';
import 'package:pharmacy_mobile/tables/ref_medicines.dart';
import 'package:pharmacy_mobile/tables/stocks.dart';
import 'package:pharmacy_mobile/widgets/button_widget.dart';
import 'package:pharmacy_mobile/widgets/buttonwithprogress_widget.dart';
import 'package:pharmacy_mobile/widgets/datepicker_widget.dart';
import 'package:pharmacy_mobile/widgets/dropdown_widget.dart';
import 'package:pharmacy_mobile/widgets/dropdown_wrappermulti_widget.dart';
@ -236,10 +237,8 @@ class _AddStockPageState extends State<AddStockPage> with WidgetsBindingObserver
const Gap(16),
InputFormWidget(label: 'Price', controller: _priceController),
const Gap(32),
if (_isLoading)
const Center(child: CircularProgressIndicator(color: Colors.white))
else
ButtonWidget(text: 'Add Stock', onPressed: _saveStock),
ButtonWithProgressWidget(
trigger: _isLoading, progressText: 'Adding Stock', buttonText: 'Save', onPressed: _saveStock)
],
),
),

View file

@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:internet_connection_checker/internet_connection_checker.dart';
import 'package:pharmacy_mobile/blocs/caches/stocklist/functions/cache_setstocklist.dart';
import 'package:pharmacy_mobile/functions/checkresult_function.dart';
import 'package:pharmacy_mobile/functions/getlist_cache_function.dart';
import 'package:pharmacy_mobile/tables/stocks.dart';
@ -55,19 +56,29 @@ class _DeleteStockPageState extends State<DeleteStockPage> {
_getQuantity(_selectedStock);
}
Future<void> _getStockListCache() async {
final stockList = await _stocks.getList();
if (stockList.isNotEmpty) {
// ignore: use_build_context_synchronously
final setCache = await cacheSetStockList(context, stockList);
if (!setCache) {}
}
}
void _saveDeletion() async {
final newQuantity = _serverQuantity - double.parse(_quantityController.text);
final newQuantityFixed = newQuantity.toStringAsFixed(0);
try {
_stocks.updateStock(_selectedUUID, 'quantity', newQuantityFixed);
await _getStockListCache();
if (mounted) {
showNotification(context, '$_selectedStock updated', true);
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) {
context.pop();
}
if (mounted) context.pop();
});
}
} catch (e) {
@ -90,6 +101,8 @@ class _DeleteStockPageState extends State<DeleteStockPage> {
setState(() {});
} else {
_noStock = false;
print('quantity: $quantity');
print('serverQuantity: $_serverQuantity');
if (double.parse(quantity) > _serverQuantity) {
_aboveQuantity = true;
setState(() {});
@ -169,7 +182,7 @@ class _DeleteStockPageState extends State<DeleteStockPage> {
if (_noStock)
const WarningWidget(
text: 'Removing Disabled',
warning: 'Quantity is above sssss',
warning: 'Stock is empty',
)
else if (_aboveQuantity)
const WarningWidget(
@ -177,7 +190,7 @@ class _DeleteStockPageState extends State<DeleteStockPage> {
warning: 'Quantity is above stocked',
)
else
ButtonWidget(text: 'Remove Stock', onPressed: _saveDeletion)
ButtonWidget(text: 'Remove', onPressed: _saveDeletion)
])
],
)))