fixed cache
This commit is contained in:
parent
d3f708ae5e
commit
64516a7df2
7 changed files with 93 additions and 21 deletions
|
|
@ -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/categorylist/functions/cache_setcategorylist.dart';
|
||||||
import 'package:pharmacy_mobile/functions/checkexisting_function.dart';
|
import 'package:pharmacy_mobile/functions/checkexisting_function.dart';
|
||||||
import 'package:pharmacy_mobile/tables/ref_categories.dart';
|
import 'package:pharmacy_mobile/tables/ref_categories.dart';
|
||||||
import 'package:pharmacy_mobile/widgets/buttonwithprogress_widget.dart';
|
import 'package:pharmacy_mobile/widgets/buttonwithprogress_widget.dart';
|
||||||
|
|
@ -23,8 +24,19 @@ class _AddCategoryPageState extends State<AddCategoryPage> {
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
final _categoryController = TextEditingController();
|
final _categoryController = TextEditingController();
|
||||||
final _refCategories = RefCategories();
|
final _refCategories = RefCategories();
|
||||||
|
|
||||||
bool _isLoading = false;
|
bool _isLoading = false;
|
||||||
|
|
||||||
|
Future<void> _getCategoryListCache() async {
|
||||||
|
final categoryList = await _refCategories.getList();
|
||||||
|
|
||||||
|
if (categoryList.isNotEmpty) {
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
final setCache = await cacheSetCategoryList(context, categoryList);
|
||||||
|
if (!setCache) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _saveCategory() async {
|
void _saveCategory() async {
|
||||||
setState(() => _isLoading = true);
|
setState(() => _isLoading = true);
|
||||||
|
|
||||||
|
|
@ -40,6 +52,7 @@ class _AddCategoryPageState extends State<AddCategoryPage> {
|
||||||
final post = await _refCategories.postCategory(_categoryController.text.toUpperCase());
|
final post = await _refCategories.postCategory(_categoryController.text.toUpperCase());
|
||||||
|
|
||||||
if (post && mounted) {
|
if (post && mounted) {
|
||||||
|
_getCategoryListCache();
|
||||||
showNotification(context, 'Category saved', true);
|
showNotification(context, 'Category saved', true);
|
||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:gap/gap.dart';
|
import 'package:gap/gap.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.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/distributorlist/functions/cache_setdistributorlist.dart';
|
||||||
import 'package:pharmacy_mobile/functions/checkexisting_function.dart';
|
import 'package:pharmacy_mobile/functions/checkexisting_function.dart';
|
||||||
import 'package:pharmacy_mobile/tables/ref_distributors.dart';
|
import 'package:pharmacy_mobile/tables/ref_distributors.dart';
|
||||||
import 'package:pharmacy_mobile/widgets/buttonwithprogress_widget.dart';
|
import 'package:pharmacy_mobile/widgets/buttonwithprogress_widget.dart';
|
||||||
|
|
@ -23,25 +24,36 @@ class _AddDistributorPageState extends State<AddDistributorPage> {
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
final _nameController = TextEditingController();
|
final _nameController = TextEditingController();
|
||||||
final _addressController = TextEditingController();
|
final _addressController = TextEditingController();
|
||||||
final _refdistributors = RefDistributors();
|
final _refDistributors = RefDistributors();
|
||||||
|
|
||||||
late bool _isLoading = false;
|
late bool _isLoading = false;
|
||||||
|
|
||||||
|
Future<void> _getDistributorListCache() async {
|
||||||
|
final distributorList = await _refDistributors.getList();
|
||||||
|
|
||||||
|
if (distributorList.isNotEmpty) {
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
final setCache = await cacheSetDistributorList(context, distributorList);
|
||||||
|
if (!setCache) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _saveDistributor() async {
|
void _saveDistributor() async {
|
||||||
setState(() => _isLoading = true);
|
setState(() => _isLoading = true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (await InternetConnectionChecker.instance.hasConnection) {
|
if (await InternetConnectionChecker.instance.hasConnection) {
|
||||||
final existing = await checkExisting(_refdistributors, _nameController);
|
final existing = await checkExisting(_refDistributors, _nameController);
|
||||||
|
|
||||||
if (existing && mounted) {
|
if (existing && mounted) {
|
||||||
showNotification(context, 'Distributor already listed', false);
|
showNotification(context, 'Distributor already listed', false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final post = await _refdistributors.postDistributor(_nameController.text, _addressController.text);
|
final post = await _refDistributors.postDistributor(_nameController.text, _addressController.text);
|
||||||
|
|
||||||
if (post && mounted) {
|
if (post && mounted) {
|
||||||
|
_getDistributorListCache();
|
||||||
showNotification(context, 'Distributor added to list', true);
|
showNotification(context, 'Distributor added to list', true);
|
||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import 'package:gap/gap.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.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/categorylist/functions/cache_getcategorylist.dart';
|
import 'package:pharmacy_mobile/blocs/caches/categorylist/functions/cache_getcategorylist.dart';
|
||||||
|
import 'package:pharmacy_mobile/blocs/caches/genericlist/functions/cache_setgenericlist.dart';
|
||||||
import 'package:pharmacy_mobile/functions/checkexisting_function.dart';
|
import 'package:pharmacy_mobile/functions/checkexisting_function.dart';
|
||||||
import 'package:pharmacy_mobile/tables/ref_categories.dart';
|
import 'package:pharmacy_mobile/tables/ref_categories.dart';
|
||||||
import 'package:pharmacy_mobile/tables/ref_generic_names.dart';
|
import 'package:pharmacy_mobile/tables/ref_generic_names.dart';
|
||||||
|
|
@ -36,6 +37,16 @@ class _AddGenericsPageState extends State<AddGenericsPage> {
|
||||||
late String _selectedCategory = '';
|
late String _selectedCategory = '';
|
||||||
late String _categoryUUID = '';
|
late String _categoryUUID = '';
|
||||||
|
|
||||||
|
Future<void> _getGenericListCache() async {
|
||||||
|
final genericNameList = await _refGenericNames.getList();
|
||||||
|
|
||||||
|
if (genericNameList.isNotEmpty) {
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
final setCache = await cacheSetGenericList(context, genericNameList);
|
||||||
|
if (!setCache) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _getList() async {
|
void _getList() async {
|
||||||
_categoryList = await _refCategories.getList();
|
_categoryList = await _refCategories.getList();
|
||||||
|
|
||||||
|
|
@ -94,6 +105,7 @@ class _AddGenericsPageState extends State<AddGenericsPage> {
|
||||||
final existing = await checkExisting(_refGenericNames, _nameController);
|
final existing = await checkExisting(_refGenericNames, _nameController);
|
||||||
|
|
||||||
if (existing && mounted) {
|
if (existing && mounted) {
|
||||||
|
_getGenericListCache();
|
||||||
showNotification(context, 'Generic Name already existing', false);
|
showNotification(context, 'Generic Name already existing', false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:gap/gap.dart';
|
import 'package:gap/gap.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.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/manufacturerlist/functions/cache_setmanufacturerlist.dart';
|
||||||
import 'package:pharmacy_mobile/functions/checkexisting_function.dart';
|
import 'package:pharmacy_mobile/functions/checkexisting_function.dart';
|
||||||
import 'package:pharmacy_mobile/tables/ref_manufacturers.dart';
|
import 'package:pharmacy_mobile/tables/ref_manufacturers.dart';
|
||||||
import 'package:pharmacy_mobile/widgets/buttonwithprogress_widget.dart';
|
import 'package:pharmacy_mobile/widgets/buttonwithprogress_widget.dart';
|
||||||
|
|
@ -27,6 +28,16 @@ class _AddManufacturerPageState extends State<AddManufacturerPage> {
|
||||||
|
|
||||||
late bool _isLoading = false;
|
late bool _isLoading = false;
|
||||||
|
|
||||||
|
Future<void> _getManufacturerListCache() async {
|
||||||
|
final manufacturerList = await _refManufacturers.getList();
|
||||||
|
|
||||||
|
if (manufacturerList.isNotEmpty) {
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
final setCache = await cacheSetManufacturerList(context, manufacturerList);
|
||||||
|
if (!setCache) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _saveManufacturer() async {
|
void _saveManufacturer() async {
|
||||||
setState(() => _isLoading = true);
|
setState(() => _isLoading = true);
|
||||||
|
|
||||||
|
|
@ -42,6 +53,7 @@ class _AddManufacturerPageState extends State<AddManufacturerPage> {
|
||||||
final post = await _refManufacturers.postManufacturer(_nameController.text, _addressController.text);
|
final post = await _refManufacturers.postManufacturer(_nameController.text, _addressController.text);
|
||||||
|
|
||||||
if (post && mounted) {
|
if (post && mounted) {
|
||||||
|
_getManufacturerListCache();
|
||||||
showNotification(context, 'Manufacturer added to list', true);
|
showNotification(context, 'Manufacturer added to list', true);
|
||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
||||||
late bool imageUploaded = false;
|
late bool imageUploaded = false;
|
||||||
late String imageUrl = '';
|
late String imageUrl = '';
|
||||||
late bool uploaded = false;
|
late bool uploaded = false;
|
||||||
|
late String imageUUID = '';
|
||||||
|
|
||||||
Future<void> _getGenerics() async {
|
Future<void> _getGenerics() async {
|
||||||
_genericNameList = await _refGenericNames.getList();
|
_genericNameList = await _refGenericNames.getList();
|
||||||
|
|
@ -174,12 +175,6 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
||||||
final distributors = await _getDistributorsCache();
|
final distributors = await _getDistributorsCache();
|
||||||
final suppliers = await _getSuppliersCache();
|
final suppliers = await _getSuppliersCache();
|
||||||
|
|
||||||
print('generics: $generics');
|
|
||||||
print('types: $types');
|
|
||||||
print('manufacturers: $manufacturers');
|
|
||||||
print('distributors: $distributors');
|
|
||||||
print('suppliers: $suppliers');
|
|
||||||
|
|
||||||
if (!generics || !types || !manufacturers || !distributors || !suppliers) {
|
if (!generics || !types || !manufacturers || !distributors || !suppliers) {
|
||||||
if (await InternetConnectionChecker.instance.hasConnection) {
|
if (await InternetConnectionChecker.instance.hasConnection) {
|
||||||
await _getGenerics();
|
await _getGenerics();
|
||||||
|
|
@ -268,6 +263,7 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
||||||
try {
|
try {
|
||||||
// final String encrpytedBarcode = await encrypt(_barcodeController.text);
|
// final String encrpytedBarcode = await encrypt(_barcodeController.text);
|
||||||
final String encrpytedBarcode = _barcodeController.text;
|
final String encrpytedBarcode = _barcodeController.text;
|
||||||
|
uuid = Uuid().v4();
|
||||||
|
|
||||||
if (await InternetConnectionChecker.instance.hasConnection) {
|
if (await InternetConnectionChecker.instance.hasConnection) {
|
||||||
final medName = _nameController.text;
|
final medName = _nameController.text;
|
||||||
|
|
@ -277,8 +273,12 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
||||||
final medDistributorUUID = await _refDistributors.getUUID(_selectedDistributor);
|
final medDistributorUUID = await _refDistributors.getUUID(_selectedDistributor);
|
||||||
final medSupplierUUID = await _refSuppliers.getUUID(_selectedSupplier);
|
final medSupplierUUID = await _refSuppliers.getUUID(_selectedSupplier);
|
||||||
|
|
||||||
|
if (imageUUID.isEmpty) {
|
||||||
|
imageUUID = '73105ee3-74bd-40ea-9434-f8176a980b43';
|
||||||
|
}
|
||||||
|
|
||||||
final posted = await _refMedicines.postMedicine(uuid, medName, medManufacturerUUID, medGenericUUID, medTypeUUID,
|
final posted = await _refMedicines.postMedicine(uuid, medName, medManufacturerUUID, medGenericUUID, medTypeUUID,
|
||||||
encrpytedBarcode, medDistributorUUID, medSupplierUUID);
|
encrpytedBarcode, medDistributorUUID, medSupplierUUID, imageUUID);
|
||||||
|
|
||||||
if (posted) {
|
if (posted) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
|
|
@ -315,7 +315,7 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
||||||
final imageBytes = await image!.readAsBytes();
|
final imageBytes = await image!.readAsBytes();
|
||||||
final webpImage = await _webpConvert(imageBytes);
|
final webpImage = await _webpConvert(imageBytes);
|
||||||
|
|
||||||
uuid = imageName;
|
imageUUID = imageName;
|
||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
uploaded = await _storage.uploadImage(context, storageName, webpImage, '$imageName.webp');
|
uploaded = await _storage.uploadImage(context, storageName, webpImage, '$imageName.webp');
|
||||||
|
|
@ -466,12 +466,12 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
||||||
// const Center(child: CircularProgressIndicator(color: Colors.white))
|
// const Center(child: CircularProgressIndicator(color: Colors.white))
|
||||||
// else
|
// else
|
||||||
// ButtonWidget(text: 'Save Medicine', onPressed: _saveMedicine)
|
// ButtonWidget(text: 'Save Medicine', onPressed: _saveMedicine)
|
||||||
if (uploaded)
|
// if (uploaded)
|
||||||
ButtonWithProgressWidget(
|
ButtonWithProgressWidget(
|
||||||
trigger: _isLoading,
|
trigger: _isLoading,
|
||||||
progressText: 'Adding Medicine',
|
progressText: 'Adding Medicine',
|
||||||
buttonText: 'Save',
|
buttonText: 'Save',
|
||||||
onPressed: _saveMedicine)
|
onPressed: _saveMedicine)
|
||||||
])
|
])
|
||||||
])))
|
])))
|
||||||
]))));
|
]))));
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:gap/gap.dart';
|
import 'package:gap/gap.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.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/supplierlist/functions/cache_setsupplierlist.dart';
|
||||||
import 'package:pharmacy_mobile/functions/checkexisting_function.dart';
|
import 'package:pharmacy_mobile/functions/checkexisting_function.dart';
|
||||||
import 'package:pharmacy_mobile/tables/ref_suppliers.dart';
|
import 'package:pharmacy_mobile/tables/ref_suppliers.dart';
|
||||||
import 'package:pharmacy_mobile/widgets/buttonwithprogress_widget.dart';
|
import 'package:pharmacy_mobile/widgets/buttonwithprogress_widget.dart';
|
||||||
|
|
@ -22,26 +23,36 @@ class AddSupplierPage extends StatefulWidget {
|
||||||
class _AddSupplierPageState extends State<AddSupplierPage> {
|
class _AddSupplierPageState extends State<AddSupplierPage> {
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
final _nameController = TextEditingController();
|
final _nameController = TextEditingController();
|
||||||
final _refsuppliers = RefSuppliers();
|
final _refSuppliers = RefSuppliers();
|
||||||
|
|
||||||
late bool _isLoading = false;
|
late bool _isLoading = false;
|
||||||
|
|
||||||
|
Future<void> _getSupplierListCache() async {
|
||||||
|
final supplierList = await _refSuppliers.getList();
|
||||||
|
|
||||||
|
if (supplierList.isNotEmpty) {
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
final setCache = await cacheSetSupplierList(context, supplierList);
|
||||||
|
if (!setCache) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _saveSupplier() async {
|
void _saveSupplier() async {
|
||||||
setState(() => _isLoading = true);
|
setState(() => _isLoading = true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (await InternetConnectionChecker.instance.hasConnection) {
|
if (await InternetConnectionChecker.instance.hasConnection) {
|
||||||
final existing = await checkExisting(_refsuppliers, _nameController);
|
final existing = await checkExisting(_refSuppliers, _nameController);
|
||||||
|
|
||||||
if (existing && mounted) {
|
if (existing && mounted) {
|
||||||
showNotification(context, 'Supplier already listed', false);
|
showNotification(context, 'Supplier already listed', false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final post = await _refsuppliers.postSupplier(_nameController.text);
|
final post = await _refSuppliers.postSupplier(_nameController.text);
|
||||||
print('post: $post');
|
|
||||||
|
|
||||||
if (post && mounted) {
|
if (post && mounted) {
|
||||||
|
_getSupplierListCache();
|
||||||
showNotification(context, 'Supplier added to list', true);
|
showNotification(context, 'Supplier added to list', true);
|
||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import 'package:gap/gap.dart';
|
import 'package:gap/gap.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.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/typelist/functions/cache_settypelist.dart';
|
||||||
import 'package:pharmacy_mobile/functions/checkexisting_function.dart';
|
import 'package:pharmacy_mobile/functions/checkexisting_function.dart';
|
||||||
import 'package:pharmacy_mobile/tables/ref_types.dart';
|
import 'package:pharmacy_mobile/tables/ref_types.dart';
|
||||||
import 'package:pharmacy_mobile/widgets/buttonwithprogress_widget.dart';
|
import 'package:pharmacy_mobile/widgets/buttonwithprogress_widget.dart';
|
||||||
|
|
@ -26,6 +27,16 @@ class _AddTypePageState extends State<AddTypePage> {
|
||||||
|
|
||||||
bool _isLoading = false;
|
bool _isLoading = false;
|
||||||
|
|
||||||
|
Future<void> _getTypeListCache() async {
|
||||||
|
final typeList = await _refTypes.getList();
|
||||||
|
|
||||||
|
if (typeList.isNotEmpty) {
|
||||||
|
// ignore: use_build_context_synchronously
|
||||||
|
final setCache = await cacheSetTypeList(context, typeList);
|
||||||
|
if (!setCache) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _saveType() async {
|
void _saveType() async {
|
||||||
setState(() => _isLoading = true);
|
setState(() => _isLoading = true);
|
||||||
try {
|
try {
|
||||||
|
|
@ -40,6 +51,7 @@ class _AddTypePageState extends State<AddTypePage> {
|
||||||
final post = await _refTypes.postType(_typeController.text);
|
final post = await _refTypes.postType(_typeController.text);
|
||||||
|
|
||||||
if (post && mounted) {
|
if (post && mounted) {
|
||||||
|
_getTypeListCache();
|
||||||
showNotification(context, 'Medicine type saved', true);
|
showNotification(context, 'Medicine type saved', true);
|
||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue