This commit is contained in:
Patrick Alvin Alcala 2025-02-28 12:36:26 +08:00
parent 2931621069
commit 27f00e43a7
15 changed files with 252 additions and 104 deletions

View file

@ -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';
@ -51,6 +53,11 @@ class _AddGenericsPageState extends State<AddGenericsPage> {
}
}
Future<bool> _checkExisting() async {
final uuid = await _refGenericNames.getUUID(_nameController.text);
return uuid.isNotEmpty;
}
void autoRun() async {
if (await InternetConnectionChecker.instance.hasConnection) {
_getList();
@ -76,18 +83,31 @@ class _AddGenericsPageState extends State<AddGenericsPage> {
try {
if (await InternetConnectionChecker.instance.hasConnection) {
final existing = await _checkExisting();
if (existing && mounted) {
showNotification(context, 'Generic Name already existing', false);
return;
}
_categoryUUID = await _refCategories.getUUID(_selectedCategory);
log('_selectedCategory: $_selectedCategory');
log('_categoryUUID: $_categoryUUID');
await _refGenericNames.postGeneric(_nameController.text, _categoryUUID);
final post = await _refGenericNames.postGeneric(_nameController.text, _categoryUUID);
if (mounted) {
showNotification(context, 'Generic Name Saved', true);
if (post && mounted) {
showNotification(context, 'Generic name saved', true);
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) {
context.push('/main');
}
});
} else {
if (mounted) {
showNotification(context, 'Generic name not saved', false);
}
}
} else {
if (mounted) {
@ -172,7 +192,7 @@ class _AddGenericsPageState extends State<AddGenericsPage> {
list: _categoryList,
listTitle: 'category_name',
onChanged: _updateCategory,
value: _selectedCategory,
// value: _selectedCategory,
),
const Gap(32),
if (_isLoading)