add cache for stocks

This commit is contained in:
Patrick Alvin Alcala 2025-03-24 11:50:39 +08:00
parent 92df0af895
commit de5a7c66a3
11 changed files with 134 additions and 3 deletions

View file

@ -1,6 +1,9 @@
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_getstocklist.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';
import 'package:pharmacy_mobile/widgets/button_widget.dart';
import 'package:pharmacy_mobile/widgets/dropdown_widget.dart';
@ -48,6 +51,17 @@ class _DeleteStockPageState extends State<DeleteStockPage> {
}
}
// Future<bool> _getStocksCache() async {
// final cache = await cacheGetStockList(context);
// if (cache.isNotEmpty) {
// _stockList = cache;
// return true;
// } else {
// return false;
// }
// }
void _updateStock(dynamic stock) {
_selectedStock = stock;
_getQuantity(_selectedStock);
@ -98,9 +112,26 @@ class _DeleteStockPageState extends State<DeleteStockPage> {
}
}
void autoRun() async {
final cache = await getListCache(context, 'stock');
if (cache.isEmpty) {
if (await InternetConnectionChecker.instance.hasConnection) {
_getStocks();
} else {
// ignore: use_build_context_synchronously
showNotification(context, 'Error: No Internet Connection', false);
}
} else {
setState(() {
_stockList = cache;
});
}
}
@override
void initState() {
_getStocks();
autoRun();
super.initState();
}