110 lines
3.4 KiB
Dart
110 lines
3.4 KiB
Dart
import 'package:gap/gap.dart';
|
|
import 'package:flutter/material.dart';
|
|
// import 'package:pharmacy_mobile/auth/auth_service.dart';
|
|
import 'package:pharmacy_mobile/tables/ref_categories.dart';
|
|
import 'package:pharmacy_mobile/tables/ref_generic_names.dart';
|
|
import 'package:pharmacy_mobile/widgets/button_widget.dart';
|
|
import 'package:pharmacy_mobile/widgets/dropdown_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/text_widget.dart';
|
|
import 'package:pharmacy_mobile/widgets/title_widget.dart';
|
|
import 'package:visibility_detector/visibility_detector.dart';
|
|
|
|
class AddGenericsPage extends StatefulWidget {
|
|
const AddGenericsPage({super.key});
|
|
|
|
@override
|
|
State<AddGenericsPage> createState() => _AddGenericsPageState();
|
|
}
|
|
|
|
class _AddGenericsPageState extends State<AddGenericsPage> {
|
|
// final _formKey = GlobalKey<FormState>();
|
|
final _refCategories = RefCategories();
|
|
final _refGenericNames = RefGenericNames();
|
|
final _nameController = TextEditingController();
|
|
final _formKey = GlobalKey<FormState>();
|
|
bool _isVisible = false;
|
|
|
|
late List _categoryList = [];
|
|
late String _selectedCategory = '';
|
|
late String _categoryUUID = '';
|
|
|
|
void autoRun() async {
|
|
_categoryList = await _refCategories.getList();
|
|
}
|
|
|
|
void _updateCategory(dynamic category) {
|
|
_selectedCategory = category;
|
|
}
|
|
|
|
void saveGeneric() async {
|
|
_categoryUUID = await _refCategories.getUUID(_selectedCategory);
|
|
|
|
await _refGenericNames.postGeneric(_nameController.text, _categoryUUID);
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
autoRun();
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_nameController.dispose();
|
|
_categoryList = [];
|
|
_selectedCategory = '';
|
|
_categoryUUID = '';
|
|
_isVisible = false;
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
body: VisibilityDetector(
|
|
key: Key('AddGenericsPage'),
|
|
onVisibilityChanged: (visibilityInfo) {
|
|
if (visibilityInfo.visibleFraction > 0.5 && !_isVisible) {
|
|
setState(() {
|
|
_isVisible = true;
|
|
autoRun();
|
|
});
|
|
}
|
|
},
|
|
child: PageBackgroundWidget(
|
|
child: Center(
|
|
child: Column(
|
|
children: [
|
|
const Gap(104),
|
|
const TitleWidget(firstTextSize: 20, secondTextSize: 32),
|
|
const Gap(32),
|
|
const TextWidget(text: 'Add Generics'),
|
|
const Gap(16),
|
|
FormBorderWidget(
|
|
color: 'blue',
|
|
child: Form(
|
|
key: _formKey,
|
|
child: Column(
|
|
children: [
|
|
InputWidget(label: 'Name', controller: _nameController),
|
|
const Gap(16),
|
|
DropDownWidget(
|
|
label: 'Category',
|
|
list: _categoryList,
|
|
listTitle: 'category_name',
|
|
onChanged: _updateCategory),
|
|
const Gap(16),
|
|
ButtonWidget(text: 'Add', onPressed: saveGeneric)
|
|
],
|
|
)),
|
|
)
|
|
],
|
|
)),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|