fixed bug that caused duedate to not setting after selecting

This commit is contained in:
2026-06-17 11:31:28 +02:00
parent f7c0d1050f
commit 12329d20e8
+8 -1
View File
@@ -17,6 +17,7 @@ class TaskEditPage extends StatefulWidget {
class _TaskEditPageState extends State<TaskEditPage> { class _TaskEditPageState extends State<TaskEditPage> {
Task? task; Task? task;
bool isInitialized = true;
final titleController = TextEditingController(); final titleController = TextEditingController();
final descriptionController = TextEditingController(); final descriptionController = TextEditingController();
final categoryController = TextEditingController(); final categoryController = TextEditingController();
@@ -29,7 +30,7 @@ class _TaskEditPageState extends State<TaskEditPage> {
void didChangeDependencies() { void didChangeDependencies() {
super.didChangeDependencies(); super.didChangeDependencies();
task = ModalRoute.of(context)!.settings.arguments as Task?; task = ModalRoute.of(context)!.settings.arguments as Task?;
if (task != null) { if (task != null && !isInitialized) {
titleController.text = task!.title; titleController.text = task!.title;
descriptionController.text = task!.description; descriptionController.text = task!.description;
categoryController.text = task!.category; categoryController.text = task!.category;
@@ -40,6 +41,7 @@ class _TaskEditPageState extends State<TaskEditPage> {
dueTimeController.text = task!.due != null dueTimeController.text = task!.due != null
? TimeOfDay.fromDateTime(task!.due!).format(context) ? TimeOfDay.fromDateTime(task!.due!).format(context)
: ''; : '';
isInitialized = true;
} }
pageTitle = task?.title ?? 'CreateTask'; pageTitle = task?.title ?? 'CreateTask';
} }
@@ -62,6 +64,10 @@ class _TaskEditPageState extends State<TaskEditPage> {
), ),
body: Form( body: Form(
autovalidateMode: AutovalidateMode.onUnfocus, autovalidateMode: AutovalidateMode.onUnfocus,
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: MediaQuery.of(context).size.width * 0.05,
),
child: Column( child: Column(
children: [ children: [
TextFormField( TextFormField(
@@ -139,6 +145,7 @@ class _TaskEditPageState extends State<TaskEditPage> {
], ],
), ),
), ),
),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
onPressed: onSavePressed, onPressed: onSavePressed,
child: Icon(Icons.save), child: Icon(Icons.save),