This commit is contained in:
Patrick Alvin Alcala 2025-02-14 13:07:37 +08:00
parent 941e9eaa5b
commit 4753926c34
4 changed files with 137 additions and 70 deletions

View file

@ -13,6 +13,7 @@ import 'package:pharmacy_mobile/tables/storage.dart';
import 'package:pharmacy_mobile/widgets/button_widget.dart';
import 'package:pharmacy_mobile/widgets/dropdown_widget.dart';
import 'package:pharmacy_mobile/widgets/dropdown_wrapper_widget.dart';
import 'package:pharmacy_mobile/widgets/dropdown_wrappermulti_widget.dart';
import 'package:pharmacy_mobile/widgets/form_border_widget.dart';
import 'package:pharmacy_mobile/widgets/input_widget.dart';
import 'package:pharmacy_mobile/widgets/page_background_widget.dart';
@ -158,6 +159,14 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
}
imageUrl = await _storage.uploadImage(storageName, image, '$imageName.webp');
setState(() {
if (imageUrl.isEmpty) {
if (mounted) {
showNotification(context, 'Image Upload failed, try again.', false);
}
}
});
}
@override
@ -184,78 +193,92 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: PageBackgroundWidget(
child: Center(
child: Column(
children: [
body: PageBackgroundWidget(
height: MediaQuery.of(context).size.height + 400,
child: Center(
child: Column(children: [
const Gap(96),
const TitleWidget(firstTextSize: 20, secondTextSize: 32),
const Gap(32),
const TextWidget(text: 'Add Medicine'),
const Gap(16),
FormBorderWidget(
color: 'green',
child: Form(
key: _formKey,
child: Center(
child: Column(
children: [
InputWidget(label: 'Name', controller: _nameController),
const Gap(16),
DropdownWrapperWidget(
list: _genericNameList,
text: 'Generics',
widget: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
DropDownWidget(
label: 'Generic Name',
list: _genericNameList,
listTitle: 'generic_name',
onChanged: _updateGeneric),
const Gap(8),
TextWidget(text: _selectedCategory, size: 18),
],
)),
const Gap(16),
DropdownWrapperWidget(
list: _typeList,
text: 'Types',
widget: DropDownWidget(
label: 'Type', list: _typeList, listTitle: 'type_name', onChanged: _updateType)),
const Gap(16),
DropdownWrapperWidget(
list: _manufactorerList,
text: 'Manufactorers',
widget: DropDownWidget(
label: 'Manufactorer',
list: _manufactorerList,
listTitle: 'manufactorer_name',
onChanged: _updateManufactorer)),
const Gap(32),
// if (imageUrl.isNotEmpty)
ClipRRect(
borderRadius: BorderRadius.circular(12), // Add your desired border radius here
child: Image.network(
'https://lijihnvjlucyvxfhghqd.supabase.co/storage/v1/object/public/ref_medicines_images//ab033e88-1933-496b-8e11-47bf85d21d8f.webp',
fit: BoxFit.cover,
width: 250,
height: 250)),
// else
// ButtonWidget(text: 'Add Image', onPressed: _addImage),
const Gap(32),
if (_isLoading)
const Center(child: CircularProgressIndicator(color: Colors.white))
else
ButtonWidget(text: 'Save Medicine', onPressed: _saveMedicine)
],
),
)),
)
],
),
),
),
);
color: 'green',
child: Form(
key: _formKey,
child: Center(
child: Column(
children: [
InputWidget(label: 'Name', controller: _nameController),
const Gap(16),
DropdownWrapperMultiWidget(list: _genericNameList, text: 'Data', children: [
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
DropDownWidget(
label: 'Generic Name',
list: _genericNameList,
listTitle: 'generic_name',
onChanged: _updateGeneric),
const Gap(8),
TextWidget(text: _selectedCategory, size: 18),
const Gap(16),
DropDownWidget(
label: 'Type', list: _typeList, listTitle: 'type_name', onChanged: _updateType),
const Gap(16),
DropDownWidget(
label: 'Manufactorer',
list: _manufactorerList,
listTitle: 'manufactorer_name',
onChanged: _updateManufactorer),
const Gap(32),
if (imageUrl.isNotEmpty)
Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(12), // Add your desired border radius here
child: Image.network(imageUrl, fit: BoxFit.cover, width: 250, height: 250)),
)
else
ButtonWidget(text: 'Add Image', onPressed: _addImage),
const Gap(32),
if (_isLoading)
const Center(child: CircularProgressIndicator(color: Colors.white))
else
ButtonWidget(text: 'Save Medicine', onPressed: _saveMedicine)
])
]),
// DropdownWrapperWidget(
// list: _genericNameList,
// text: 'Generics',
// widget: Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// DropDownWidget(
// label: 'Generic Name',
// list: _genericNameList,
// listTitle: 'generic_name',
// onChanged: _updateGeneric),
// const Gap(8),
// TextWidget(text: _selectedCategory, size: 18),
// ],
// )),
// const Gap(16),
// DropdownWrapperWidget(
// list: _typeList,
// text: 'Types',
// widget: DropDownWidget(
// label: 'Type', list: _typeList, listTitle: 'type_name', onChanged: _updateType)),
// const Gap(16),
// DropdownWrapperWidget(
// list: _manufactorerList,
// text: 'Manufactorers',
// widget: DropDownWidget(
// label: 'Manufactorer',
// list: _manufactorerList,
// listTitle: 'manufactorer_name',
// onChanged: _updateManufactorer)),
// const Gap(32),
],
),
)))
]))));
}
}

View file

@ -1,3 +1,5 @@
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:gap/gap.dart';
@ -22,8 +24,8 @@ class _MainPageState extends State<MainPage> {
void _checkLogged() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
bool userStatus = prefs.containsKey('user');
if (!userStatus) {
// ignore: use_build_context_synchronously
context.go('/');
}
}

View file

@ -0,0 +1,41 @@
import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:pharmacy_mobile/widgets/text_widget.dart';
class DropdownWrapperMultiWidget extends StatelessWidget {
final List list;
final String text;
final List<Widget> children;
const DropdownWrapperMultiWidget({
super.key,
required this.list,
required this.text,
required this.children,
});
@override
Widget build(BuildContext context) {
return (list.isEmpty)
? Column(
children: [
const Gap(8),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
spacing: 16,
children: [
const CircularProgressIndicator(color: Color.fromRGBO(255, 255, 255, 1)),
TextWidget(
text: 'Fetching $text',
size: 16,
)
],
),
],
)
: Column(
children: children,
);
}
}

View file

@ -3,8 +3,9 @@ import 'package:flutter/material.dart';
class PageBackgroundWidget extends StatelessWidget {
final Widget child;
final String? page;
final double? height;
const PageBackgroundWidget({super.key, required this.child, this.page});
const PageBackgroundWidget({super.key, required this.child, this.page, this.height});
@override
Widget build(BuildContext context) {
@ -12,7 +13,7 @@ class PageBackgroundWidget extends StatelessWidget {
scrollDirection: Axis.vertical,
child: Container(
alignment: Alignment.center,
height: MediaQuery.of(context).size.height + 200,
height: height ?? MediaQuery.of(context).size.height + 200,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(