begin with using one widget for all the text fields

This commit is contained in:
2024-04-20 15:45:43 +02:00
parent e70b49e3a7
commit 5e8ed05c41
4 changed files with 223 additions and 104 deletions

View File

@@ -10,6 +10,7 @@ nach koordinaten lkr auswählen (esri-leaflet-geocoder)
fix ktage und nebeneinander positioniere
textdateien auch an server senden
error check wenn dateiauswahl abgebrochen wurde einfügen
save option einfügen nur zum speichern
keine ahnung obs funktioniert:
eintrg in db wenn http response (in sent column)

View File

@@ -256,7 +256,7 @@ class _AddCamMainState extends State<AddCamMain> {
child: Text(AppLocalizations.of(context)!.template)),
TextButton(
onPressed: () async {
saveFile();
saveData();
_httpRequest();
Navigator.pushNamedAndRemoveUntil(
// ignore: use_build_context_synchronously
@@ -412,7 +412,12 @@ class _AddCamMainState extends State<AddCamMain> {
children: [
Align(
alignment: Alignment.bottomLeft,
child: Standort(standortC: standortC),
child: RequiredVarTextField(
required: true,
dbName: "Standort",
textController: standortC,
localization: AppLocalizations.of(context)!.altstort,
),
),
const SizedBox(
height: 1,
@@ -447,6 +452,7 @@ class _AddCamMainState extends State<AddCamMain> {
});
},
),
RequiredVarTextField(textController: betreuungC, localization: AppLocalizations.of(context)!.betreuung, dbName: "KontSum", required: false),
Betreuung(betreuungC: betreuungC),
const SizedBox(
height: 20,
@@ -510,7 +516,7 @@ class _AddCamMainState extends State<AddCamMain> {
],
)),
// Second step
// Second step
Step(
title: Text(AppLocalizations.of(context)!.secondstep),
content: Column(
@@ -699,7 +705,7 @@ class _AddCamMainState extends State<AddCamMain> {
))
];
// Here the site is built inclusive the steps from above
// Here the site is built with the steps from above
return Scaffold(
appBar: AppBar(title: Text(AppLocalizations.of(context)!.addplace)),
body: PageTransitionSwitcher(

View File

@@ -16,6 +16,192 @@ import 'package:shared_preferences/shared_preferences.dart';
// * Step 1 place, camera, terretory
//
class RequiredVarTextField extends StatefulWidget {
final TextEditingController textController;
final String localization;
final String dbName;
final bool required;
const RequiredVarTextField(
{super.key,
required this.textController,
required this.localization,
required this.dbName, required this.required});
@override
State<RequiredVarTextField> createState() => _RequiredVarTextFieldState();
}
class _RequiredVarTextFieldState extends State<RequiredVarTextField> {
late Future<List<Map<String, dynamic>>> dbVar;
@override
void initState() {
super.initState();
dbVar = DBHelper().getPlace();
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 3,
child: TextField(
controller: widget.textController,
keyboardType: TextInputType.multiline,
maxLines: null,
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))
),
)),
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) {
return PopupMenuButton<String>(
onSelected: (String value) {
setState(() {
widget.textController.text = value;
});
},
itemBuilder: (BuildContext context) {
return snapshot.data!
.map((item) => PopupMenuItem<String>(
value: item[widget.dbName].toString(),
child: Text(item[widget.dbName].toString()),
))
.toList();
},
child: const Icon(Icons.arrow_drop_down),
);
} else if (snapshot.hasError) {
return Text('Fehler: ${snapshot.error}');
} else {
return const CircularProgressIndicator();
}
},
),
),
)
],
);
}
DropdownMenuItem<String> buildMenuItem(String item) => DropdownMenuItem(
value: item,
child: Text(item),
);
}
// Standort
class Standort extends StatefulWidget {
final TextEditingController standortC;
final String localization;
const Standort(
{super.key, required this.standortC, required this.localization});
@override
State<RequiredVarTextField> createState() => _RequiredVarTextFieldState();
}
class _StandortState extends State<RequiredVarTextField> {
late Future<List<Map<String, dynamic>>> Standort;
@override
void initState() {
super.initState();
Standort = DBHelper().getPlace();
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 3,
child: TextField(
keyboardType: TextInputType.multiline,
maxLines: null,
decoration: InputDecoration(
hintText: widget.localization,
enabledBorder: widget.textController.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)),
focusedBorder: widget.textController.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)),
),
controller: widget.textController,
)),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomLeft,
child: FutureBuilder<List<Map<String, dynamic>>>(
future: Standort,
builder: (BuildContext context,
AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
if (snapshot.hasData) {
return DropdownButton<String>(
items: snapshot.data!
.map((item) =>
buildMenuItem(item['Standort'].toString()))
.toList(),
onChanged: (value) {
setState(
() {
widget.textController.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),
);
}
// CamId == ID of the camera
class CamId extends StatefulWidget {
@@ -45,8 +231,8 @@ class _CamIdState extends State<CamId> {
Expanded(
flex: 2,
child: TextField(
keyboardType: TextInputType.multiline,
maxLines: null,
keyboardType: TextInputType.multiline,
maxLines: null,
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.camLink,
enabledBorder: widget.id.text.isEmpty
@@ -233,7 +419,9 @@ class Karte extends StatefulWidget {
}
class KarteState extends State<Karte> {
List<Marker> markers = [const Marker(point: LatLng(0, 0), child: Icon(Icons.location_on))];
List<Marker> markers = [
const Marker(point: LatLng(0, 0), child: Icon(Icons.location_on))
];
LatLng? selectedPosition;
Position? updatedPosition;
bool saveVisible = false;
@@ -241,7 +429,15 @@ class KarteState extends State<Karte> {
@override
void initState() {
super.initState();
markers = [Marker(point: LatLng(widget.currentPosition.latitude, widget.currentPosition.longitude), child: const Icon(Icons.location_on, color: Colors.red,))];
markers = [
Marker(
point: LatLng(widget.currentPosition.latitude,
widget.currentPosition.longitude),
child: const Icon(
Icons.location_on,
color: Colors.red,
))
];
}
@override
@@ -283,9 +479,12 @@ class KarteState extends State<Karte> {
],
),
body: FlutterMap(
mapController: MapController(),
mapController: MapController(),
options: MapOptions(
interactionOptions: const InteractionOptions(flags: InteractiveFlag.pinchZoom | InteractiveFlag.drag | InteractiveFlag.pinchMove),
interactionOptions: const InteractionOptions(
flags: InteractiveFlag.pinchZoom |
InteractiveFlag.drag |
InteractiveFlag.pinchMove),
initialCenter: LatLng(widget.currentPosition.latitude,
widget.currentPosition.longitude),
initialZoom: 16.0,
@@ -406,7 +605,7 @@ class Adresse1 extends StatefulWidget {
const Adresse1({super.key, required this.adresse1C});
@override
State<Adresse1> createState() => _Adresse1State();
State<Adresse1> createState() => _Adresse1State();
}
class _Adresse1State extends State<Adresse1> {
@@ -551,7 +750,8 @@ class _Adresse2State extends State<Adresse2> {
if (snapshot.hasData) {
return DropdownButton<String>(
items: snapshot.data!
.map((item) => buildMenuItem(item['Adresse2'].toString()))
.map((item) =>
buildMenuItem(item['Adresse2'].toString()))
.toList(),
onChanged: (value) {
setState(
@@ -1721,7 +1921,8 @@ class _AbbauDatState extends State<AbbauDat> {
),
Builder(builder: (context) {
if (abbauDat != null) {
return Text('${abbauDat?.day}. ${abbauDat?.month}. ${abbauDat?.year}');
return Text(
'${abbauDat?.day}. ${abbauDat?.month}. ${abbauDat?.year}');
} else {
return Text(AppLocalizations.of(context)!.nichts);
}
@@ -2216,96 +2417,6 @@ class _FKontakt3State extends State<FKontakt3> {
);
}
// Standort
class Standort extends StatefulWidget {
final TextEditingController standortC;
const Standort({super.key, required this.standortC});
@override
State<Standort> createState() => _StandortState();
}
class _StandortState extends State<Standort> {
String? selectedRudel;
late Future<List<Map<String, dynamic>>> Standort;
@override
void initState() {
super.initState();
Standort = DBHelper().getPlace();
}
@override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
flex: 3,
child: TextField(
keyboardType: TextInputType.multiline,
maxLines: null,
decoration: InputDecoration(
hintText: AppLocalizations.of(context)!.altstort,
enabledBorder: widget.standortC.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)),
focusedBorder: widget.standortC.text.isEmpty
? const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red))
: const UnderlineInputBorder(
borderSide: BorderSide(color: Colors.green)),
),
controller: widget.standortC,
)),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomLeft,
child: FutureBuilder<List<Map<String, dynamic>>>(
future: Standort,
builder: (BuildContext context,
AsyncSnapshot<List<Map<String, dynamic>>> snapshot) {
if (snapshot.hasData) {
return DropdownButton<String>(
items: snapshot.data!
.map((item) =>
buildMenuItem(item['Standort'].toString()))
.toList(),
onChanged: (value) {
setState(
() {
selectedRudel = value;
widget.standortC.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),
);
}
// KTage1
class KTage1 extends StatefulWidget {

View File

@@ -46,4 +46,5 @@
21 mär 4h 15 min
23 mär 2h 15 min
24 mär 1h
26 mär beginn 10:20
26 mär 45 min
20 mär 1h 30 min