added cache for distributors

This commit is contained in:
Patrick Alvin Alcala 2025-04-22 11:33:46 +08:00
parent 77fae74302
commit f2fdfc644a
6 changed files with 70 additions and 4 deletions

View file

@ -0,0 +1,14 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pharmacy_mobile/blocs/caches/distributorlist/distributorlist_cache_event.dart';
import 'package:pharmacy_mobile/blocs/caches/distributorlist/distributorlist_cache_state.dart';
class DistributorListBloc extends Bloc<DistributorListCacheEvent, DistributorListCacheState> {
DistributorListBloc() : super(DistributorListCacheState([])) {
on<DistributorListCacheSet>((event, emit) {
emit(DistributorListCacheState(event.value));
});
on<DistributorListCacheGet>((event, emit) {
emit(state);
});
}
}

View file

@ -0,0 +1,8 @@
abstract class DistributorListCacheEvent {}
class DistributorListCacheSet extends DistributorListCacheEvent {
final List value;
DistributorListCacheSet(this.value);
}
class DistributorListCacheGet extends DistributorListCacheEvent {}

View file

@ -0,0 +1,5 @@
class DistributorListCacheState {
final List value;
DistributorListCacheState(this.value);
}

View file

@ -0,0 +1,14 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pharmacy_mobile/blocs/caches/distributorlist/distributorlist_cache_bloc.dart';
import 'package:pharmacy_mobile/blocs/caches/distributorlist/distributorlist_cache_event.dart';
Future<List> cacheGetDistributorList(BuildContext context) async {
try {
final distributorListCache = context.read<DistributorListBloc>();
distributorListCache.add(DistributorListCacheGet());
return distributorListCache.state.value;
} catch (e) {
return [];
}
}

View file

@ -0,0 +1,14 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:pharmacy_mobile/blocs/caches/distributorlist/distributorlist_cache_bloc.dart';
import 'package:pharmacy_mobile/blocs/caches/distributorlist/distributorlist_cache_event.dart';
Future<bool> cacheSetDistributorList(BuildContext context, List value) async {
try {
final distributorListCache = context.read<DistributorListBloc>();
distributorListCache.add(DistributorListCacheSet(value));
return true;
} catch (e) {
return false;
}
}

View file

@ -63,7 +63,7 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
late List _supplierList = [];
late String _selectedManufacturer = '';
late String _selectedDistributor = '';
late final String _selectedSupplier = '';
late String _selectedSupplier = '';
late String uuid = '';
late bool imageUploaded = false;
late String imageUrl = '';
@ -206,6 +206,10 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
_selectedDistributor = distributor;
}
void _updateSupplier(dynamic supplier) {
_selectedSupplier = supplier;
}
Future<void> _scanBarcode() async {
// String? barcode = await SimpleBarcodeScanner.scanBarcode(
// context,
@ -238,8 +242,8 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
final medDistributorUUID = await _refDistributors.getUUID(_selectedDistributor);
final medSupplierUUID = await _refSuppliers.getUUID(_selectedSupplier);
final posted = await _refMedicines.postMedicine(
uuid, medName, medManufacturerUUID, medGenericUUID, medTypeUUID, encrpytedBarcode, medDistributorUUID, medSupplierUUID);
final posted = await _refMedicines.postMedicine(uuid, medName, medManufacturerUUID, medGenericUUID, medTypeUUID,
encrpytedBarcode, medDistributorUUID, medSupplierUUID);
if (posted) {
if (mounted) {
@ -357,7 +361,7 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
color: 'green',
child: Form(
key: _formKey,
child: DropdownWrapperMultiWidget(list: _genericNameList, text: 'Data', children: [
child: DropdownWrapperMultiWidget(list: _supplierList, text: 'Data', children: [
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
InputFormWidget(label: 'Name', controller: _nameController),
const Gap(16),
@ -394,6 +398,13 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
onChanged: _updateDistributor,
),
const Gap(16),
DropDownWidget(
label: 'Supplier',
list: _supplierList,
listTitle: 'supplier_name',
onChanged: _updateSupplier,
),
const Gap(16),
InputFormWidget(label: 'Barcode', controller: _barcodeController),
ScanbarcodeWidget(onTap: _scanBarcode),
const Gap(16),