continued hinweise widget (doesnt save the strings yet); splittet up databases

This commit is contained in:
Nico
2025-04-29 23:01:43 +02:00
parent 7c7760f356
commit 8997ff0576
9 changed files with 1177 additions and 916 deletions

View File

@@ -1,4 +1,6 @@
import 'package:fforte/methods/db_helper.dart';
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';
@@ -6,19 +8,21 @@ import 'package:shared_preferences/shared_preferences.dart';
class VarTextField extends StatefulWidget {
final TextEditingController textController;
final String localization;
final DatabasesEnum dbDesignation;
final String dbName;
final String? defaultValue;
final String? otherDefault;
final bool required;
const VarTextField(
{super.key,
required this.textController,
required this.localization,
required this.dbName,
required this.required,
this.defaultValue,
this.otherDefault});
{super.key,
required this.textController,
required this.localization,
required this.dbName,
required this.required,
required this.dbDesignation,
this.defaultValue,
this.otherDefault});
@override
State<VarTextField> createState() => _VarTextFieldState();
@@ -43,9 +47,15 @@ class _VarTextFieldState extends State<VarTextField> {
}
Future<List<Map<String, dynamic>>> _loadData() async {
var places = await DBHelper().getPlace();
var templates = await DBHelper().getTemplates();
return [...places, ...templates];
if (widget.dbDesignation == DatabasesEnum.excursion) {
var entries = await PlaceDBHelper().getPlace();
var templatesEntries = await PlaceDBHelper().getTemplates();
return [...entries, ...templatesEntries];
} else {
var entries = await ExcursionDBHelper().getExcursionen();
var templatesEntries = await ExcursionDBHelper().getTemplates();
return [...entries, ...templatesEntries];
}
}
void _loadPref() {
@@ -63,35 +73,35 @@ class _VarTextFieldState extends State<VarTextField> {
return Row(
children: [
Expanded(
flex: 5,
child: TextField(
controller: widget.textController,
keyboardType: TextInputType.multiline,
maxLines: null,
onChanged: (value) {
setState(() {
widget.textController.text = value;
});
},
decoration: InputDecoration(
hintText: widget.localization,
enabledBorder: widget.required
? (widget.textController.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey)),
focusedBorder: widget.required
? (widget.textController.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey))),
)),
flex: 5,
child: TextField(
controller: widget.textController,
keyboardType: TextInputType.multiline,
maxLines: null,
onChanged: (value) {
setState(() {
widget.textController.text = value;
});
},
decoration: InputDecoration(
hintText: widget.localization,
enabledBorder: widget.required
? (widget.textController.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey)),
focusedBorder: widget.required
? (widget.textController.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey))),
)),
const Expanded(
child: SizedBox(
width: 15,
@@ -102,10 +112,10 @@ class _VarTextFieldState extends State<VarTextField> {
child: Align(
alignment: Alignment.bottomLeft,
child: FutureBuilder<List<Map<String, dynamic>>>(
future: dbVar,
builder: (BuildContext context,
AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
if (snapshot.hasData) {
future: dbVar,
builder: (BuildContext context,
AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
if (snapshot.hasData) {
// Filtern der Daten, um sicherzustellen, dass keine 'null' Werte für den Schlüssel dbName vorhanden sind
var filteredData = snapshot.data!
.where((item) =>
@@ -136,8 +146,8 @@ class _VarTextFieldState extends State<VarTextField> {
} else {
return const CircularProgressIndicator();
}
},
),
},
),
),
)
],