let AI comment everything because well... yeah...
This commit is contained in:
@@ -1,8 +1,21 @@
|
||||
// * Shared widget for date selection across the application
|
||||
// * Features:
|
||||
// * - Date picker dialog interface
|
||||
// * - Formatted date display
|
||||
// * - Customizable button label
|
||||
// * - Date range validation
|
||||
// * - Callback for date changes
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Widget for managing date selection
|
||||
/// Provides a button to open date picker and displays selected date
|
||||
class Datum extends StatefulWidget {
|
||||
/// Initial date value
|
||||
final DateTime? initDatum;
|
||||
/// Callback function when date changes
|
||||
final Function(DateTime) onDateChanged;
|
||||
/// Label for the date picker button
|
||||
final String name;
|
||||
|
||||
const Datum(
|
||||
@@ -12,7 +25,9 @@ class Datum extends StatefulWidget {
|
||||
State<Datum> createState() => _DatumState();
|
||||
}
|
||||
|
||||
/// State class for the date selection widget
|
||||
class _DatumState extends State<Datum> {
|
||||
/// Currently selected date
|
||||
DateTime? datum;
|
||||
|
||||
@override
|
||||
@@ -26,6 +41,7 @@ class _DatumState extends State<Datum> {
|
||||
return Row(
|
||||
children: [
|
||||
Row(children: [
|
||||
// Date picker button
|
||||
SizedBox(
|
||||
width: 140,
|
||||
child: ElevatedButton(
|
||||
@@ -40,6 +56,7 @@ class _DatumState extends State<Datum> {
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
// Formatted date display
|
||||
Text(
|
||||
'${datum?.day}. ${datum?.month}. ${datum?.year}',
|
||||
),
|
||||
@@ -48,6 +65,8 @@ class _DatumState extends State<Datum> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Shows date picker dialog and returns selected date
|
||||
/// @return Future<DateTime?> Selected date or null if cancelled
|
||||
Future<DateTime?> pickDate() async {
|
||||
final date = await showDatePicker(
|
||||
context: context,
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user