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/button_widget.dart';
import 'package:pharmacy_mobile/widgets/dropdown_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_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/form_border_widget.dart';
import 'package:pharmacy_mobile/widgets/input_widget.dart'; import 'package:pharmacy_mobile/widgets/input_widget.dart';
import 'package:pharmacy_mobile/widgets/page_background_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'); imageUrl = await _storage.uploadImage(storageName, image, '$imageName.webp');
setState(() {
if (imageUrl.isEmpty) {
if (mounted) {
showNotification(context, 'Image Upload failed, try again.', false);
}
}
});
} }
@override @override
@ -184,78 +193,92 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
body: PageBackgroundWidget( body: PageBackgroundWidget(
child: Center( height: MediaQuery.of(context).size.height + 400,
child: Column( child: Center(
children: [ child: Column(children: [
const Gap(96), const Gap(96),
const TitleWidget(firstTextSize: 20, secondTextSize: 32), const TitleWidget(firstTextSize: 20, secondTextSize: 32),
const Gap(32), const Gap(32),
const TextWidget(text: 'Add Medicine'), const TextWidget(text: 'Add Medicine'),
const Gap(16), const Gap(16),
FormBorderWidget( FormBorderWidget(
color: 'green', color: 'green',
child: Form( child: Form(
key: _formKey, key: _formKey,
child: Center( child: Center(
child: Column( child: Column(
children: [ children: [
InputWidget(label: 'Name', controller: _nameController), InputWidget(label: 'Name', controller: _nameController),
const Gap(16), const Gap(16),
DropdownWrapperWidget( DropdownWrapperMultiWidget(list: _genericNameList, text: 'Data', children: [
list: _genericNameList, Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
text: 'Generics', DropDownWidget(
widget: Column( label: 'Generic Name',
crossAxisAlignment: CrossAxisAlignment.start, list: _genericNameList,
children: [ listTitle: 'generic_name',
DropDownWidget( onChanged: _updateGeneric),
label: 'Generic Name', const Gap(8),
list: _genericNameList, TextWidget(text: _selectedCategory, size: 18),
listTitle: 'generic_name', const Gap(16),
onChanged: _updateGeneric), DropDownWidget(
const Gap(8), label: 'Type', list: _typeList, listTitle: 'type_name', onChanged: _updateType),
TextWidget(text: _selectedCategory, size: 18), const Gap(16),
], DropDownWidget(
)), label: 'Manufactorer',
const Gap(16), list: _manufactorerList,
DropdownWrapperWidget( listTitle: 'manufactorer_name',
list: _typeList, onChanged: _updateManufactorer),
text: 'Types', const Gap(32),
widget: DropDownWidget( if (imageUrl.isNotEmpty)
label: 'Type', list: _typeList, listTitle: 'type_name', onChanged: _updateType)), Center(
const Gap(16), child: ClipRRect(
DropdownWrapperWidget( borderRadius: BorderRadius.circular(12), // Add your desired border radius here
list: _manufactorerList, child: Image.network(imageUrl, fit: BoxFit.cover, width: 250, height: 250)),
text: 'Manufactorers', )
widget: DropDownWidget( else
label: 'Manufactorer', ButtonWidget(text: 'Add Image', onPressed: _addImage),
list: _manufactorerList, const Gap(32),
listTitle: 'manufactorer_name', if (_isLoading)
onChanged: _updateManufactorer)), const Center(child: CircularProgressIndicator(color: Colors.white))
const Gap(32), else
// if (imageUrl.isNotEmpty) ButtonWidget(text: 'Save Medicine', onPressed: _saveMedicine)
ClipRRect( ])
borderRadius: BorderRadius.circular(12), // Add your desired border radius here ]),
child: Image.network( // DropdownWrapperWidget(
'https://lijihnvjlucyvxfhghqd.supabase.co/storage/v1/object/public/ref_medicines_images//ab033e88-1933-496b-8e11-47bf85d21d8f.webp', // list: _genericNameList,
fit: BoxFit.cover, // text: 'Generics',
width: 250, // widget: Column(
height: 250)), // crossAxisAlignment: CrossAxisAlignment.start,
// else // children: [
// ButtonWidget(text: 'Add Image', onPressed: _addImage), // DropDownWidget(
const Gap(32), // label: 'Generic Name',
if (_isLoading) // list: _genericNameList,
const Center(child: CircularProgressIndicator(color: Colors.white)) // listTitle: 'generic_name',
else // onChanged: _updateGeneric),
ButtonWidget(text: 'Save Medicine', onPressed: _saveMedicine) // 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:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:gap/gap.dart'; import 'package:gap/gap.dart';
@ -22,8 +24,8 @@ class _MainPageState extends State<MainPage> {
void _checkLogged() async { void _checkLogged() async {
SharedPreferences prefs = await SharedPreferences.getInstance(); SharedPreferences prefs = await SharedPreferences.getInstance();
bool userStatus = prefs.containsKey('user'); bool userStatus = prefs.containsKey('user');
if (!userStatus) { if (!userStatus) {
// ignore: use_build_context_synchronously
context.go('/'); 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 { class PageBackgroundWidget extends StatelessWidget {
final Widget child; final Widget child;
final String? page; 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -12,7 +13,7 @@ class PageBackgroundWidget extends StatelessWidget {
scrollDirection: Axis.vertical, scrollDirection: Axis.vertical,
child: Container( child: Container(
alignment: Alignment.center, alignment: Alignment.center,
height: MediaQuery.of(context).size.height + 200, height: height ?? MediaQuery.of(context).size.height + 200,
decoration: BoxDecoration( decoration: BoxDecoration(
image: DecorationImage( image: DecorationImage(
image: AssetImage( image: AssetImage(