let AI comment everything because well... yeah...

This commit is contained in:
Nico
2025-06-06 21:00:32 +02:00
parent 9c84d0c375
commit cc110ac104
44 changed files with 1230 additions and 646 deletions

View File

@@ -1,15 +1,32 @@
// * Shared widget for text input fields with database integration
// * Features:
// * - Customizable text input field
// * - Database value suggestions
// * - Required field validation
// * - Default value support
// * - Visual feedback for validation state
// * - Dropdown for previous entries
import 'package:fforte/enums/databases.dart';
import 'package:fforte/methods/excursion_db_helper.dart';
import 'package:fforte/methods/place_db_helper.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
/// Widget for managing text input with database integration
/// Provides suggestions from previous entries and validation
class VarTextField extends StatefulWidget {
/// Controller for the text input
final TextEditingController textController;
/// Localized label/hint text
final String localization;
/// Database type (place or excursion)
final DatabasesEnum dbDesignation;
/// Database field name
final String dbName;
/// Default value key for preferences
final String? defaultValue;
/// Whether the field is required
final bool required;
const VarTextField({
@@ -26,24 +43,31 @@ class VarTextField extends StatefulWidget {
State<VarTextField> createState() => _VarTextFieldState();
}
/// State class for the variable text field widget
class _VarTextFieldState extends State<VarTextField> {
/// List of previous values from database
List<String> dbVar = [];
@override
void initState() {
super.initState();
// Load default value if field is empty
if (widget.textController.text == "" && widget.defaultValue != null) {
_loadPref();
}
// Load previous values from database
_loadData().then((e) => dbVar = e);
}
/// Load previous values from the appropriate database
/// @return Future<List<String>> List of previous values
Future<List<String>> _loadData() async {
List<Map<String, dynamic>> entries = [];
List<Map<String, dynamic>> templatesEntries = [];
// Get entries from appropriate database
if (widget.dbDesignation == DatabasesEnum.place) {
entries = await PlaceDBHelper().getAllMainEntries();
templatesEntries = await PlaceDBHelper().getAllTemplates();
@@ -54,6 +78,7 @@ class _VarTextFieldState extends State<VarTextField> {
List<String> erg = [];
// Extract values for this field from entries
for (var element in entries) {
for (var key in element.keys) {
if (key == widget.dbName && element[key].toString() != "") {
@@ -62,6 +87,7 @@ class _VarTextFieldState extends State<VarTextField> {
}
}
// Extract values from templates
for (var element in templatesEntries) {
for (var key in element.keys) {
if (key == widget.dbName && element[key].toString() != "") {
@@ -73,6 +99,7 @@ class _VarTextFieldState extends State<VarTextField> {
return erg;
}
/// Load default value from preferences
void _loadPref() {
Future.delayed(Duration.zero, () async {
SharedPreferences prefs = await SharedPreferences.getInstance();
@@ -87,6 +114,7 @@ class _VarTextFieldState extends State<VarTextField> {
Widget build(BuildContext context) {
return Row(
children: [
// Text input field
Expanded(
flex: 5,
child: TextField(
@@ -100,6 +128,7 @@ class _VarTextFieldState extends State<VarTextField> {
},
decoration: InputDecoration(
hintText: widget.localization,
// Border color based on required status and value
enabledBorder:
widget.required
? (widget.textController.text.isEmpty
@@ -128,6 +157,7 @@ class _VarTextFieldState extends State<VarTextField> {
),
),
const Expanded(child: SizedBox(width: 15)),
// Dropdown for previous values
Expanded(
flex: 1,
child: Align(