@@ -8,9 +8,8 @@ import 'package:taskwarrior/app/utils/constants/utilites.dart';
88import 'package:taskwarrior/app/utils/themes/theme_extension.dart' ;
99import 'package:taskwarrior/app/utils/language/sentence_manager.dart' ;
1010import 'package:taskwarrior/app/v3/db/task_database.dart' ;
11- import 'package:taskwarrior/app/v3/models/annotation.dart' ;
12- import 'package:taskwarrior/app/v3/models/task.dart' ; // Ensure this path is correct for your new model
13- // import 'package:taskwarrior/app/v3/net/modify.dart';
11+ import 'package:taskwarrior/app/v3/models/task.dart' ;
12+ import 'package:taskwarrior/app/v3/net/modify.dart' ;
1413
1514class TaskDetails extends StatefulWidget {
1615 final TaskForC task;
@@ -26,14 +25,6 @@ class _TaskDetailsState extends State<TaskDetails> {
2625 late String status;
2726 late String priority;
2827 late String due;
29- late String start;
30- late String wait;
31- late List <String > tags;
32- late List <String > depends;
33- late String rtype;
34- late String recur;
35- late List <Annotation > annotations;
36-
3728 late TaskDatabase taskDatabase;
3829
3930 bool hasChanges = false ;
@@ -42,22 +33,11 @@ class _TaskDetailsState extends State<TaskDetails> {
4233 void initState () {
4334 super .initState ();
4435 description = widget.task.description;
45- project = widget.task.project ?? '-' ;
36+ project = widget.task.project! ;
4637 status = widget.task.status;
47- priority = widget.task.priority ?? '-' ;
38+ priority = widget.task.priority! ;
4839 due = widget.task.due ?? '-' ;
49- start = widget.task.start ?? '-' ;
50- wait = widget.task.wait ?? '-' ;
51- tags = widget.task.tags ?? [];
52- depends = widget.task.depends ?? [];
53- rtype = widget.task.rtype ?? '-' ;
54- recur = widget.task.recur ?? '-' ;
55- annotations = widget.task.annotations ?? [];
56-
57- due = _buildDate (due); // Format the date for display
58- start = _buildDate (start);
59- wait = _buildDate (wait);
60-
40+ due = _buildDate (due);
6141 setState (() {
6242 taskDatabase = TaskDatabase ();
6343 taskDatabase.open ();
@@ -67,10 +47,6 @@ class _TaskDetailsState extends State<TaskDetails> {
6747 @override
6848 void didChangeDependencies () {
6949 super .didChangeDependencies ();
70- // This part seems redundant if taskDatabase.open() is already in initState
71- // and ideally, the database connection should be managed more robustly
72- // (e.g., singleton, provider, or passed down).
73- // However, keeping it as per original logic, but be aware of potential multiple openings.
7450 taskDatabase = TaskDatabase ();
7551 taskDatabase.open ();
7652 }
@@ -133,7 +109,7 @@ class _TaskDetailsState extends State<TaskDetails> {
133109 _buildSelectableDetail (
134110 '${SentenceManager (currentLanguage : AppSettings .selectedLanguage ).sentences .detailPagePriority }:' ,
135111 priority,
136- ['H' , 'M' , 'L' , '-' ], (value) {
112+ ['H' , 'M' , 'L' ], (value) {
137113 setState (() {
138114 priority = value;
139115 hasChanges = true ;
@@ -147,52 +123,10 @@ class _TaskDetailsState extends State<TaskDetails> {
147123 hasChanges = true ;
148124 });
149125 }),
150- _buildDatePickerDetail (
151- '${SentenceManager (currentLanguage : AppSettings .selectedLanguage ).sentences .detailPageStart }:' ,
152- start, (value) {
153- setState (() {
154- start = value;
155- hasChanges = true ;
156- });
157- }),
158- _buildDatePickerDetail (
159- '${SentenceManager (currentLanguage : AppSettings .selectedLanguage ).sentences .detailPageWait }:' ,
160- wait, (value) {
161- setState (() {
162- wait = value;
163- hasChanges = true ;
164- });
165- }),
166- _buildEditableDetail (
167- '${SentenceManager (currentLanguage : AppSettings .selectedLanguage ).sentences .detailPageTags }:' ,
168- tags.join (', ' ), (value) {
169- setState (() {
170- tags = value.split (',' ).map ((e) => e.trim ()).toList ();
171- hasChanges = true ;
172- });
173- }),
174- _buildEditableDetail ('Depends:' , depends.join (', ' ), (value) {
175- setState (() {
176- depends = value.split (',' ).map ((e) => e.trim ()).toList ();
177- hasChanges = true ;
178- });
179- }),
180- _buildEditableDetail ('Rtype:' , rtype, (value) {
181- setState (() {
182- rtype = value;
183- hasChanges = true ;
184- });
185- }),
186- _buildEditableDetail ('Recur:' , recur, (value) {
187- setState (() {
188- recur = value;
189- hasChanges = true ;
190- });
191- }),
192- _buildDetail ('UUID:' , widget.task.uuid ?? '-' ),
126+ _buildDetail ('UUID:' , widget.task.uuid! ),
193127 _buildDetail (
194128 '${SentenceManager (currentLanguage : AppSettings .selectedLanguage ).sentences .detailPageUrgency }:' ,
195- widget.task.urgency? . toStringAsFixed ( 2 ) ?? '-' ),
129+ widget.task.urgency. toString () ),
196130 _buildDetail (
197131 '${SentenceManager (currentLanguage : AppSettings .selectedLanguage ).sentences .detailPageEnd }:' ,
198132 _buildDate (widget.task.end)),
@@ -202,11 +136,6 @@ class _TaskDetailsState extends State<TaskDetails> {
202136 _buildDetail (
203137 '${SentenceManager (currentLanguage : AppSettings .selectedLanguage ).sentences .detailPageModified }:' ,
204138 _buildDate (widget.task.modified)),
205- _buildDetail (
206- '${SentenceManager (currentLanguage : AppSettings .selectedLanguage ).sentences }:' ,
207- annotations.isNotEmpty
208- ? annotations.map ((e) => e.description).join ('\n ' )
209- : '-' ),
210139 ],
211140 ),
212141 ),
@@ -254,9 +183,7 @@ class _TaskDetailsState extends State<TaskDetails> {
254183 onTap: () async {
255184 final DateTime ? pickedDate = await showDatePicker (
256185 context: context,
257- initialDate: value != '-'
258- ? DateTime .tryParse (value) ?? DateTime .now ()
259- : DateTime .now (),
186+ initialDate: value != '-' ? DateTime .parse (value) : DateTime .now (),
260187 firstDate: DateTime (2000 ),
261188 lastDate: DateTime (2101 ),
262189 builder: (BuildContext context, Widget ? child) {
@@ -269,9 +196,8 @@ class _TaskDetailsState extends State<TaskDetails> {
269196 if (pickedDate != null ) {
270197 final TimeOfDay ? pickedTime = await showTimePicker (
271198 context: context,
272- initialTime: TimeOfDay .fromDateTime (value != '-'
273- ? DateTime .tryParse (value) ?? DateTime .now ()
274- : DateTime .now ()),
199+ initialTime: TimeOfDay .fromDateTime (
200+ value != '-' ? DateTime .parse (value) : DateTime .now ()),
275201 );
276202 if (pickedTime != null ) {
277203 final DateTime fullDateTime = DateTime (
@@ -281,9 +207,6 @@ class _TaskDetailsState extends State<TaskDetails> {
281207 pickedTime.hour,
282208 pickedTime.minute);
283209 onChanged (DateFormat ('yyyy-MM-dd HH:mm:ss' ).format (fullDateTime));
284- } else {
285- // If only date is picked, use current time
286- onChanged (DateFormat ('yyyy-MM-dd HH:mm:ss' ).format (pickedDate));
287210 }
288211 }
289212 },
@@ -491,36 +414,25 @@ class _TaskDetailsState extends State<TaskDetails> {
491414 }
492415
493416 Future <void > _saveTask () async {
494- // Update the TaskForC object with the new values
495- // final updatedTask = TaskForC(
496- // id: widget.task.id,
497- // description: description,
498- // project: project == '-' ? null : project,
499- // status: status,
500- // uuid: widget.task.uuid,
501- // urgency: widget
502- // .task.urgency, // Urgency is typically calculated, not edited directly
503- // priority: priority == '-' ? null : priority,
504- // due: due == '-' ? null : due,
505- // start: start == '-' ? null : start,
506- // end: widget
507- // .task.end, // 'end' is usually set when completed, not edited directly
508- // entry: widget.task.entry, // 'entry' is static
509- // wait: wait == '-' ? null : wait,
510- // modified: DateFormat('yyyy-MM-dd HH:mm:ss')
511- // .format(DateTime.now()), // Update modified time
512- // tags: tags.isEmpty ? null : tags,
513- // depends: depends.isEmpty ? null : depends,
514- // rtype: rtype == '-' ? null : rtype,
515- // recur: recur == '-' ? null : recur,
516- // annotations: annotations.isEmpty ? null : annotations,
517- // );
518-
417+ await taskDatabase.saveEditedTaskInDB (
418+ widget.task.uuid! ,
419+ description,
420+ project,
421+ status,
422+ priority,
423+ due,
424+ );
519425 setState (() {
520426 hasChanges = false ;
521427 });
522- // Assuming modifyTaskOnTaskwarrior takes the updated TaskForC object
523- // await modifyTaskOnTaskwarrior(updatedTask);
428+ modifyTaskOnTaskwarrior (
429+ description,
430+ project,
431+ due,
432+ priority,
433+ status,
434+ widget.task.uuid! ,
435+ );
524436 }
525437}
526438
0 commit comments