update
This commit is contained in:
parent
47a2d34933
commit
4586256032
9 changed files with 246 additions and 154 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:internet_connection_checker/internet_connection_checker.dart';
|
||||
|
|
@ -25,7 +27,7 @@ class _AddGenericsPageState extends State<AddGenericsPage> {
|
|||
final _refGenericNames = RefGenericNames();
|
||||
final _nameController = TextEditingController();
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
// bool _isVisible = false;
|
||||
|
||||
bool _isLoading = false;
|
||||
|
||||
late List _categoryList = [];
|
||||
|
|
@ -33,12 +35,11 @@ class _AddGenericsPageState extends State<AddGenericsPage> {
|
|||
late String _categoryUUID = '';
|
||||
|
||||
void _getList() async {
|
||||
// if (await InternetConnectionChecker.instance.hasConnection) {
|
||||
_categoryList = await _refCategories.getList();
|
||||
|
||||
if (_categoryList.isEmpty) {
|
||||
if (mounted) {
|
||||
showNotification(context, 'Error: Empty', false);
|
||||
showNotification(context, 'Error: No Categories Found', false);
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
|
|
@ -46,23 +47,14 @@ class _AddGenericsPageState extends State<AddGenericsPage> {
|
|||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
setState(() => {});
|
||||
}
|
||||
// } else {
|
||||
// if (mounted) {
|
||||
// showNotification(context, 'Error: No Internet Connection', false);
|
||||
|
||||
// WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// if (mounted) {
|
||||
// context.push('/main');
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
void autoRun() async {
|
||||
if (await InternetConnectionChecker.instance.hasConnection) {
|
||||
_categoryList = await _refCategories.getList();
|
||||
_getList();
|
||||
} else {
|
||||
if (mounted) {
|
||||
showNotification(context, 'Error: No Internet Connection', false);
|
||||
|
|
@ -114,7 +106,7 @@ class _AddGenericsPageState extends State<AddGenericsPage> {
|
|||
|
||||
@override
|
||||
void initState() {
|
||||
// autoRun();
|
||||
autoRun();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
|
|
@ -148,20 +140,40 @@ class _AddGenericsPageState extends State<AddGenericsPage> {
|
|||
children: [
|
||||
InputWidget(label: 'Name', controller: _nameController),
|
||||
const Gap(16),
|
||||
GestureDetector(
|
||||
onTap: _getList,
|
||||
child: DropDownWidget(
|
||||
if (_categoryList.isEmpty)
|
||||
Column(
|
||||
children: [
|
||||
const Gap(8),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
spacing: 16,
|
||||
children: [
|
||||
CircularProgressIndicator(color: Colors.white),
|
||||
TextWidget(
|
||||
text: 'Fetching Categories',
|
||||
size: 16,
|
||||
)
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
else
|
||||
Column(
|
||||
children: [
|
||||
DropDownWidget(
|
||||
label: 'Category',
|
||||
list: _categoryList,
|
||||
listTitle: 'category_name',
|
||||
onChanged: _updateCategory),
|
||||
),
|
||||
const Gap(32),
|
||||
if (_isLoading)
|
||||
Center(child: CircularProgressIndicator(color: Colors.white))
|
||||
else
|
||||
ButtonWidget(text: 'Add', onPressed: saveGeneric)
|
||||
],
|
||||
),
|
||||
],
|
||||
)),
|
||||
)
|
||||
],
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:internet_connection_checker/internet_connection_checker.dart';
|
||||
|
|
@ -8,13 +10,14 @@ import 'package:pharmacy_mobile/tables/ref_medicines.dart';
|
|||
import 'package:pharmacy_mobile/tables/ref_types.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/form_border_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/input_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/page_background_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/snackbar_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/text_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/title_widget.dart';
|
||||
import 'package:visibility_detector/visibility_detector.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
class AddMedicinePage extends StatefulWidget {
|
||||
const AddMedicinePage({super.key});
|
||||
|
|
@ -25,7 +28,6 @@ class AddMedicinePage extends StatefulWidget {
|
|||
|
||||
class _AddMedicinePageState extends State<AddMedicinePage> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
// final _authService = AuthService();
|
||||
final _refGenericNames = RefGenericNames();
|
||||
final _refCategories = RefCategories();
|
||||
final _refTypes = RefTypes();
|
||||
|
|
@ -33,7 +35,6 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
final _refMedicines = RefMedicines();
|
||||
final _nameController = TextEditingController();
|
||||
final FocusNode _focusNode = FocusNode();
|
||||
bool _isVisible = false;
|
||||
bool _isLoading = false;
|
||||
|
||||
late List _genericNameList = [];
|
||||
|
|
@ -44,14 +45,56 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
late List _manufactorerList = [];
|
||||
late String _selectedManufactorer = '';
|
||||
|
||||
void _checkResult(List list, String name) {
|
||||
if (list.isEmpty) {
|
||||
if (mounted) {
|
||||
showNotification(context, 'Error: No $name Found', false);
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
context.push('/main');
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
setState(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
void _getGenerics() async {
|
||||
_genericNameList = await _refGenericNames.getList();
|
||||
_checkResult(_genericNameList, 'Generics');
|
||||
}
|
||||
|
||||
void _getTypes() async {
|
||||
_typeList = await _refTypes.getList();
|
||||
_checkResult(_typeList, 'Types');
|
||||
}
|
||||
|
||||
void _getManufactorer() async {
|
||||
_manufactorerList = await _refManufactorer.getList();
|
||||
_checkResult(_manufactorerList, 'Manufactorer');
|
||||
}
|
||||
|
||||
void autoRun() async {
|
||||
if (await InternetConnectionChecker.instance.hasConnection) {
|
||||
_genericNameList = await _refGenericNames.getList();
|
||||
_typeList = await _refTypes.getList();
|
||||
_manufactorerList = await _refManufactorer.getList();
|
||||
_getGenerics();
|
||||
_getTypes();
|
||||
_getManufactorer();
|
||||
|
||||
setState(() {});
|
||||
|
||||
final sample = await _refMedicines.getList2();
|
||||
log(sample.toString());
|
||||
} else {
|
||||
if (mounted) {
|
||||
showNotification(context, 'Error: No Internet Connection', false);
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
context.push('/main');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -82,7 +125,7 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
final medTypeUUID = await _refTypes.getUUID(_selectedType);
|
||||
final medManufactorerUUID = await _refManufactorer.getUUID(_selectedManufactorer);
|
||||
|
||||
await _refMedicines.postMedicine(medName, medGenericUUID, medManufactorerUUID, medTypeUUID);
|
||||
await _refMedicines.postMedicine(medName, medManufactorerUUID, medGenericUUID, medTypeUUID);
|
||||
} else {
|
||||
if (mounted) {
|
||||
showNotification(context, 'Error: No Internet Connection', false);
|
||||
|
|
@ -121,17 +164,7 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: VisibilityDetector(
|
||||
key: Key('AddMedicinePage'),
|
||||
onVisibilityChanged: (visibilityInfo) {
|
||||
if (visibilityInfo.visibleFraction > 0.5 && !_isVisible) {
|
||||
setState(() {
|
||||
_isVisible = true;
|
||||
autoRun();
|
||||
});
|
||||
}
|
||||
},
|
||||
child: PageBackgroundWidget(
|
||||
body: PageBackgroundWidget(
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
|
|
@ -149,7 +182,10 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
children: [
|
||||
InputWidget(label: 'Name', controller: _nameController),
|
||||
const Gap(16),
|
||||
Column(
|
||||
DropdownWrapperWidget(
|
||||
list: _genericNameList,
|
||||
text: 'Generics',
|
||||
widget: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
DropDownWidget(
|
||||
|
|
@ -160,16 +196,22 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
const Gap(8),
|
||||
TextWidget(text: _selectedCategory, size: 18),
|
||||
],
|
||||
),
|
||||
)),
|
||||
const Gap(16),
|
||||
DropDownWidget(
|
||||
label: 'Type', list: _typeList, listTitle: 'type_name', onChanged: _updateType),
|
||||
DropdownWrapperWidget(
|
||||
list: _typeList,
|
||||
text: 'Types',
|
||||
widget: DropDownWidget(
|
||||
label: 'Type', list: _typeList, listTitle: 'type_name', onChanged: _updateType)),
|
||||
const Gap(16),
|
||||
DropDownWidget(
|
||||
DropdownWrapperWidget(
|
||||
list: _manufactorerList,
|
||||
text: 'Manufactorers',
|
||||
widget: DropDownWidget(
|
||||
label: 'Manufactorer',
|
||||
list: _manufactorerList,
|
||||
listTitle: 'manufactorer_name',
|
||||
onChanged: _updateManufactorer),
|
||||
onChanged: _updateManufactorer)),
|
||||
const Gap(32),
|
||||
if (_isLoading)
|
||||
Center(child: CircularProgressIndicator(color: Colors.white))
|
||||
|
|
@ -183,7 +225,6 @@ class _AddMedicinePageState extends State<AddMedicinePage> {
|
|||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import 'package:pharmacy_mobile/widgets/input_widget.dart';
|
|||
import 'package:pharmacy_mobile/widgets/page_background_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/text_widget.dart';
|
||||
import 'package:pharmacy_mobile/widgets/title_widget.dart';
|
||||
import 'package:visibility_detector/visibility_detector.dart'; // Import this package
|
||||
|
||||
// import 'package:intl/intl.dart';
|
||||
|
||||
|
|
@ -32,7 +31,6 @@ class _AddStockPageState extends State<AddStockPage> {
|
|||
late List _medicineList = [];
|
||||
late String _selectedMedicine = '';
|
||||
late DateTime selectedDate = DateTime.now();
|
||||
bool _isVisible = false;
|
||||
|
||||
void autoRun() async {
|
||||
_medicineList = await _refMedicines.getList();
|
||||
|
|
@ -63,24 +61,13 @@ class _AddStockPageState extends State<AddStockPage> {
|
|||
_selectedMedicine = '';
|
||||
_quantityController.dispose();
|
||||
_dateController.dispose();
|
||||
_isVisible = false;
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: VisibilityDetector(
|
||||
key: Key('AddStockPage'),
|
||||
onVisibilityChanged: (visibilityInfo) {
|
||||
if (visibilityInfo.visibleFraction > 0.5 && !_isVisible) {
|
||||
setState(() {
|
||||
_isVisible = true;
|
||||
autoRun();
|
||||
});
|
||||
}
|
||||
},
|
||||
child: PageBackgroundWidget(
|
||||
body: PageBackgroundWidget(
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
|
|
@ -120,7 +107,6 @@ class _AddStockPageState extends State<AddStockPage> {
|
|||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ class _AddTypePageState extends State<AddTypePage> {
|
|||
child: Column(
|
||||
children: [
|
||||
InputWidget(label: 'Type Name', controller: _typeController),
|
||||
const Gap(16),
|
||||
const Gap(32),
|
||||
if (_isLoading)
|
||||
Center(child: CircularProgressIndicator(color: Colors.white))
|
||||
else
|
||||
|
|
|
|||
|
|
@ -27,4 +27,20 @@ class RefGenericNames {
|
|||
.from('ref_generic_names')
|
||||
.insert({'ref_generic_names_uuid': genericUUID, 'generic_name': name, 'ref_categories_uuid': uuid});
|
||||
}
|
||||
|
||||
Future<List> getSample() async {
|
||||
final data = await _supabase.from('ref_generic_names').select('''generic_name, ref_categories(category_name)''');
|
||||
return data.toList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// let { data: ref_generic_names, error } = await supabase
|
||||
// .from('ref_generic_names')
|
||||
// .select(`
|
||||
// some_column,
|
||||
// other_table (
|
||||
// foreign_key
|
||||
// )
|
||||
// `)
|
||||
|
||||
|
|
@ -9,6 +9,13 @@ class RefMedicines {
|
|||
return data.toList();
|
||||
}
|
||||
|
||||
Future<List> getList2() async {
|
||||
final data = await _supabase
|
||||
.from('ref_medicines')
|
||||
.select('''medicine_name, ref_manufactorers(manufactorer_name)''').order('medicine_name', ascending: true);
|
||||
return data.toList();
|
||||
}
|
||||
|
||||
Future<String> getUUID(String name) async {
|
||||
final data = await _supabase.from('ref_medicines').select('ref_medicines_uuid').eq('medicine_name', name);
|
||||
return data.first['ref_medicines_uuid'];
|
||||
|
|
|
|||
39
lib/widgets/dropdown_wrapper_widget.dart
Normal file
39
lib/widgets/dropdown_wrapper_widget.dart
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:pharmacy_mobile/widgets/text_widget.dart';
|
||||
|
||||
class DropdownWrapperWidget extends StatelessWidget {
|
||||
final List list;
|
||||
final String text;
|
||||
final Widget widget;
|
||||
|
||||
const DropdownWrapperWidget({
|
||||
super.key,
|
||||
required this.list,
|
||||
required this.text,
|
||||
required this.widget,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return (list.isEmpty)
|
||||
? Column(
|
||||
children: [
|
||||
const Gap(8),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
spacing: 16,
|
||||
children: [
|
||||
CircularProgressIndicator(color: Colors.white),
|
||||
TextWidget(
|
||||
text: 'Fetching $text',
|
||||
size: 16,
|
||||
)
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
: widget;
|
||||
}
|
||||
}
|
||||
|
|
@ -693,14 +693,6 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.4"
|
||||
visibility_detector:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: visibility_detector
|
||||
sha256: dd5cc11e13494f432d15939c3aa8ae76844c42b723398643ce9addb88a5ed420
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.4.0+2"
|
||||
vm_service:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ dependencies:
|
|||
font_awesome_flutter: ^10.8.0
|
||||
uuid: ^4.5.1
|
||||
intl: ^0.20.2
|
||||
visibility_detector: ^0.4.0+2
|
||||
internet_connection_checker: ^3.0.1
|
||||
|
||||
dev_dependencies:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue