149 lines
4.7 KiB
Dart
149 lines
4.7 KiB
Dart
import 'package:ernaehrung/android/components/form/form_builder_text_field_component.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
|
import 'package:hive/hive.dart';
|
|
import '../../models/form_builder.dart';
|
|
import '../../models/user.dart';
|
|
import '../../pages/nav_pages/main_page.dart';
|
|
|
|
class FormBuilderComponent extends StatefulWidget {
|
|
final bool lockTextFields;
|
|
|
|
const FormBuilderComponent({Key? key, required this.lockTextFields})
|
|
: super(key: key);
|
|
|
|
@override
|
|
State<FormBuilderComponent> createState() => _FormBuilderComponentState();
|
|
}
|
|
|
|
class _FormBuilderComponentState extends State<FormBuilderComponent> {
|
|
final formKey = GlobalKey<FormBuilderState>();
|
|
|
|
final List<FormTextField> listOfTextField = [
|
|
FormTextField(
|
|
"vorname",
|
|
TextInputType.text,
|
|
30,
|
|
"Der Vorname sollte maximal 30 Zeichen lang sein",
|
|
"Der Vorname sollte mindestens 2 Zeichen lang sein",
|
|
2,
|
|
null,
|
|
null,
|
|
null,
|
|
null),
|
|
FormTextField(
|
|
"nachname",
|
|
TextInputType.text,
|
|
30,
|
|
"Der Nachname sollte maximal 30 Zeichen lang sein",
|
|
"Der Nachname sollte mindestens 2 Zeichen lang sein",
|
|
2,
|
|
null,
|
|
null,
|
|
null,
|
|
null),
|
|
FormTextField(
|
|
"gewicht",
|
|
TextInputType.number,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
200,
|
|
10,
|
|
"Der Gewicht sollte maximal 200 kg sein",
|
|
"Der Gewicht sollte mindestens 10 kg sein"),
|
|
FormTextField(
|
|
"groesse",
|
|
TextInputType.number,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
230,
|
|
60,
|
|
"Die Größe sollte maximal 230cm sein",
|
|
"Die Größe sollte mindestens 60cm sein"),
|
|
FormTextField(
|
|
"alter",
|
|
TextInputType.number,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
99,
|
|
6,
|
|
"Das Alter sollte maximal 99 Jahre alt sein",
|
|
"Das Alter sollte mindestens 6 Jahre alt sein"),
|
|
FormTextField(
|
|
"kalorien",
|
|
TextInputType.number,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
30000,
|
|
1000,
|
|
"Die Kalorienanzahl sollte mindestens 30000 Kcal sein",
|
|
"Die Kalorienanzahl sollte mindestens 1000 Kcal sein")
|
|
];
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
print("widget enable ${widget.lockTextFields}");
|
|
return FormBuilder(
|
|
key: formKey,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(8),
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
ListView.builder(
|
|
primary: false,
|
|
itemCount: listOfTextField.length,
|
|
shrinkWrap: true,
|
|
itemBuilder: (context, index) {
|
|
print(listOfTextField[index]);
|
|
return FormBuilderTextFieldComponent(
|
|
true, listOfTextField[index]);
|
|
}),
|
|
Container(
|
|
margin:
|
|
const EdgeInsets.symmetric(vertical: 8, horizontal: 0),
|
|
width: double.infinity,
|
|
child: ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
minimumSize: const Size.fromHeight(40), //
|
|
backgroundColor: const Color(0xFF6E7BFB),
|
|
foregroundColor: const Color(0xFFffffff),
|
|
shape: const StadiumBorder(),
|
|
),
|
|
onPressed: () {
|
|
final Box box = Hive.box<User>("USER_BOX");
|
|
box.put(
|
|
"USER",
|
|
User(
|
|
formKey.currentState?.fields['vorname']?.value,
|
|
formKey.currentState?.fields['nachname']?.value,
|
|
int.parse(formKey
|
|
.currentState?.fields['gewicht']?.value),
|
|
int.parse(formKey
|
|
.currentState?.fields['groesse']?.value),
|
|
int.parse(
|
|
formKey.currentState?.fields['alter']?.value),
|
|
int.parse(formKey
|
|
.currentState?.fields['kalorien']?.value)));
|
|
|
|
print(box.get("USER"));
|
|
|
|
Navigator.of(context).pushReplacement(MaterialPageRoute(
|
|
builder: (BuildContext context) => const MainPage()));
|
|
},
|
|
child: const Text("Eingaben bestätigen"),
|
|
)),
|
|
],
|
|
)),
|
|
));
|
|
}
|
|
}
|