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/distributorlist/functions/cache_setdistributorlist.dart';
|
||||
import 'package:pharmacy_mobile/functions/checkexisting_function.dart';
|
||||
import 'package:pharmacy_mobile/tables/ref_distributors.dart';
|
||||
import 'package:pharmacy_mobile/widgets/buttonwithprogress_widget.dart';
|
||||
|
|
@ -23,25 +24,36 @@ class _AddDistributorPageState extends State<AddDistributorPage> {
|
|||
final _formKey = GlobalKey<FormState>();
|
||||
final _nameController = TextEditingController();
|
||||
final _addressController = TextEditingController();
|
||||
final _refdistributors = RefDistributors();
|
||||
final _refDistributors = RefDistributors();
|
||||
|
||||
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 {
|
||||
setState(() => _isLoading = true);
|
||||
|
||||
try {
|
||||
if (await InternetConnectionChecker.instance.hasConnection) {
|
||||
final existing = await checkExisting(_refdistributors, _nameController);
|
||||
final existing = await checkExisting(_refDistributors, _nameController);
|
||||
|
||||
if (existing && mounted) {
|
||||
showNotification(context, 'Distributor already listed', false);
|
||||
return;
|
||||
}
|
||||
|
||||
final post = await _refdistributors.postDistributor(_nameController.text, _addressController.text);
|
||||
final post = await _refDistributors.postDistributor(_nameController.text, _addressController.text);
|
||||
|
||||
if (post && mounted) {
|
||||
_getDistributorListCache();
|
||||
showNotification(context, 'Distributor added to list', true);
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue