bissl weiter
This commit is contained in:
60
lib/screens/sharedWidgets/datum.dart
Normal file
60
lib/screens/sharedWidgets/datum.dart
Normal file
@@ -0,0 +1,60 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
|
||||
class Datum extends StatefulWidget {
|
||||
final DateTime? initDatum;
|
||||
final Function(DateTime) onDateChanged;
|
||||
|
||||
const Datum({super.key, required this.initDatum, required this.onDateChanged});
|
||||
|
||||
@override
|
||||
State<Datum> createState() => _DatumState();
|
||||
}
|
||||
|
||||
class _DatumState extends State<Datum> {
|
||||
DateTime? datum;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
datum = widget.initDatum;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
Row(children: [
|
||||
SizedBox(
|
||||
width: 140,
|
||||
child: ElevatedButton(
|
||||
onPressed: () async {
|
||||
final date = await pickDate();
|
||||
if (date == null) return;
|
||||
setState(() => datum = date);
|
||||
widget.onDateChanged(date);
|
||||
},
|
||||
child: Text(AppLocalizations.of(context)!.pickDate)),
|
||||
),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Text(
|
||||
'${datum?.day}. ${datum?.month}. ${datum?.year}',
|
||||
),
|
||||
]),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<DateTime?> pickDate() async {
|
||||
final date = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: datum!,
|
||||
firstDate: DateTime(2000),
|
||||
lastDate: DateTime(5000));
|
||||
|
||||
return date;
|
||||
}
|
||||
}
|
||||
146
lib/screens/sharedWidgets/var_text_field.dart
Normal file
146
lib/screens/sharedWidgets/var_text_field.dart
Normal file
@@ -0,0 +1,146 @@
|
||||
import 'package:fforte/methods/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;
|
||||
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});
|
||||
|
||||
@override
|
||||
State<VarTextField> createState() => _VarTextFieldState();
|
||||
}
|
||||
|
||||
class _VarTextFieldState extends State<VarTextField> {
|
||||
late Future<List<Map<String, dynamic>>> dbVar;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
if (widget.textController.text == "" && widget.defaultValue != null) {
|
||||
_loadPref();
|
||||
}
|
||||
|
||||
if (widget.otherDefault != null) {
|
||||
widget.textController.text = widget.otherDefault!;
|
||||
}
|
||||
|
||||
dbVar = _loadData();
|
||||
}
|
||||
|
||||
Future<List<Map<String, dynamic>>> _loadData() async {
|
||||
var places = await DBHelper().getPlace();
|
||||
var templates = await DBHelper().getTemplates();
|
||||
return [...places, ...templates];
|
||||
}
|
||||
|
||||
void _loadPref() {
|
||||
Future.delayed(Duration.zero, () async {
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
String bLand = prefs.getString(widget.defaultValue!) ?? "";
|
||||
setState(() {
|
||||
widget.textController.text = bLand;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
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))),
|
||||
)),
|
||||
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();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user