fixed bug that caused duedate to not setting after selecting
This commit is contained in:
@@ -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,81 +64,86 @@ class _TaskEditPageState extends State<TaskEditPage> {
|
|||||||
),
|
),
|
||||||
body: Form(
|
body: Form(
|
||||||
autovalidateMode: AutovalidateMode.onUnfocus,
|
autovalidateMode: AutovalidateMode.onUnfocus,
|
||||||
child: Column(
|
child: Padding(
|
||||||
children: [
|
padding: EdgeInsets.symmetric(
|
||||||
TextFormField(
|
horizontal: MediaQuery.of(context).size.width * 0.05,
|
||||||
autofocus: true,
|
),
|
||||||
controller: titleController,
|
child: Column(
|
||||||
decoration: InputDecoration(label: Text('Title')),
|
children: [
|
||||||
keyboardType: TextInputType.text,
|
TextFormField(
|
||||||
textInputAction: TextInputAction.next,
|
autofocus: true,
|
||||||
),
|
controller: titleController,
|
||||||
TextFormField(
|
decoration: InputDecoration(label: Text('Title')),
|
||||||
controller: descriptionController,
|
keyboardType: TextInputType.text,
|
||||||
decoration: InputDecoration(label: Text('Description')),
|
textInputAction: TextInputAction.next,
|
||||||
keyboardType: TextInputType.text,
|
),
|
||||||
textInputAction: TextInputAction.next,
|
TextFormField(
|
||||||
),
|
controller: descriptionController,
|
||||||
TextFormField(
|
decoration: InputDecoration(label: Text('Description')),
|
||||||
controller: dueDateController,
|
keyboardType: TextInputType.text,
|
||||||
onChanged: (value) {
|
textInputAction: TextInputAction.next,
|
||||||
if (dateTimeValidator(value) == null) {}
|
),
|
||||||
|
TextFormField(
|
||||||
|
controller: dueDateController,
|
||||||
|
onChanged: (value) {
|
||||||
|
if (dateTimeValidator(value) == null) {}
|
||||||
|
|
||||||
setState(() {});
|
setState(() {});
|
||||||
},
|
},
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
label: Text('Due Date'),
|
label: Text('Due Date'),
|
||||||
suffix: IconButton(
|
suffix: IconButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
final result = await onOpenCalendarPickerPressed();
|
final result = await onOpenCalendarPickerPressed();
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
dueDateController.text = getIsoDateString(result);
|
dueDateController.text = getIsoDateString(result);
|
||||||
}
|
}
|
||||||
setState(() {});
|
setState(() {});
|
||||||
},
|
},
|
||||||
icon: Icon(Icons.calendar_month),
|
icon: Icon(Icons.calendar_month),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
|
validator: dateTimeValidator,
|
||||||
|
keyboardType: TextInputType.text,
|
||||||
|
textInputAction: TextInputAction.next,
|
||||||
),
|
),
|
||||||
validator: dateTimeValidator,
|
TextFormField(
|
||||||
keyboardType: TextInputType.text,
|
controller: dueTimeController,
|
||||||
textInputAction: TextInputAction.next,
|
enabled: DateTime.tryParse(dueDateController.text) != null
|
||||||
),
|
? true
|
||||||
TextFormField(
|
: false,
|
||||||
controller: dueTimeController,
|
decoration: InputDecoration(
|
||||||
enabled: DateTime.tryParse(dueDateController.text) != null
|
label: Text('Due Time'),
|
||||||
? true
|
suffix: IconButton(
|
||||||
: false,
|
onPressed: () async {
|
||||||
decoration: InputDecoration(
|
final result = await onOpenTimePickerPressed();
|
||||||
label: Text('Due Time'),
|
if (result != null) {
|
||||||
suffix: IconButton(
|
setState(() {
|
||||||
onPressed: () async {
|
dueTimeController.text = result.format(context);
|
||||||
final result = await onOpenTimePickerPressed();
|
});
|
||||||
if (result != null) {
|
}
|
||||||
setState(() {
|
},
|
||||||
dueTimeController.text = result.format(context);
|
icon: Icon(Icons.schedule),
|
||||||
});
|
),
|
||||||
}
|
|
||||||
},
|
|
||||||
icon: Icon(Icons.schedule),
|
|
||||||
),
|
),
|
||||||
|
validator: timeValidator,
|
||||||
|
keyboardType: TextInputType.text,
|
||||||
|
textInputAction: TextInputAction.next,
|
||||||
),
|
),
|
||||||
validator: timeValidator,
|
TextFormField(
|
||||||
keyboardType: TextInputType.text,
|
controller: categoryController,
|
||||||
textInputAction: TextInputAction.next,
|
decoration: InputDecoration(label: Text('Category')),
|
||||||
),
|
keyboardType: TextInputType.text,
|
||||||
TextFormField(
|
textInputAction: TextInputAction.next,
|
||||||
controller: categoryController,
|
),
|
||||||
decoration: InputDecoration(label: Text('Category')),
|
TextFormField(
|
||||||
keyboardType: TextInputType.text,
|
controller: urlController,
|
||||||
textInputAction: TextInputAction.next,
|
decoration: InputDecoration(label: Text('Url')),
|
||||||
),
|
keyboardType: TextInputType.text,
|
||||||
TextFormField(
|
textInputAction: TextInputAction.next,
|
||||||
controller: urlController,
|
),
|
||||||
decoration: InputDecoration(label: Text('Url')),
|
],
|
||||||
keyboardType: TextInputType.text,
|
),
|
||||||
textInputAction: TextInputAction.next,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
floatingActionButton: FloatingActionButton(
|
floatingActionButton: FloatingActionButton(
|
||||||
|
|||||||
Reference in New Issue
Block a user