fixed a lot of things after i broke everything. Just the card is not implemented again yet

time
This commit is contained in:
Nico
2025-05-12 23:09:28 +02:00
parent 97691f3453
commit 74b4648e73
18 changed files with 599 additions and 479 deletions

View File

@@ -4,7 +4,6 @@ import 'package:fforte/methods/place_db_helper.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class VarTextField extends StatefulWidget {
final TextEditingController textController;
final String localization;
@@ -14,22 +13,23 @@ class VarTextField extends StatefulWidget {
final String? otherDefault;
final bool required;
const VarTextField(
{super.key,
const VarTextField({
super.key,
required this.textController,
required this.localization,
required this.dbName,
required this.required,
required this.dbDesignation,
this.defaultValue,
this.otherDefault});
this.otherDefault,
});
@override
State<VarTextField> createState() => _VarTextFieldState();
}
class _VarTextFieldState extends State<VarTextField> {
late Future<List<Map<String, dynamic>>> dbVar;
List<String> dbVar = [];
@override
void initState() {
@@ -43,19 +43,40 @@ class _VarTextFieldState extends State<VarTextField> {
widget.textController.text = widget.otherDefault!;
}
dbVar = _loadData();
_loadData().then((e) => dbVar = e);
}
Future<List<Map<String, dynamic>>> _loadData() async {
Future<List<String>> _loadData() async {
List<Map<String, dynamic>> entries = [];
List<Map<String, dynamic>> templatesEntries = [];
if (widget.dbDesignation == DatabasesEnum.place) {
var entries = await PlaceDBHelper().getAllMainEntries();
var templatesEntries = await PlaceDBHelper().getAllTemplates();
return [...entries, ...templatesEntries];
} else {
var entries = await ExcursionDBHelper().getAllMainEntries();
var templatesEntries = await ExcursionDBHelper().getAllTemplates();
return [...entries, ...templatesEntries];
entries = await PlaceDBHelper().getAllMainEntries();
templatesEntries = await PlaceDBHelper().getAllTemplates();
} else if (widget.dbDesignation == DatabasesEnum.excursion) {
entries = await ExcursionDBHelper().getAllMainEntries();
templatesEntries = await ExcursionDBHelper().getAllTemplates();
}
List<String> erg = [];
for (var element in entries) {
for (var key in element.keys) {
if (key == widget.dbName && element[key].toString() != "") {
erg.add(element[key].toString());
}
}
}
for (var element in templatesEntries) {
for (var key in element.keys) {
if (key == widget.dbName && element[key].toString() != "") {
erg.add(element[key].toString());
}
}
}
return erg;
}
void _loadPref() {
@@ -85,71 +106,53 @@ class _VarTextFieldState extends State<VarTextField> {
},
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,
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)),
Expanded(
flex: 1,
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) {
// Filtern der Daten, um sicherzustellen, dass keine 'null' Werte für den Schlüssel dbName vorhanden sind
var filteredData = snapshot.data!
.where((item) =>
item[widget.dbName] != null &&
item[widget.dbName] != "")
.toList();
var uniqueData = { ...filteredData.map((e) => e[widget.dbName].toString())};
return PopupMenuButton<String>(
onSelected: (String value) {
setState(() {
widget.textController.text = value;
});
},
itemBuilder: (BuildContext context) {
return uniqueData
.map((value) => PopupMenuItem<String>(
value: value,
child: Text(value),
))
.toList();
},
child: const Icon(Icons.arrow_drop_down),
);
} else if (snapshot.hasError) {
return Text('Fehler: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
child: PopupMenuButton<String>(
onSelected: (String value) {
setState(() {
widget.textController.text = value;
});
},
itemBuilder: (BuildContext context) {
return dbVar.map((String item) {
return PopupMenuItem<String>(value: item, child: Text(item));
}).toList();
},
child: const Icon(Icons.arrow_drop_down),
),
),
),
)
),
],
);
}