add cache for medicines

This commit is contained in:
Patrick Alvin Alcala 2025-03-21 15:33:00 +08:00
parent 518415aa4e
commit 92df0af895
12 changed files with 110 additions and 14 deletions

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/medicinelist/functions/cache_getmedicinelist.dart';
import 'package:pharmacy_mobile/functions/barcode_scan_function.dart';
import 'package:pharmacy_mobile/functions/checkresult_function.dart';
import 'package:pharmacy_mobile/tables/ref_medicines.dart';
@ -49,17 +50,37 @@ class _AddStockPageState extends State<AddStockPage> with WidgetsBindingObserver
});
}
void autoRun() async {
if (await InternetConnectionChecker.instance.hasConnection) {
_getMedicines();
} else {
if (mounted) {
showNotification(context, 'Error: No Internet Connection', false);
Future<bool> _getMedicinesCache() async {
final cache = await cacheGetMedicineList(context);
print('cache: $cache');
WidgetsBinding.instance.addPostFrameCallback((_) {
context.push('/main');
});
if (cache.isNotEmpty) {
_medicineList = cache;
return true;
} else {
return false;
}
}
void autoRun() async {
final medicines = await _getMedicinesCache();
print('medicines: $medicines');
if (!medicines) {
if (await InternetConnectionChecker.instance.hasConnection) {
_getMedicines();
} else {
if (mounted) {
showNotification(context, 'Error: No Internet Connection', false);
WidgetsBinding.instance.addPostFrameCallback((_) {
context.push('/main');
});
}
}
} else {
setState(() {});
}
}