From 302d52fe4f62fdc0e0134f23c1e4ce6a451deb66 Mon Sep 17 00:00:00 2001 From: Marc Rejohn Castillano Date: Sat, 21 Feb 2026 23:44:21 +0800 Subject: [PATCH] Proper signatory layout on Task Printout --- lib/screens/tasks/task_pdf.dart | 128 ++++++++++++++++++++++---------- 1 file changed, 88 insertions(+), 40 deletions(-) diff --git a/lib/screens/tasks/task_pdf.dart b/lib/screens/tasks/task_pdf.dart index 86899161..976c7b61 100644 --- a/lib/screens/tasks/task_pdf.dart +++ b/lib/screens/tasks/task_pdf.dart @@ -85,13 +85,11 @@ Future buildTaskPdfBytes( final profileById = {for (final p in profiles) p.id: p}; final assignedForTask = assignments.where((a) => a.taskId == task.id).toList() ..sort((a, b) => a.createdAt.compareTo(b.createdAt)); - final latestAssignment = assignedForTask.isEmpty - ? null - : assignedForTask.last; - final performedBy = latestAssignment == null + // Collect all unique assigned user IDs for this task and map to profile names + final assignedUserIds = {for (final a in assignedForTask) a.userId}; + final performedBy = assignedUserIds.isEmpty ? '' - : (profileById[latestAssignment.userId]?.fullName ?? - latestAssignment.userId); + : assignedUserIds.map((id) => profileById[id]?.fullName ?? id).join(', '); doc.addPage( pw.Page( @@ -182,30 +180,43 @@ Future buildTaskPdfBytes( child: pw.Text(descriptionText), ), pw.SizedBox(height: 12), - // Requested/Noted signature lines + // Requested/Noted signature lines (bottom-aligned to match Performed/Received) pw.Row( + crossAxisAlignment: pw.CrossAxisAlignment.end, children: [ pw.Expanded( - child: pw.Column( - children: [ - pw.Container(height: 28), - pw.Container(height: 1, color: pdf.PdfColors.black), - pw.SizedBox(height: 6), - pw.Text(requestedBy), - pw.Text('Requested By'), - ], + child: pw.Container( + height: 56, + child: pw.Column( + mainAxisAlignment: pw.MainAxisAlignment.end, + children: [ + pw.Container(height: 1, color: pdf.PdfColors.black), + pw.SizedBox(height: 6), + pw.Text( + requestedBy, + style: pw.TextStyle(fontWeight: pw.FontWeight.bold), + ), + pw.Text('Requested By'), + ], + ), ), ), pw.SizedBox(width: 12), pw.Expanded( - child: pw.Column( - children: [ - pw.Container(height: 28), - pw.Container(height: 1, color: pdf.PdfColors.black), - pw.SizedBox(height: 6), - pw.Text(notedBy), - pw.Text('Noted by Supervisor/Senior'), - ], + child: pw.Container( + height: 56, + child: pw.Column( + mainAxisAlignment: pw.MainAxisAlignment.end, + children: [ + pw.Container(height: 1, color: pdf.PdfColors.black), + pw.SizedBox(height: 6), + pw.Text( + notedBy, + style: pw.TextStyle(fontWeight: pw.FontWeight.bold), + ), + pw.Text('Noted by Supervisor/Senior'), + ], + ), ), ), ], @@ -236,34 +247,71 @@ Future buildTaskPdfBytes( ], ), pw.SizedBox(height: 12), - // Performed/Received signature lines + // Signature lines row (fixed) — stays aligned regardless of name length pw.Row( children: [ pw.Expanded( - child: pw.Column( - children: [ - pw.Container(height: 28), - pw.Container(height: 1, color: pdf.PdfColors.black), - pw.SizedBox(height: 6), - pw.Text(performedBy), - pw.Text('Performed By'), - ], + child: pw.Container( + height: 24, + alignment: pw.Alignment.center, + child: pw.Container(height: 1, color: pdf.PdfColors.black), ), ), pw.SizedBox(width: 12), pw.Expanded( - child: pw.Column( - children: [ - pw.Container(height: 28), - pw.Container(height: 1, color: pdf.PdfColors.black), - pw.SizedBox(height: 6), - pw.Text(receivedBy), - pw.Text('Received By'), - ], + child: pw.Container( + height: 24, + alignment: pw.Alignment.center, + child: pw.Container(height: 1, color: pdf.PdfColors.black), ), ), ], ), + pw.SizedBox(height: 6), + // Names row: performedBy can be long but won't move the signature line; center names under lines + pw.Row( + children: [ + pw.Expanded( + child: pw.Container( + padding: pw.EdgeInsets.only(right: 6), + alignment: pw.Alignment.center, + child: pw.Text( + performedBy, + textAlign: pw.TextAlign.center, + style: pw.TextStyle(fontWeight: pw.FontWeight.bold), + ), + ), + ), + pw.SizedBox(width: 12), + pw.Expanded( + child: pw.Container( + padding: pw.EdgeInsets.only(left: 6), + alignment: pw.Alignment.center, + child: pw.Text( + receivedBy, + textAlign: pw.TextAlign.center, + style: pw.TextStyle(fontWeight: pw.FontWeight.bold), + ), + ), + ), + ], + ), + pw.SizedBox(height: 6), + // Labels row (centered) + pw.Row( + children: [ + pw.Expanded( + child: pw.Text( + 'Performed By', + textAlign: pw.TextAlign.center, + ), + ), + pw.SizedBox(width: 12), + pw.Expanded( + child: pw.Text('Received By', textAlign: pw.TextAlign.center), + ), + ], + ), ], ); },