Files
fforte/lib/addCam/cam_widgets.dart
2024-03-15 19:22:46 +01:00

2591 lines
72 KiB
Dart

// ignore_for_file: non_constant_identifier_names
import 'package:fforte/db_helper.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:geolocator/geolocator.dart';
import 'package:intl/intl.dart';
import 'package:latlong2/latlong.dart';
import 'package:shared_preferences/shared_preferences.dart';
// * Collection of All widgets displayed in the add_cam section
// ! Sort!!
//
// * Step 1 place, camera, terretory
//
// CamId == ID of the camera
class CamId extends StatefulWidget {
final TextEditingController id;
const CamId({super.key, required this.id});
@override
State<CamId> createState() => _CamIdState();
}
class _CamIdState extends State<CamId> {
bool error = false;
String? selectedID;
late Future<List<Map<String, dynamic>>> ids;
@override
void initState() {
super.initState();
ids = DBHelper().getPlace();
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 2,
child: TextField(
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.camLink,
enabledBorder: widget.id.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)),
focusedBorder: widget.id.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)),
),
controller: widget.id,
onChanged: (value) {
setState(() {
widget.id.text = value;
});
},
),
),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomLeft,
child: FutureBuilder<List<Map<String, dynamic>>>(
future: ids,
builder: (BuildContext context,
AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
if (snapshot.hasData) {
return DropdownButton<String>(
items: snapshot.data!
.map((item) => buildMenuItem(item['CID'].toString()))
.toList(),
onChanged: (value) {
setState(
() {
selectedID = value;
widget.id.text = value ?? '';
},
);
},
value: null,
underline: const SizedBox(),
);
} else if (snapshot.hasError) {
return Text('Fehler: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
),
),
)
],
);
}
DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem(
value: item,
child: Text(item),
);
}
// Rudel == Rudel or Terretory or Animal species
class Rudel extends StatefulWidget {
final TextEditingController rudelC;
const Rudel({super.key, required this.rudelC});
@override
State<Rudel> createState() => _RudelState();
}
class _RudelState extends State<Rudel> {
String? selectedRudel;
late Future<List<Map<String, dynamic>>> rudel;
@override
void initState() {
super.initState();
rudel = DBHelper().getPlace();
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 2,
child: TextField(
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.rudel,
enabledBorder: widget.rudelC.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)),
focusedBorder: widget.rudelC.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)),
),
controller: widget.rudelC,
onChanged: (value) => setState(() {
widget.rudelC.text = value;
}),
)),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomLeft,
child: FutureBuilder<List<Map<String, dynamic>>>(
future: rudel,
builder: (BuildContext context,
AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
if (snapshot.hasData) {
return DropdownButton<String>(
items: snapshot.data!
.map((item) => buildMenuItem(item['Rudel'].toString()))
.toList(),
onChanged: (value) {
setState(
() {
selectedRudel = value;
widget.rudelC.text = value ?? '';
},
);
},
value: null,
underline: const SizedBox(),
);
} else if (snapshot.hasError) {
return Text('Fehler: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
),
),
)
],
);
}
DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem(
value: item,
child: Text(item),
);
}
//
// * Step 2 Date, contact, place
//
//
//
//
//
//
//
//
//
//
//
// Standort
// ! completely new page
class Standort extends StatefulWidget {
final Position currentPosition;
final Function(Position) onPositionChange;
const Standort(
{super.key,
required this.currentPosition,
required this.onPositionChange});
@override
StandortState createState() => StandortState();
}
class StandortState extends State<Standort> {
List<Marker> markers = [];
LatLng? selectedPosition;
Position? updatedPosition;
bool saveVisible = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(AppLocalizations.of(context)!.map),
actions: [
Visibility(
visible: saveVisible,
child: Row(
children: [
Text(AppLocalizations.of(context)!.saveMap),
TextButton(
onPressed: () {
if (selectedPosition != null) {
setState(() {
updatedPosition = Position(
longitude: selectedPosition!.longitude,
latitude: selectedPosition!.latitude,
timestamp: DateTime.now(),
accuracy: 0.0,
altitude: 0.0,
altitudeAccuracy: 0.0,
heading: 0.0,
headingAccuracy: 0.0,
speed: 0.0,
speedAccuracy: 0.0);
widget.onPositionChange(updatedPosition!);
});
}
Navigator.pop(context);
},
child: const Icon(Icons.save),
),
],
),
),
],
),
body: FlutterMap(
options: MapOptions(
initialCenter: LatLng(widget.currentPosition.latitude,
widget.currentPosition.longitude),
initialZoom: 13.0,
onTap: _handleTap,
),
children: [
TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'com.example.app',
),
MarkerLayer(markers: markers),
]),
);
}
_handleTap(TapPosition position, LatLng latlng) {
setState(() {
markers.clear();
markers.add(
Marker(
width: 80.0,
height: 80.0,
point: latlng,
child: const Icon(
Icons.location_on,
color: Colors.red,
),
),
);
selectedPosition = latlng;
saveVisible = true;
});
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(
"${AppLocalizations.of(context)!.markerSet}\n${selectedPosition!.latitude}\n${selectedPosition!.longitude}")));
}
}
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
// Datum == Datum der Aufstellung
// datum is the variable where the chosen date is stored
class Datum extends StatefulWidget {
final DateTime? datum;
const Datum({super.key, required this.datum});
@override
State<Datum> createState() => _DatumState();
}
class _DatumState extends State<Datum> {
DateTime? datum = DateTime.now();
@override
Widget build(BuildContext context) {
return Row(
children: [
Column(children: [
Text(
'${datum?.day}. ${datum?.month}. ${datum?.year}',
),
//const SizedBox(
// height: 2,
//),
ElevatedButton(
onPressed: () async {
final date = await pickDate();
if (date == null) return;
setState(() => datum = date);
},
child: Text(AppLocalizations.of(context)!.pickDate)),
]),
],
);
}
Future<DateTime?> pickDate() async {
final date = await showDatePicker(
context: context,
initialDate: datum!,
firstDate: DateTime(2000),
lastDate: DateTime(5000));
if (date == null) return null;
setState(() => datum = date);
var place = {'Datum': DateFormat('yyyy-MM-dd').format(datum!)};
await DBHelper().addPlace(place);
return datum;
}
}
// NameVorname
class NameVorname extends StatefulWidget {
final TextEditingController nameVornameC;
const NameVorname({super.key, required this.nameVornameC});
@override
State<NameVorname> createState() => _NameVornameState();
}
class _NameVornameState extends State<NameVorname> {
String? selectedRudel;
late Future<List<Map<String, dynamic>>> NameVorname;
@override
void initState() {
super.initState();
_loadPref();
NameVorname = DBHelper().getPlace();
}
void _loadPref() {
Future.delayed(Duration.zero, () async {
SharedPreferences prefs = await SharedPreferences.getInstance();
String nameVorname = prefs.getString('nameVorname') ?? "";
setState(() {
widget.nameVornameC.text = nameVorname;
});
});
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 2,
child: TextField(
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.namevorname,
enabledBorder: widget.nameVornameC.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)),
focusedBorder: widget.nameVornameC.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)),
),
controller: widget.nameVornameC,
onChanged: (value) => setState(() {
widget.nameVornameC.text = value;
}),
)),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomLeft,
child: FutureBuilder<List<Map<String, dynamic>>>(
future: NameVorname,
builder: (BuildContext context,
AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
if (snapshot.hasData) {
return DropdownButton<String>(
items: snapshot.data!
.map((item) =>
buildMenuItem(item['NameVorname'].toString()))
.toList(),
onChanged: (value) {
setState(
() {
selectedRudel = value;
widget.nameVornameC.text = value ?? '';
},
);
},
value: null,
underline: const SizedBox(),
);
} else if (snapshot.hasError) {
return Text('Fehler: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
),
),
)
],
);
}
DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem(
value: item,
child: Text(item),
);
}
// PLZOrt
class PLZOrt extends StatefulWidget {
final TextEditingController plzOrtC;
const PLZOrt({super.key, required this.plzOrtC});
@override
State<PLZOrt> createState() => _PLZOrtState();
}
class _PLZOrtState extends State<PLZOrt> {
String? selectedRudel;
late Future<List<Map<String, dynamic>>> PLZOrt;
@override
void initState() {
super.initState();
PLZOrt = DBHelper().getPlace();
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 2,
child: TextField(
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.plzort),
controller: widget.plzOrtC,
onChanged: (value) => setState(() {
widget.plzOrtC.text = value;
}),
)),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomLeft,
child: FutureBuilder<List<Map<String, dynamic>>>(
future: PLZOrt,
builder: (BuildContext context,
AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
if (snapshot.hasData) {
return DropdownButton<String>(
items: snapshot.data!
.map((item) => buildMenuItem(item['PLZOrt'].toString()))
.toList(),
onChanged: (value) {
setState(
() {
selectedRudel = value;
widget.plzOrtC.text = value ?? '';
},
);
},
value: null,
underline: const SizedBox(),
);
} else if (snapshot.hasError) {
return Text('Fehler: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
),
),
)
],
);
}
DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem(
value: item,
child: Text(item),
);
}
// EmailTel
class EmailTel extends StatefulWidget {
final TextEditingController emailTelC;
const EmailTel({super.key, required this.emailTelC});
@override
State<EmailTel> createState() => _EmailTelState();
}
class _EmailTelState extends State<EmailTel> {
String? selectedRudel;
late Future<List<Map<String, dynamic>>> EmailTel;
@override
void initState() {
super.initState();
EmailTel = DBHelper().getPlace();
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 2,
child: TextField(
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.emailtel),
controller: widget.emailTelC,
)),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomLeft,
child: FutureBuilder<List<Map<String, dynamic>>>(
future: EmailTel,
builder: (BuildContext context,
AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
if (snapshot.hasData) {
return DropdownButton<String>(
items: snapshot.data!
.map((item) =>
buildMenuItem(item['EmailTel'].toString()))
.toList(),
onChanged: (value) {
setState(
() {
selectedRudel = value;
widget.emailTelC.text = value ?? '';
},
);
},
value: null,
underline: const SizedBox(),
);
} else if (snapshot.hasError) {
return Text('Fehler: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
),
),
)
],
);
}
DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem(
value: item,
child: Text(item),
);
}
// BLand
class BLand extends StatefulWidget {
final TextEditingController bLandC;
const BLand({super.key, required this.bLandC});
@override
State<BLand> createState() => _BLandState();
}
class _BLandState extends State<BLand> {
String? selectedRudel;
late Future<List<Map<String, dynamic>>> BLand;
@override
void initState() {
super.initState();
_loadPref();
BLand = DBHelper().getPlace();
}
void _loadPref() {
Future.delayed(Duration.zero, () async {
SharedPreferences prefs = await SharedPreferences.getInstance();
String bLand = prefs.getString('bLand') ?? "";
setState(() {
widget.bLandC.text = bLand;
});
});
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 2,
child: TextField(
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.bland,
enabledBorder: widget.bLandC.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)),
focusedBorder: widget.bLandC.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)),
),
controller: widget.bLandC,
onChanged: (value) => setState(() {
widget.bLandC.text = value;
}),
)),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomLeft,
child: FutureBuilder<List<Map<String, dynamic>>>(
future: BLand,
builder: (BuildContext context,
AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
if (snapshot.hasData) {
return DropdownButton<String>(
items: snapshot.data!
.map((item) => buildMenuItem(item['BLand'].toString()))
.toList(),
onChanged: (value) {
setState(
() {
selectedRudel = value;
widget.bLandC.text = value ?? '';
},
);
},
value: null,
underline: const SizedBox(),
);
} else if (snapshot.hasError) {
return Text('Fehler: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
),
),
)
],
);
}
DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem(
value: item,
child: Text(item),
);
}
// Lkr
class Lkr extends StatefulWidget {
final TextEditingController lkrC;
const Lkr({super.key, required this.lkrC});
@override
State<Lkr> createState() => _LkrState();
}
class _LkrState extends State<Lkr> {
String? selectedRudel;
late Future<List<Map<String, dynamic>>> Lkr;
@override
void initState() {
super.initState();
Lkr = DBHelper().getPlace();
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 2,
child: TextField(
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.lkr,
enabledBorder: widget.lkrC.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)),
focusedBorder: widget.lkrC.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)),
),
controller: widget.lkrC,
onChanged: (value) => setState(() {
widget.lkrC.text = value;
}),
)),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomLeft,
child: FutureBuilder<List<Map<String, dynamic>>>(
future: Lkr,
builder: (BuildContext context,
AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
if (snapshot.hasData) {
return DropdownButton<String>(
items: snapshot.data!
.map((item) => buildMenuItem(item['Lkr'].toString()))
.toList(),
onChanged: (value) {
setState(
() {
selectedRudel = value;
widget.lkrC.text = value ?? '';
},
);
},
value: null,
underline: const SizedBox(),
);
} else if (snapshot.hasError) {
return Text('Fehler: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
),
),
)
],
);
}
DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem(
value: item,
child: Text(item),
);
}
// BeiOrt
class BeiOrt extends StatefulWidget {
final TextEditingController beiOrtC;
const BeiOrt({super.key, required this.beiOrtC});
@override
State<BeiOrt> createState() => _BeiOrtState();
}
class _BeiOrtState extends State<BeiOrt> {
String? selectedRudel;
late Future<List<Map<String, dynamic>>> BeiOrt;
@override
void initState() {
super.initState();
BeiOrt = DBHelper().getPlace();
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 2,
child: TextField(
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.beiort,
enabledBorder: widget.beiOrtC.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)),
focusedBorder: widget.beiOrtC.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)),
),
controller: widget.beiOrtC,
onChanged: (value) => setState(() {
widget.beiOrtC.text = value;
}),
)),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomLeft,
child: FutureBuilder<List<Map<String, dynamic>>>(
future: BeiOrt,
builder: (BuildContext context,
AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
if (snapshot.hasData) {
return DropdownButton<String>(
items: snapshot.data!
.map((item) => buildMenuItem(item['BeiOrt'].toString()))
.toList(),
onChanged: (value) {
setState(
() {
selectedRudel = value;
widget.beiOrtC.text = value ?? '';
},
);
},
value: null,
underline: const SizedBox(),
);
} else if (snapshot.hasError) {
return Text('Fehler: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
),
),
)
],
);
}
DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem(
value: item,
child: Text(item),
);
}
// OrtInfo
class OrtInfo extends StatefulWidget {
final TextEditingController ortInfoC;
const OrtInfo({super.key, required this.ortInfoC});
@override
State<OrtInfo> createState() => _OrtInfoState();
}
class _OrtInfoState extends State<OrtInfo> {
String? selectedRudel;
late Future<List<Map<String, dynamic>>> OrtInfo;
@override
void initState() {
super.initState();
OrtInfo = DBHelper().getPlace();
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 2,
child: TextField(
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.ortinfo,),
controller: widget.ortInfoC,
onChanged: (value) => setState(() {
widget.ortInfoC.text = value;
}),
)),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomLeft,
child: FutureBuilder<List<Map<String, dynamic>>>(
future: OrtInfo,
builder: (BuildContext context,
AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
if (snapshot.hasData) {
return DropdownButton<String>(
items: snapshot.data!
.map(
(item) => buildMenuItem(item['OrtInfo'].toString()))
.toList(),
onChanged: (value) {
setState(
() {
selectedRudel = value;
widget.ortInfoC.text = value ?? '';
},
);
},
value: null,
underline: const SizedBox(),
);
} else if (snapshot.hasError) {
return Text('Fehler: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
),
),
)
],
);
}
DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem(
value: item,
child: Text(item),
);
}
// Status
class Status extends StatefulWidget {
final Function(String) onStatusChanged;
final String initialStatus;
const Status(
{super.key, required this.onStatusChanged, this.initialStatus = 'aktiv'});
@override
State<Status> createState() => _StatusState();
}
class _StatusState extends State<Status> {
String? _selectedStatus;
@override
void initState() {
super.initState();
_selectedStatus = widget.initialStatus;
}
@override
Widget build(BuildContext context) {
return Column(
children: [
ListTile(
visualDensity: const VisualDensity(vertical: -4),
title: Text(AppLocalizations.of(context)!.aktiv),
leading: Radio<String>(
value: 'aktiv',
groupValue: _selectedStatus,
onChanged: (value) {
setState(() {
_selectedStatus = value;
widget.onStatusChanged(value!);
});
},
),
),
ListTile(
visualDensity: const VisualDensity(vertical: -4),
title: Text(AppLocalizations.of(context)!.inaktiv),
leading: Radio<String>(
value: 'inaktiv',
groupValue: _selectedStatus,
onChanged: (value) {
setState(() {
_selectedStatus = value;
widget.onStatusChanged(value!);
});
},
),
),
],
);
}
}
// STTyp
class STTyp extends StatefulWidget {
final Function(String) onSTTypChanged;
final String initialSTTyp;
const STTyp(
{super.key,
required this.onSTTypChanged,
this.initialSTTyp = 'opportunistisch'});
@override
State<STTyp> createState() => _STTypState();
}
class _STTypState extends State<STTyp> {
String? _selectedSTTyp;
@override
void initState() {
super.initState();
_selectedSTTyp = widget.initialSTTyp;
}
@override
Widget build(BuildContext context) {
return Column(
children: [
ListTile(
visualDensity: const VisualDensity(vertical: -4),
title: Text(AppLocalizations.of(context)!.opportunistisch),
leading: Radio<String>(
value: 'opportunistisch',
groupValue: _selectedSTTyp,
onChanged: (value) {
setState(() {
_selectedSTTyp = value;
widget.onSTTypChanged(value!);
});
},
),
),
ListTile(
visualDensity: const VisualDensity(vertical: -4),
title: Text(AppLocalizations.of(context)!.systematisch),
leading: Radio<String>(
value: 'systematisch',
groupValue: _selectedSTTyp,
onChanged: (value) {
setState(() {
_selectedSTTyp = value;
widget.onSTTypChanged(value!);
});
},
),
),
],
);
}
}
// FFTyp
class FFTyp extends StatefulWidget {
final TextEditingController ffTypC;
const FFTyp({super.key, required this.ffTypC});
@override
State<FFTyp> createState() => _FFTypState();
}
class _FFTypState extends State<FFTyp> {
String? selectedRudel;
late Future<List<Map<String, dynamic>>> FFTyp;
@override
void initState() {
super.initState();
FFTyp = DBHelper().getPlace();
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 2,
child: TextField(
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.fftyp,
enabledBorder: widget.ffTypC.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)),
focusedBorder: widget.ffTypC.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)),
),
controller: widget.ffTypC,
onChanged: (value) => setState(() {
widget.ffTypC.text = value;
}),
)),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomLeft,
child: FutureBuilder<List<Map<String, dynamic>>>(
future: FFTyp,
builder: (BuildContext context,
AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
if (snapshot.hasData) {
return DropdownButton<String>(
items: snapshot.data!
.map((item) => buildMenuItem(item['FFTyp'].toString()))
.toList(),
onChanged: (value) {
setState(
() {
selectedRudel = value;
widget.ffTypC.text = value ?? '';
},
);
},
value: null,
underline: const SizedBox(),
);
} else if (snapshot.hasError) {
return Text('Fehler: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
),
),
)
],
);
}
DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem(
value: item,
child: Text(item),
);
}
// platzung
class Platzung extends StatefulWidget {
final Function(String) onPlatzungChanged;
final String initialPlatzung;
const Platzung(
{super.key,
required this.onPlatzungChanged,
this.initialPlatzung = 'kirrung'});
@override
State<Platzung> createState() => _PlatzungState();
}
class _PlatzungState extends State<Platzung> {
String? _selectedPlatzung;
@override
void initState() {
super.initState();
_selectedPlatzung = widget.initialPlatzung;
}
@override
Widget build(BuildContext context) {
return Column(
children: [
ListTile(
visualDensity: const VisualDensity(vertical: -4),
title: Text(AppLocalizations.of(context)!.kirrung),
leading: Radio<String>(
value: 'kirrung',
groupValue: _selectedPlatzung,
onChanged: (value) {
setState(() {
_selectedPlatzung = value;
widget.onPlatzungChanged(value!);
});
},
),
),
ListTile(
visualDensity: const VisualDensity(vertical: -4),
title: Text(AppLocalizations.of(context)!.wasserstelle),
leading: Radio<String>(
value: 'wasserstelle',
groupValue: _selectedPlatzung,
onChanged: (value) {
setState(() {
_selectedPlatzung = value;
widget.onPlatzungChanged(value!);
});
},
),
),
ListTile(
visualDensity: const VisualDensity(vertical: -4),
title: Text(AppLocalizations.of(context)!.wald),
leading: Radio<String>(
value: 'wald',
groupValue: _selectedPlatzung,
onChanged: (value) {
setState(() {
_selectedPlatzung = value;
widget.onPlatzungChanged(value!);
});
},
),
),
ListTile(
visualDensity: const VisualDensity(vertical: -4),
title: Text(AppLocalizations.of(context)!.wildwechsel),
leading: Radio<String>(
value: 'wildwechsel',
groupValue: _selectedPlatzung,
onChanged: (value) {
setState(() {
_selectedPlatzung = value;
widget.onPlatzungChanged(value!);
});
},
),
),
ListTile(
visualDensity: const VisualDensity(vertical: -4),
title: Text(AppLocalizations.of(context)!.wegstrasse),
leading: Radio<String>(
value: 'weg/straße',
groupValue: _selectedPlatzung,
onChanged: (value) {
setState(() {
_selectedPlatzung = value;
widget.onPlatzungChanged(value!);
});
},
),
),
ListTile(
visualDensity: const VisualDensity(vertical: -4),
title: Text(AppLocalizations.of(context)!.hofgarten),
leading: Radio<String>(
value: 'hof/garten',
groupValue: _selectedPlatzung,
onChanged: (value) {
setState(() {
_selectedPlatzung = value;
widget.onPlatzungChanged(value!);
});
},
),
),
ListTile(
visualDensity: const VisualDensity(vertical: -4),
title: Text(AppLocalizations.of(context)!.wiesefeld),
leading: Radio<String>(
value: 'wiese/feld/offenfläche',
groupValue: _selectedPlatzung,
onChanged: (value) {
setState(() {
_selectedPlatzung = value;
widget.onPlatzungChanged(value!);
});
},
),
),
],
);
}
}
// FotoFilm
class FotoFilm extends StatefulWidget {
final Function(String) onFotoFilmChanged;
final String initialFotoFilm;
const FotoFilm(
{super.key,
required this.onFotoFilmChanged,
this.initialFotoFilm = 'foto'});
@override
State<FotoFilm> createState() => _FotoFilmState();
}
class _FotoFilmState extends State<FotoFilm> {
String? _selectedFotoFilm;
@override
void initState() {
super.initState();
_selectedFotoFilm = widget.initialFotoFilm;
}
@override
Widget build(BuildContext context) {
return Column(
children: [
ListTile(
visualDensity: const VisualDensity(vertical: -4),
title: Text(AppLocalizations.of(context)!.foto),
leading: Radio<String>(
value: 'foto',
groupValue: _selectedFotoFilm,
onChanged: (value) {
setState(() {
_selectedFotoFilm = value;
widget.onFotoFilmChanged(value!);
});
},
),
),
ListTile(
visualDensity: const VisualDensity(vertical: -4),
title: Text(AppLocalizations.of(context)!.film),
leading: Radio<String>(
value: 'film',
groupValue: _selectedFotoFilm,
onChanged: (value) {
setState(() {
_selectedFotoFilm = value;
widget.onFotoFilmChanged(value!);
});
},
),
),
],
);
}
}
// MEZ
class MEZ extends StatefulWidget {
final Function(String) onMEZChanged;
final String initialMEZ;
const MEZ({super.key, required this.onMEZChanged, this.initialMEZ = 'sommerzeit'});
@override
State<MEZ> createState() => _MEZState();
}
class _MEZState extends State<MEZ> {
String? _selectedMEZ;
@override
void initState() {
super.initState();
_selectedMEZ = widget.initialMEZ;
}
@override
Widget build(BuildContext context) {
return Column(
children: [
ListTile(
visualDensity: const VisualDensity(vertical: -4),
title: Text(AppLocalizations.of(context)!.sommerzeit),
leading: Radio<String>(
value: 'sommerzeit',
groupValue: _selectedMEZ,
onChanged: (value) {
setState(() {
_selectedMEZ = value;
widget.onMEZChanged(value!);
});
},
),
),
ListTile(
visualDensity: const VisualDensity(vertical: -4),
title: Text(AppLocalizations.of(context)!.winterzeit),
leading: Radio<String>(
value: 'winterzeit',
groupValue: _selectedMEZ,
onChanged: (value) {
setState(() {
_selectedMEZ = value;
widget.onMEZChanged(value!);
});
},
),
),
],
);
}
}
// KSchloNr
class KSchloNr extends StatefulWidget {
final TextEditingController kSchloNrC;
const KSchloNr({super.key, required this.kSchloNrC});
@override
State<KSchloNr> createState() => _KSchloNrState();
}
class _KSchloNrState extends State<KSchloNr> {
String? selectedRudel;
late Future<List<Map<String, dynamic>>> KSchloNr;
@override
void initState() {
super.initState();
KSchloNr = DBHelper().getPlace();
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 2,
child: TextField(
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.kschlonr),
controller: widget.kSchloNrC,
)),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomLeft,
child: FutureBuilder<List<Map<String, dynamic>>>(
future: KSchloNr,
builder: (BuildContext context,
AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
if (snapshot.hasData) {
return DropdownButton<String>(
items: snapshot.data!
.map((item) =>
buildMenuItem(item['KSchloNr'].toString()))
.toList(),
onChanged: (value) {
setState(
() {
selectedRudel = value;
widget.kSchloNrC.text = value ?? '';
},
);
},
value: null,
underline: const SizedBox(),
);
} else if (snapshot.hasError) {
return Text('Fehler: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
),
),
)
],
);
}
DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem(
value: item,
child: Text(item),
);
}
// Bearsafe
class Bearsafe extends StatefulWidget {
final Function(String) onBearsafeChanged;
final String initialBearsafe;
const Bearsafe(
{super.key,
required this.onBearsafeChanged,
this.initialBearsafe = 'nein'});
@override
State<Bearsafe> createState() => _BearsafeState();
}
class _BearsafeState extends State<Bearsafe> {
String? _selectedBearsafe;
@override
void initState() {
super.initState();
_selectedBearsafe = widget.initialBearsafe;
}
@override
Widget build(BuildContext context) {
return Column(
children: [
ListTile(
visualDensity: const VisualDensity(vertical: -4),
title: Text(AppLocalizations.of(context)!.nein),
leading: Radio<String>(
value: 'nein',
groupValue: _selectedBearsafe,
onChanged: (value) {
setState(() {
_selectedBearsafe = value;
widget.onBearsafeChanged(value!);
});
},
),
),
ListTile(
visualDensity: const VisualDensity(vertical: -4),
title: Text(AppLocalizations.of(context)!.ja),
leading: Radio<String>(
value: 'ja',
groupValue: _selectedBearsafe,
onChanged: (value) {
setState(() {
_selectedBearsafe = value;
widget.onBearsafeChanged(value!);
});
},
),
),
],
);
}
}
// KontDat
class KontDat extends StatefulWidget {
final DateTime? kontDat;
const KontDat({super.key, required this.kontDat});
@override
State<KontDat> createState() => _KontDatState();
}
class _KontDatState extends State<KontDat> {
DateTime? kontDat = DateTime.now();
@override
Widget build(BuildContext context) {
return Row(
children: [
Column(children: [
Text(
'${kontDat?.day}. ${kontDat?.month}. ${kontDat?.year}',
),
const SizedBox(
height: 8,
),
ElevatedButton(
onPressed: () async {
final date = await pickDate();
if (date == null) return;
setState(() => kontDat = date);
},
child: Text(AppLocalizations.of(context)!.pickkontdat)),
]),
],
);
}
Future<DateTime?> pickDate() async {
final date = await showDatePicker(
context: context,
initialDate: kontDat!,
firstDate: DateTime(2000),
lastDate: DateTime(5000));
if (date == null) return null;
setState(() => kontDat = date);
var place = {'KontDat': DateFormat('yyyy-MM-dd').format(kontDat!)};
await DBHelper().addPlace(place);
return kontDat;
}
}
// AbbauDat
class AbbauDat extends StatefulWidget {
final DateTime? abbauDat;
const AbbauDat({super.key, required this.abbauDat});
@override
State<AbbauDat> createState() => _AbbauDatState();
}
class _AbbauDatState extends State<AbbauDat> {
DateTime? abbauDat = DateTime.now();
@override
Widget build(BuildContext context) {
return Row(
children: [
Column(children: [
Text(
'${abbauDat?.day}. ${abbauDat?.month}. ${abbauDat?.year}',
),
const SizedBox(
height: 8,
),
ElevatedButton(
onPressed: () async {
final date = await pickDate();
if (date == null) return;
setState(() => abbauDat = date);
},
child: Text(AppLocalizations.of(context)!.pickabbaudat)),
]),
],
);
}
Future<DateTime?> pickDate() async {
final date = await showDatePicker(
context: context,
initialDate: abbauDat!,
firstDate: DateTime(2000),
lastDate: DateTime(5000));
if (date == null) return null;
setState(() => abbauDat = date);
var place = {'AbbauDat': DateFormat('yyyy-MM-dd').format(abbauDat!)};
await DBHelper().addPlace(place);
return abbauDat;
}
}
// Auftrag
class Auftrag extends StatefulWidget {
final TextEditingController auftragC;
const Auftrag({super.key, required this.auftragC});
@override
State<Auftrag> createState() => _AuftragState();
}
class _AuftragState extends State<Auftrag> {
String? selectedRudel;
late Future<List<Map<String, dynamic>>> Auftrag;
@override
void initState() {
super.initState();
Auftrag = DBHelper().getPlace();
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 2,
child: TextField(
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.auftrag),
controller: widget.auftragC,
)),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomLeft,
child: FutureBuilder<List<Map<String, dynamic>>>(
future: Auftrag,
builder: (BuildContext context,
AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
if (snapshot.hasData) {
return DropdownButton<String>(
items: snapshot.data!
.map(
(item) => buildMenuItem(item['Auftrag'].toString()))
.toList(),
onChanged: (value) {
setState(
() {
selectedRudel = value;
widget.auftragC.text = value ?? '';
},
);
},
value: null,
underline: const SizedBox(),
);
} else if (snapshot.hasError) {
return Text('Fehler: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
),
),
)
],
);
}
DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem(
value: item,
child: Text(item),
);
}
// Absprachen
class Absprachen extends StatefulWidget {
final TextEditingController absprachenC;
const Absprachen({super.key, required this.absprachenC});
@override
State<Absprachen> createState() => _AbsprachenState();
}
class _AbsprachenState extends State<Absprachen> {
String? selectedRudel;
late Future<List<Map<String, dynamic>>> Absprachen;
@override
void initState() {
super.initState();
Absprachen = DBHelper().getPlace();
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 2,
child: TextField(
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.absprachen),
controller: widget.absprachenC,
)),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomLeft,
child: FutureBuilder<List<Map<String, dynamic>>>(
future: Absprachen,
builder: (BuildContext context,
AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
if (snapshot.hasData) {
return DropdownButton<String>(
items: snapshot.data!
.map((item) =>
buildMenuItem(item['Absprachen'].toString()))
.toList(),
onChanged: (value) {
setState(
() {
selectedRudel = value;
widget.absprachenC.text = value ?? '';
},
);
},
value: null,
underline: const SizedBox(),
);
} else if (snapshot.hasError) {
return Text('Fehler: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
),
),
)
],
);
}
DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem(
value: item,
child: Text(item),
);
}
// SonstBemerkungen
class SonstBemerkungen extends StatefulWidget {
final TextEditingController sonstBemerkungenC;
const SonstBemerkungen({super.key, required this.sonstBemerkungenC});
@override
State<SonstBemerkungen> createState() => _SonstBemerkungenState();
}
class _SonstBemerkungenState extends State<SonstBemerkungen> {
String? selectedRudel;
late Future<List<Map<String, dynamic>>> SonstBemerkungen;
@override
void initState() {
super.initState();
SonstBemerkungen = DBHelper().getPlace();
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 2,
child: TextField(
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.sonstbemerkungen),
controller: widget.sonstBemerkungenC,
)),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomLeft,
child: FutureBuilder<List<Map<String, dynamic>>>(
future: SonstBemerkungen,
builder: (BuildContext context,
AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
if (snapshot.hasData) {
return DropdownButton<String>(
items: snapshot.data!
.map((item) =>
buildMenuItem(item['SonstBemerkungen'].toString()))
.toList(),
onChanged: (value) {
setState(
() {
selectedRudel = value;
widget.sonstBemerkungenC.text = value ?? '';
},
);
},
value: null,
underline: const SizedBox(),
);
} else if (snapshot.hasError) {
return Text('Fehler: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
),
),
)
],
);
}
DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem(
value: item,
child: Text(item),
);
}
// FKontakt1
class FKontakt1 extends StatefulWidget {
final TextEditingController fKontakt1C;
const FKontakt1({super.key, required this.fKontakt1C});
@override
State<FKontakt1> createState() => _FKontakt1State();
}
class _FKontakt1State extends State<FKontakt1> {
String? selectedRudel;
late Future<List<Map<String, dynamic>>> FKontakt1;
@override
void initState() {
super.initState();
FKontakt1 = DBHelper().getPlace();
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 2,
child: TextField(
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.fkontakt1),
controller: widget.fKontakt1C,
)),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomLeft,
child: FutureBuilder<List<Map<String, dynamic>>>(
future: FKontakt1,
builder: (BuildContext context,
AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
if (snapshot.hasData) {
return DropdownButton<String>(
items: snapshot.data!
.map((item) =>
buildMenuItem(item['FKontakt1'].toString()))
.toList(),
onChanged: (value) {
setState(
() {
selectedRudel = value;
widget.fKontakt1C.text = value ?? '';
},
);
},
value: null,
underline: const SizedBox(),
);
} else if (snapshot.hasError) {
return Text('Fehler: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
),
),
)
],
);
}
DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem(
value: item,
child: Text(item),
);
}
// FKontakt2
class FKontakt2 extends StatefulWidget {
final TextEditingController fKontakt2C;
const FKontakt2({super.key, required this.fKontakt2C});
@override
State<FKontakt2> createState() => _FKontakt2State();
}
class _FKontakt2State extends State<FKontakt2> {
String? selectedRudel;
late Future<List<Map<String, dynamic>>> FKontakt2;
@override
void initState() {
super.initState();
FKontakt2 = DBHelper().getPlace();
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 2,
child: TextField(
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.fkontakt2),
controller: widget.fKontakt2C,
)),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomLeft,
child: FutureBuilder<List<Map<String, dynamic>>>(
future: FKontakt2,
builder: (BuildContext context,
AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
if (snapshot.hasData) {
return DropdownButton<String>(
items: snapshot.data!
.map((item) =>
buildMenuItem(item['FKontakt2'].toString()))
.toList(),
onChanged: (value) {
setState(
() {
selectedRudel = value;
widget.fKontakt2C.text = value ?? '';
},
);
},
value: null,
underline: const SizedBox(),
);
} else if (snapshot.hasError) {
return Text('Fehler: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
),
),
)
],
);
}
DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem(
value: item,
child: Text(item),
);
}
// FKontakt3
class FKontakt3 extends StatefulWidget {
final TextEditingController fKontakt3C;
const FKontakt3({super.key, required this.fKontakt3C});
@override
State<FKontakt3> createState() => _FKontakt3State();
}
class _FKontakt3State extends State<FKontakt3> {
String? selectedRudel;
late Future<List<Map<String, dynamic>>> FKontakt3;
@override
void initState() {
super.initState();
FKontakt3 = DBHelper().getPlace();
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 3,
child: TextField(
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.fkontakt3),
controller: widget.fKontakt3C,
)),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomLeft,
child: FutureBuilder<List<Map<String, dynamic>>>(
future: FKontakt3,
builder: (BuildContext context,
AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
if (snapshot.hasData) {
return DropdownButton<String>(
items: snapshot.data!
.map((item) =>
buildMenuItem(item['FKontakt3'].toString()))
.toList(),
onChanged: (value) {
setState(
() {
selectedRudel = value;
widget.fKontakt3C.text = value ?? '';
},
);
},
value: null,
underline: const SizedBox(),
);
} else if (snapshot.hasError) {
return Text('Fehler: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
),
),
)
],
);
}
DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem(
value: item,
child: Text(item),
);
}
// AltStOrt
class AltStOrt extends StatefulWidget {
final TextEditingController altStOrtC;
const AltStOrt({super.key, required this.altStOrtC});
@override
State<AltStOrt> createState() => _AltStOrtState();
}
class _AltStOrtState extends State<AltStOrt> {
String? selectedRudel;
late Future<List<Map<String, dynamic>>> AltStOrt;
@override
void initState() {
super.initState();
AltStOrt = DBHelper().getPlace();
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 3,
child: TextField(
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.altstort),
controller: widget.altStOrtC,
)),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomLeft,
child: FutureBuilder<List<Map<String, dynamic>>>(
future: AltStOrt,
builder: (BuildContext context,
AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
if (snapshot.hasData) {
return DropdownButton<String>(
items: snapshot.data!
.map((item) =>
buildMenuItem(item['AltStOrt'].toString()))
.toList(),
onChanged: (value) {
setState(
() {
selectedRudel = value;
widget.altStOrtC.text = value ?? '';
},
);
},
value: null,
underline: const SizedBox(),
);
} else if (snapshot.hasError) {
return Text('Fehler: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
),
),
)
],
);
}
DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem(
value: item,
child: Text(item),
);
}
// AusVon
class AusVon extends StatefulWidget {
final DateTime? ausVon;
const AusVon({super.key, required this.ausVon});
@override
State<AusVon> createState() => _AusVonState();
}
class _AusVonState extends State<AusVon> {
DateTime? ausVon;
@override
Widget build(BuildContext context) {
return Row(
children: [
Column(children: [
Builder(builder: (context) {
if (ausVon != null) {
return Text('${ausVon?.day}. ${ausVon?.month}. ${ausVon?.year}');
} else {
return Text(AppLocalizations.of(context)!.nichts);
}
}),
const SizedBox(
height: 8,
),
ElevatedButton(
onPressed: () async {
final date = await pickDate();
if (date == null) return;
setState(() => ausVon = date);
},
child: Text(AppLocalizations.of(context)!.ausvon)),
]),
],
);
}
Future<DateTime?> pickDate() async {
final date = await showDatePicker(
context: context,
initialDate: ausVon,
firstDate: DateTime(2000),
lastDate: DateTime(5000));
if (date == null) return null;
setState(() => ausVon = date);
var place = {'AusVon': DateFormat('yyyy-MM-dd').format(ausVon!)};
await DBHelper().addPlace(place);
return ausVon;
}
}
// AusBis
class AusBis extends StatefulWidget {
final DateTime? ausBis;
const AusBis({super.key, required this.ausBis});
@override
State<AusBis> createState() => _AusBisState();
}
class _AusBisState extends State<AusBis> {
DateTime? ausBis;
@override
Widget build(BuildContext context) {
return Row(
children: [
Column(children: [
Builder(builder: (context) {
if (ausBis != null) {
return Text('${ausBis?.day}. ${ausBis?.month}. ${ausBis?.year}');
} else {
return Text(AppLocalizations.of(context)!.nichts);
}
}),
const SizedBox(
height: 8,
),
ElevatedButton(
onPressed: () async {
final date = await pickDate();
if (date == null) return;
setState(() => ausBis = date);
},
child: Text(AppLocalizations.of(context)!.ausbis)),
]),
],
);
}
Future<DateTime?> pickDate() async {
final date = await showDatePicker(
context: context,
initialDate: ausBis,
firstDate: DateTime(2000),
lastDate: DateTime(5000));
if (date == null) return null;
setState(() => ausBis = date);
var place = {'ausBis': DateFormat('yyyy-MM-dd').format(ausBis!)};
await DBHelper().addPlace(place);
return ausBis;
}
}
// KTage1
class KTage1 extends StatefulWidget {
final TextEditingController kTage1C;
const KTage1({super.key, required this.kTage1C});
@override
State<KTage1> createState() => _KTage1State();
}
class _KTage1State extends State<KTage1> {
@override
void initState() {
super.initState();
widget.kTage1C.text = '28';
}
@override
Widget build(BuildContext context) {
return TextField(
keyboardType: TextInputType.number,
controller: widget.kTage1C,
onChanged: (value) => setState(() {
widget.kTage1C.text = value;
}),
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.ktage1,
enabledBorder: widget.kTage1C.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)),
focusedBorder: widget.kTage1C.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)),
),
);
}
}
// KTage2
class KTage2 extends StatefulWidget {
final TextEditingController kTage2C;
const KTage2({super.key, required this.kTage2C});
@override
State<KTage2> createState() => _KTage2State();
}
class _KTage2State extends State<KTage2> {
@override
void initState() {
super.initState();
widget.kTage2C.text = '42';
}
@override
Widget build(BuildContext context) {
return TextField(
keyboardType: TextInputType.number,
controller: widget.kTage2C,
onChanged: (value) => setState(() {
widget.kTage2C.text = value;
}),
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.ktage2,
enabledBorder: widget.kTage2C.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)),
focusedBorder: widget.kTage2C.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)),
),
);
}
}
// IntKomm
class IntKomm extends StatefulWidget {
final TextEditingController intKommC;
const IntKomm({super.key, required this.intKommC});
@override
State<IntKomm> createState() => _IntKommState();
}
class _IntKommState extends State<IntKomm> {
String? selectedRudel;
late Future<List<Map<String, dynamic>>> IntKomm;
@override
void initState() {
super.initState();
IntKomm = DBHelper().getPlace();
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 2,
child: TextField(
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.intkomm),
controller: widget.intKommC,
)),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomLeft,
child: FutureBuilder<List<Map<String, dynamic>>>(
future: IntKomm,
builder: (BuildContext context,
AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
if (snapshot.hasData) {
return DropdownButton<String>(
items: snapshot.data!
.map(
(item) => buildMenuItem(item['IntKomm'].toString()))
.toList(),
onChanged: (value) {
setState(
() {
selectedRudel = value;
widget.intKommC.text = value ?? '';
},
);
},
value: null,
underline: const SizedBox(),
);
} else if (snapshot.hasError) {
return Text('Fehler: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
),
),
)
],
);
}
DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem(
value: item,
child: Text(item),
);
}
// KontSum
class KontSum extends StatefulWidget {
final TextEditingController kontSumC;
const KontSum({super.key, required this.kontSumC});
@override
State<KontSum> createState() => _KontSumState();
}
class _KontSumState extends State<KontSum> {
String? selectedRudel;
late Future<List<Map<String, dynamic>>> KontSum;
@override
void initState() {
super.initState();
KontSum = DBHelper().getPlace();
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 3,
child: TextField(
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.kontsum),
controller: widget.kontSumC,
)),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomLeft,
child: FutureBuilder<List<Map<String, dynamic>>>(
future: KontSum,
builder: (BuildContext context,
AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
if (snapshot.hasData) {
return DropdownButton<String>(
items: snapshot.data!
.map(
(item) => buildMenuItem(item['KontSum'].toString()))
.toList(),
onChanged: (value) {
setState(
() {
selectedRudel = value;
widget.kontSumC.text = value ?? '';
},
);
},
value: null,
underline: const SizedBox(),
);
} else if (snapshot.hasError) {
return Text('Fehler: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
),
),
)
],
);
}
DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem(
value: item,
child: Text(item),
);
}