Skip to content

Commit

Permalink
♻️: refactor of datetime input
Browse files Browse the repository at this point in the history
  • Loading branch information
PHPLukaas committed Mar 13, 2024
1 parent 96f81e4 commit bb12671
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ class SubmitButton extends StatelessWidget {
final TextEditingController ineController;
final TextEditingController nameController;
final TextEditingController birthDateController;
final DateTime birthDate;

const SubmitButton(
{super.key,
required this.ineController,
required this.nameController,
required this.birthDateController});
required this.birthDateController,
required this.birthDate});

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -46,6 +48,8 @@ class SubmitButton extends StatelessWidget {
final String name = nameController.text.trim();
final String birthDate = birthDateController.text.trim();

print(birthDate);

context
.read<LoginCubit>()
.saveLoginDetails(ine, name, birthDate);
Expand Down
11 changes: 10 additions & 1 deletion frontend/app_student/lib/login/widgets/form/form_login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class FormLoginState extends State<FormLogin> {
final TextEditingController ineController = TextEditingController();
final TextEditingController nameController = TextEditingController();
final TextEditingController birthDateController = TextEditingController();
DateTime birthDate = DateTime.now();

@override
Widget build(BuildContext context) {
Expand All @@ -24,12 +25,20 @@ class FormLoginState extends State<FormLogin> {
child: Column(
children: [
INETextField(controller: ineController),
BirthDateField(controller: birthDateController),
BirthDateField(
controller: birthDateController,
onDateChanged: (newDate) {
setState(() {
birthDate = newDate;
});
},
),
FirstnameTextField(controller: nameController),
SubmitButton(
ineController: ineController,
nameController: nameController,
birthDateController: birthDateController,
birthDate: birthDate,
)
],
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ import 'package:flutter/material.dart';

class BirthDateField extends StatefulWidget {
final TextEditingController controller;
final ValueChanged<DateTime> onDateChanged;

const BirthDateField({super.key, required this.controller});
const BirthDateField({
super.key,
required this.controller,
required this.onDateChanged,
});

@override
BirthDateFieldState createState() => BirthDateFieldState();
Expand All @@ -25,6 +30,7 @@ class BirthDateFieldState extends State<BirthDateField> {
widget.controller.text =
_selectedDate.toLocal().toString().split(' ')[0];
});
widget.onDateChanged(_selectedDate);
}
}

Expand Down

0 comments on commit bb12671

Please sign in to comment.