fix saving and display of stocks

This commit is contained in:
Patrick Alvin Alcala 2025-04-07 17:23:57 +08:00
parent 6c5e9f84d7
commit e8d0f213e9
5 changed files with 255 additions and 138 deletions

View file

@ -190,8 +190,20 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
final medTypeUUID = await _refTypes.getUUID(_selectedType);
final medManufacturerUUID = await _refManufacturer.getUUID(_selectedManufacturer);
await _refMedicines.postMedicine(
final posted = await _refMedicines.postMedicine(
uuid, medName, medManufacturerUUID, medGenericUUID, medTypeUUID, encrpytedBarcode);
if (posted) {
if (mounted) {
showNotification(context, 'Medicine Added Successfully', true);
setState(() => _isLoading = false);
context.pop();
}
} else {
if (mounted) {
showNotification(context, 'Error: Medicine Not Added', false);
}
}
} else {
if (mounted) {
showNotification(context, 'Error: No Internet Connection', false);

View file

@ -28,17 +28,20 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
late String imageUrl = '';
late List _stockList = [];
late List _cartList = [];
// late final List _medicinesList = [];
Future<void> _getURL() async {
final image = await _storage.getImageURL('ref_medicines_images', '91ba5229-244b-4377-ba4e-9de57b9ba4df.webp');
setState(() {
imageUrl = image;
});
Future<String> _getURL(String imageName) async {
final image = await _storage.getImageURL('ref_medicines_images', '$imageName.webp');
return image;
}
Future<void> _getAllStocks() async {
_stockList = await _stocks.getList();
_stockList = await _stocks.getListWithUUID();
if (_stockList.isNotEmpty) {
for (int i = 0; i < _stockList.length; i++) {
_stockList[i]['uuid'] = await _getURL(_stockList[i]['uuid']);
}
setState(() {});
}
}
Future<String> _getCurrentUserId() async {
@ -79,7 +82,7 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
await _getAllStocks();
await _getCarts();
// // // await _getAllMedicines();
await _getURL();
// await _getURL();
}
@override
@ -100,7 +103,7 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
Widget build(BuildContext context) {
return Scaffold(
body: CustomerPagebackgroundWidget(
height: MediaQuery.of(context).size.height + 800,
height: MediaQuery.of(context).size.height + 200,
child: Column(
children: [
Column(
@ -121,13 +124,13 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
),
),
const Gap(32),
const IndicatorWidget(text: 'All Stocks'),
const IndicatorWidget(text: 'Prescribed Medicines'),
const Gap(8),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
if (imageUrl.isEmpty)
if (_stockList.isEmpty)
const Row(
children: [
ItemCardWidget(
@ -159,7 +162,7 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
else
for (var item in _stockList)
ItemCardWidget(
imageUrl: imageUrl,
imageUrl: item['uuid'],
text: item['medicine_name'].toString(),
subtext: item['generic_name'].toString(),
price: item['price'].toDouble(),
@ -169,137 +172,185 @@ class _CustomerSearchPageState extends State<CustomerSearchPage> {
],
)),
const Gap(16),
const IndicatorWidget(text: 'For Fever'),
const IndicatorWidget(text: 'All Stocks'),
const Gap(8),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
ItemCardWidget(
imageUrl: imageUrl,
text: 'sample',
subtext: 'generic_name',
price: 500,
quantity: 0,
isLoading: imageUrl.isEmpty,
cart: 2),
ItemCardWidget(
imageUrl: imageUrl,
text: 'sample',
subtext: 'generic_name',
price: 500,
quantity: 15,
isLoading: imageUrl.isEmpty,
cart: 0),
ItemCardWidget(
imageUrl: imageUrl,
text: 'sample',
subtext: 'generic_name',
price: 500,
quantity: 15,
isLoading: imageUrl.isEmpty,
cart: 0),
],
)),
const Gap(16),
const IndicatorWidget(text: 'For Headaches'),
const Gap(8),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
ItemCardWidget(
imageUrl: imageUrl,
text: 'sample',
subtext: 'generic_name',
price: 500,
quantity: 15,
isLoading: imageUrl.isEmpty,
cart: 0),
ItemCardWidget(
imageUrl: imageUrl,
text: 'sample',
subtext: 'generic_name',
price: 500,
quantity: 15,
isLoading: imageUrl.isEmpty,
cart: 0),
ItemCardWidget(
imageUrl: imageUrl,
text: 'sample',
subtext: 'generic_name',
price: 500,
quantity: 15,
isLoading: imageUrl.isEmpty,
cart: 0),
],
)),
const Gap(16),
const IndicatorWidget(text: 'For Colds and Coughes'),
const Gap(8),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
ItemCardWidget(
imageUrl: imageUrl,
text: 'sample',
subtext: 'generic_name',
price: 500,
quantity: 15,
isLoading: imageUrl.isEmpty,
cart: 0),
ItemCardWidget(
imageUrl: imageUrl,
text: 'sample',
subtext: 'generic_name',
price: 500,
quantity: 15,
isLoading: imageUrl.isEmpty,
cart: 0),
ItemCardWidget(
imageUrl: imageUrl,
text: 'sample',
subtext: 'generic_name',
price: 500,
quantity: 15,
isLoading: imageUrl.isEmpty,
cart: 0),
],
)),
const Gap(16),
const IndicatorWidget(text: 'For Infection and Irritations'),
const Gap(8),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
ItemCardWidget(
imageUrl: imageUrl,
text: 'sample',
subtext: 'generic_name',
price: 500,
quantity: 15,
isLoading: imageUrl.isEmpty,
cart: 0),
ItemCardWidget(
imageUrl: imageUrl,
text: 'sample',
subtext: 'generic_name',
price: 500,
quantity: 15,
isLoading: imageUrl.isEmpty,
cart: 0),
ItemCardWidget(
imageUrl: imageUrl,
text: 'sample',
subtext: 'generic_name',
price: 500,
quantity: 15,
isLoading: imageUrl.isEmpty,
cart: 0),
if (_stockList.isEmpty)
const Row(
children: [
ItemCardWidget(
imageUrl: 'imageUrl',
text: 'item[medicine_name]',
subtext: 'item[generic_name]',
price: 123,
quantity: 123,
isLoading: true,
cart: 0),
ItemCardWidget(
imageUrl: 'imageUrl',
text: 'item[medicine_name]',
subtext: 'item[generic_name]',
price: 123,
quantity: 123,
isLoading: true,
cart: 0),
ItemCardWidget(
imageUrl: 'imageUrl',
text: 'item[medicine_name]',
subtext: 'item[generic_name]',
price: 123,
quantity: 123,
isLoading: true,
cart: 0)
],
)
else
for (var item in _stockList)
ItemCardWidget(
imageUrl: item['uuid'].toString(),
text: item['medicine_name'].toString(),
subtext: item['generic_name'].toString(),
price: item['price'].toDouble(),
quantity: item['quantity'].toDouble(),
isLoading: false,
cart: 0),
],
)),
// const Gap(16),
// const IndicatorWidget(text: 'For Fever'),
// const Gap(8),
// SingleChildScrollView(
// scrollDirection: Axis.horizontal,
// child: Row(
// children: [
// ItemCardWidget(
// imageUrl: imageUrl,
// text: 'sample',
// subtext: 'generic_name',
// price: 500,
// quantity: 0,
// isLoading: imageUrl.isEmpty,
// cart: 2),
// ItemCardWidget(
// imageUrl: imageUrl,
// text: 'sample',
// subtext: 'generic_name',
// price: 500,
// quantity: 15,
// isLoading: imageUrl.isEmpty,
// cart: 0),
// ItemCardWidget(
// imageUrl: imageUrl,
// text: 'sample',
// subtext: 'generic_name',
// price: 500,
// quantity: 15,
// isLoading: imageUrl.isEmpty,
// cart: 0),
// ],
// )),
// const Gap(16),
// const IndicatorWidget(text: 'For Headaches'),
// const Gap(8),
// SingleChildScrollView(
// scrollDirection: Axis.horizontal,
// child: Row(
// children: [
// ItemCardWidget(
// imageUrl: imageUrl,
// text: 'sample',
// subtext: 'generic_name',
// price: 500,
// quantity: 15,
// isLoading: imageUrl.isEmpty,
// cart: 0),
// ItemCardWidget(
// imageUrl: imageUrl,
// text: 'sample',
// subtext: 'generic_name',
// price: 500,
// quantity: 15,
// isLoading: imageUrl.isEmpty,
// cart: 0),
// ItemCardWidget(
// imageUrl: imageUrl,
// text: 'sample',
// subtext: 'generic_name',
// price: 500,
// quantity: 15,
// isLoading: imageUrl.isEmpty,
// cart: 0),
// ],
// )),
// const Gap(16),
// const IndicatorWidget(text: 'For Colds and Coughes'),
// const Gap(8),
// SingleChildScrollView(
// scrollDirection: Axis.horizontal,
// child: Row(
// children: [
// ItemCardWidget(
// imageUrl: imageUrl,
// text: 'sample',
// subtext: 'generic_name',
// price: 500,
// quantity: 15,
// isLoading: imageUrl.isEmpty,
// cart: 0),
// ItemCardWidget(
// imageUrl: imageUrl,
// text: 'sample',
// subtext: 'generic_name',
// price: 500,
// quantity: 15,
// isLoading: imageUrl.isEmpty,
// cart: 0),
// ItemCardWidget(
// imageUrl: imageUrl,
// text: 'sample',
// subtext: 'generic_name',
// price: 500,
// quantity: 15,
// isLoading: imageUrl.isEmpty,
// cart: 0),
// ],
// )),
// const Gap(16),
// const IndicatorWidget(text: 'For Infection and Irritations'),
// const Gap(8),
// SingleChildScrollView(
// scrollDirection: Axis.horizontal,
// child: Row(
// children: [
// ItemCardWidget(
// imageUrl: imageUrl,
// text: 'sample',
// subtext: 'generic_name',
// price: 500,
// quantity: 15,
// isLoading: imageUrl.isEmpty,
// cart: 0),
// ItemCardWidget(
// imageUrl: imageUrl,
// text: 'sample',
// subtext: 'generic_name',
// price: 500,
// quantity: 15,
// isLoading: imageUrl.isEmpty,
// cart: 0),
// ItemCardWidget(
// imageUrl: imageUrl,
// text: 'sample',
// subtext: 'generic_name',
// price: 500,
// quantity: 15,
// isLoading: imageUrl.isEmpty,
// cart: 0),
// ],
// )),
],
)
],