fix cache error
This commit is contained in:
parent
efe74f9711
commit
5283e7a6c6
2 changed files with 21 additions and 9 deletions
|
|
@ -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/ref_medicines.dart';
|
||||||
import 'package:pharmacy_mobile/tables/stocks.dart';
|
import 'package:pharmacy_mobile/tables/stocks.dart';
|
||||||
import 'package:pharmacy_mobile/widgets/button_widget.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/datepicker_widget.dart';
|
||||||
import 'package:pharmacy_mobile/widgets/dropdown_widget.dart';
|
import 'package:pharmacy_mobile/widgets/dropdown_widget.dart';
|
||||||
import 'package:pharmacy_mobile/widgets/dropdown_wrappermulti_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),
|
const Gap(16),
|
||||||
InputFormWidget(label: 'Price', controller: _priceController),
|
InputFormWidget(label: 'Price', controller: _priceController),
|
||||||
const Gap(32),
|
const Gap(32),
|
||||||
if (_isLoading)
|
ButtonWithProgressWidget(
|
||||||
const Center(child: CircularProgressIndicator(color: Colors.white))
|
trigger: _isLoading, progressText: 'Adding Stock', buttonText: 'Save', onPressed: _saveStock)
|
||||||
else
|
|
||||||
ButtonWidget(text: 'Add Stock', onPressed: _saveStock),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:gap/gap.dart';
|
import 'package:gap/gap.dart';
|
||||||
import 'package:internet_connection_checker/internet_connection_checker.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/checkresult_function.dart';
|
||||||
import 'package:pharmacy_mobile/functions/getlist_cache_function.dart';
|
import 'package:pharmacy_mobile/functions/getlist_cache_function.dart';
|
||||||
import 'package:pharmacy_mobile/tables/stocks.dart';
|
import 'package:pharmacy_mobile/tables/stocks.dart';
|
||||||
|
|
@ -55,19 +56,29 @@ class _DeleteStockPageState extends State<DeleteStockPage> {
|
||||||
_getQuantity(_selectedStock);
|
_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 {
|
void _saveDeletion() async {
|
||||||
final newQuantity = _serverQuantity - double.parse(_quantityController.text);
|
final newQuantity = _serverQuantity - double.parse(_quantityController.text);
|
||||||
final newQuantityFixed = newQuantity.toStringAsFixed(0);
|
final newQuantityFixed = newQuantity.toStringAsFixed(0);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_stocks.updateStock(_selectedUUID, 'quantity', newQuantityFixed);
|
_stocks.updateStock(_selectedUUID, 'quantity', newQuantityFixed);
|
||||||
|
await _getStockListCache();
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
showNotification(context, '$_selectedStock updated', true);
|
showNotification(context, '$_selectedStock updated', true);
|
||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
if (mounted) {
|
if (mounted) context.pop();
|
||||||
context.pop();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
@ -90,6 +101,8 @@ class _DeleteStockPageState extends State<DeleteStockPage> {
|
||||||
setState(() {});
|
setState(() {});
|
||||||
} else {
|
} else {
|
||||||
_noStock = false;
|
_noStock = false;
|
||||||
|
print('quantity: $quantity');
|
||||||
|
print('serverQuantity: $_serverQuantity');
|
||||||
if (double.parse(quantity) > _serverQuantity) {
|
if (double.parse(quantity) > _serverQuantity) {
|
||||||
_aboveQuantity = true;
|
_aboveQuantity = true;
|
||||||
setState(() {});
|
setState(() {});
|
||||||
|
|
@ -169,7 +182,7 @@ class _DeleteStockPageState extends State<DeleteStockPage> {
|
||||||
if (_noStock)
|
if (_noStock)
|
||||||
const WarningWidget(
|
const WarningWidget(
|
||||||
text: 'Removing Disabled',
|
text: 'Removing Disabled',
|
||||||
warning: 'Quantity is above sssss',
|
warning: 'Stock is empty',
|
||||||
)
|
)
|
||||||
else if (_aboveQuantity)
|
else if (_aboveQuantity)
|
||||||
const WarningWidget(
|
const WarningWidget(
|
||||||
|
|
@ -177,7 +190,7 @@ class _DeleteStockPageState extends State<DeleteStockPage> {
|
||||||
warning: 'Quantity is above stocked',
|
warning: 'Quantity is above stocked',
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
ButtonWidget(text: 'Remove Stock', onPressed: _saveDeletion)
|
ButtonWidget(text: 'Remove', onPressed: _saveDeletion)
|
||||||
])
|
])
|
||||||
],
|
],
|
||||||
)))
|
)))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue