added cache for distributors
This commit is contained in:
parent
77fae74302
commit
f2fdfc644a
6 changed files with 70 additions and 4 deletions
|
|
@ -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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
abstract class DistributorListCacheEvent {}
|
||||||
|
|
||||||
|
class DistributorListCacheSet extends DistributorListCacheEvent {
|
||||||
|
final List value;
|
||||||
|
DistributorListCacheSet(this.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
class DistributorListCacheGet extends DistributorListCacheEvent {}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
class DistributorListCacheState {
|
||||||
|
final List value;
|
||||||
|
|
||||||
|
DistributorListCacheState(this.value);
|
||||||
|
}
|
||||||
|
|
@ -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 [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -63,7 +63,7 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
||||||
late List _supplierList = [];
|
late List _supplierList = [];
|
||||||
late String _selectedManufacturer = '';
|
late String _selectedManufacturer = '';
|
||||||
late String _selectedDistributor = '';
|
late String _selectedDistributor = '';
|
||||||
late final String _selectedSupplier = '';
|
late String _selectedSupplier = '';
|
||||||
late String uuid = '';
|
late String uuid = '';
|
||||||
late bool imageUploaded = false;
|
late bool imageUploaded = false;
|
||||||
late String imageUrl = '';
|
late String imageUrl = '';
|
||||||
|
|
@ -206,6 +206,10 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
||||||
_selectedDistributor = distributor;
|
_selectedDistributor = distributor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _updateSupplier(dynamic supplier) {
|
||||||
|
_selectedSupplier = supplier;
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _scanBarcode() async {
|
Future<void> _scanBarcode() async {
|
||||||
// String? barcode = await SimpleBarcodeScanner.scanBarcode(
|
// String? barcode = await SimpleBarcodeScanner.scanBarcode(
|
||||||
// context,
|
// context,
|
||||||
|
|
@ -238,8 +242,8 @@ 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);
|
||||||
|
|
||||||
final posted = await _refMedicines.postMedicine(
|
final posted = await _refMedicines.postMedicine(uuid, medName, medManufacturerUUID, medGenericUUID, medTypeUUID,
|
||||||
uuid, medName, medManufacturerUUID, medGenericUUID, medTypeUUID, encrpytedBarcode, medDistributorUUID, medSupplierUUID);
|
encrpytedBarcode, medDistributorUUID, medSupplierUUID);
|
||||||
|
|
||||||
if (posted) {
|
if (posted) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
|
|
@ -357,7 +361,7 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
||||||
color: 'green',
|
color: 'green',
|
||||||
child: Form(
|
child: Form(
|
||||||
key: _formKey,
|
key: _formKey,
|
||||||
child: DropdownWrapperMultiWidget(list: _genericNameList, text: 'Data', children: [
|
child: DropdownWrapperMultiWidget(list: _supplierList, text: 'Data', children: [
|
||||||
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||||
InputFormWidget(label: 'Name', controller: _nameController),
|
InputFormWidget(label: 'Name', controller: _nameController),
|
||||||
const Gap(16),
|
const Gap(16),
|
||||||
|
|
@ -394,6 +398,13 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
||||||
onChanged: _updateDistributor,
|
onChanged: _updateDistributor,
|
||||||
),
|
),
|
||||||
const Gap(16),
|
const Gap(16),
|
||||||
|
DropDownWidget(
|
||||||
|
label: 'Supplier',
|
||||||
|
list: _supplierList,
|
||||||
|
listTitle: 'supplier_name',
|
||||||
|
onChanged: _updateSupplier,
|
||||||
|
),
|
||||||
|
const Gap(16),
|
||||||
InputFormWidget(label: 'Barcode', controller: _barcodeController),
|
InputFormWidget(label: 'Barcode', controller: _barcodeController),
|
||||||
ScanbarcodeWidget(onTap: _scanBarcode),
|
ScanbarcodeWidget(onTap: _scanBarcode),
|
||||||
const Gap(16),
|
const Gap(16),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue