fixed cache
This commit is contained in:
parent
d3f708ae5e
commit
64516a7df2
7 changed files with 93 additions and 21 deletions
|
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:gap/gap.dart';
|
||||
import 'package:go_router/go_router.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/tables/ref_suppliers.dart';
|
||||
import 'package:pharmacy_mobile/widgets/buttonwithprogress_widget.dart';
|
||||
|
|
@ -22,26 +23,36 @@ class AddSupplierPage extends StatefulWidget {
|
|||
class _AddSupplierPageState extends State<AddSupplierPage> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _nameController = TextEditingController();
|
||||
final _refsuppliers = RefSuppliers();
|
||||
final _refSuppliers = RefSuppliers();
|
||||
|
||||
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 {
|
||||
setState(() => _isLoading = true);
|
||||
|
||||
try {
|
||||
if (await InternetConnectionChecker.instance.hasConnection) {
|
||||
final existing = await checkExisting(_refsuppliers, _nameController);
|
||||
final existing = await checkExisting(_refSuppliers, _nameController);
|
||||
|
||||
if (existing && mounted) {
|
||||
showNotification(context, 'Supplier already listed', false);
|
||||
return;
|
||||
}
|
||||
|
||||
final post = await _refsuppliers.postSupplier(_nameController.text);
|
||||
print('post: $post');
|
||||
final post = await _refSuppliers.postSupplier(_nameController.text);
|
||||
|
||||
if (post && mounted) {
|
||||
_getSupplierListCache();
|
||||
showNotification(context, 'Supplier added to list', true);
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue