diff --git a/lib/pages/task_edit_page.dart b/lib/pages/task_edit_page.dart index a5fcc29..7e06501 100644 --- a/lib/pages/task_edit_page.dart +++ b/lib/pages/task_edit_page.dart @@ -17,6 +17,7 @@ class TaskEditPage extends StatefulWidget { class _TaskEditPageState extends State { Task? task; + bool isInitialized = true; final titleController = TextEditingController(); final descriptionController = TextEditingController(); final categoryController = TextEditingController(); @@ -29,7 +30,7 @@ class _TaskEditPageState extends State { void didChangeDependencies() { super.didChangeDependencies(); task = ModalRoute.of(context)!.settings.arguments as Task?; - if (task != null) { + if (task != null && !isInitialized) { titleController.text = task!.title; descriptionController.text = task!.description; categoryController.text = task!.category; @@ -40,6 +41,7 @@ class _TaskEditPageState extends State { dueTimeController.text = task!.due != null ? TimeOfDay.fromDateTime(task!.due!).format(context) : ''; + isInitialized = true; } pageTitle = task?.title ?? 'CreateTask'; } @@ -62,81 +64,86 @@ class _TaskEditPageState extends State { ), body: Form( autovalidateMode: AutovalidateMode.onUnfocus, - child: Column( - children: [ - TextFormField( - autofocus: true, - controller: titleController, - decoration: InputDecoration(label: Text('Title')), - keyboardType: TextInputType.text, - textInputAction: TextInputAction.next, - ), - TextFormField( - controller: descriptionController, - decoration: InputDecoration(label: Text('Description')), - keyboardType: TextInputType.text, - textInputAction: TextInputAction.next, - ), - TextFormField( - controller: dueDateController, - onChanged: (value) { - if (dateTimeValidator(value) == null) {} + child: Padding( + padding: EdgeInsets.symmetric( + horizontal: MediaQuery.of(context).size.width * 0.05, + ), + child: Column( + children: [ + TextFormField( + autofocus: true, + controller: titleController, + decoration: InputDecoration(label: Text('Title')), + keyboardType: TextInputType.text, + textInputAction: TextInputAction.next, + ), + TextFormField( + controller: descriptionController, + decoration: InputDecoration(label: Text('Description')), + keyboardType: TextInputType.text, + textInputAction: TextInputAction.next, + ), + TextFormField( + controller: dueDateController, + onChanged: (value) { + if (dateTimeValidator(value) == null) {} - setState(() {}); - }, - decoration: InputDecoration( - label: Text('Due Date'), - suffix: IconButton( - onPressed: () async { - final result = await onOpenCalendarPickerPressed(); - if (result != null) { - dueDateController.text = getIsoDateString(result); - } - setState(() {}); - }, - icon: Icon(Icons.calendar_month), + setState(() {}); + }, + decoration: InputDecoration( + label: Text('Due Date'), + suffix: IconButton( + onPressed: () async { + final result = await onOpenCalendarPickerPressed(); + if (result != null) { + dueDateController.text = getIsoDateString(result); + } + setState(() {}); + }, + icon: Icon(Icons.calendar_month), + ), ), + validator: dateTimeValidator, + keyboardType: TextInputType.text, + textInputAction: TextInputAction.next, ), - validator: dateTimeValidator, - keyboardType: TextInputType.text, - textInputAction: TextInputAction.next, - ), - TextFormField( - controller: dueTimeController, - enabled: DateTime.tryParse(dueDateController.text) != null - ? true - : false, - decoration: InputDecoration( - label: Text('Due Time'), - suffix: IconButton( - onPressed: () async { - final result = await onOpenTimePickerPressed(); - if (result != null) { - setState(() { - dueTimeController.text = result.format(context); - }); - } - }, - icon: Icon(Icons.schedule), + TextFormField( + controller: dueTimeController, + enabled: DateTime.tryParse(dueDateController.text) != null + ? true + : false, + decoration: InputDecoration( + label: Text('Due Time'), + suffix: IconButton( + onPressed: () async { + final result = await onOpenTimePickerPressed(); + if (result != null) { + setState(() { + dueTimeController.text = result.format(context); + }); + } + }, + icon: Icon(Icons.schedule), + ), ), + validator: timeValidator, + keyboardType: TextInputType.text, + textInputAction: TextInputAction.next, ), - validator: timeValidator, - keyboardType: TextInputType.text, - textInputAction: TextInputAction.next, - ), - TextFormField( - controller: categoryController, - decoration: InputDecoration(label: Text('Category')), - keyboardType: TextInputType.text, - textInputAction: TextInputAction.next, - ), - TextFormField( - controller: urlController, - decoration: InputDecoration(label: Text('Url')), - keyboardType: TextInputType.text, - textInputAction: TextInputAction.next, - ), - ], + TextFormField( + controller: categoryController, + decoration: InputDecoration(label: Text('Category')), + keyboardType: TextInputType.text, + textInputAction: TextInputAction.next, + ), + TextFormField( + controller: urlController, + decoration: InputDecoration(label: Text('Url')), + keyboardType: TextInputType.text, + textInputAction: TextInputAction.next, + ), + ], + ), ), ), floatingActionButton: FloatingActionButton(