Proper signatory layout on Task Printout

This commit is contained in:
Marc Rejohn Castillano 2026-02-21 23:44:21 +08:00
parent 74f9511ee3
commit 302d52fe4f

View File

@ -85,13 +85,11 @@ Future<Uint8List> buildTaskPdfBytes(
final profileById = {for (final p in profiles) p.id: p}; final profileById = {for (final p in profiles) p.id: p};
final assignedForTask = assignments.where((a) => a.taskId == task.id).toList() final assignedForTask = assignments.where((a) => a.taskId == task.id).toList()
..sort((a, b) => a.createdAt.compareTo(b.createdAt)); ..sort((a, b) => a.createdAt.compareTo(b.createdAt));
final latestAssignment = assignedForTask.isEmpty // Collect all unique assigned user IDs for this task and map to profile names
? null final assignedUserIds = {for (final a in assignedForTask) a.userId};
: assignedForTask.last; final performedBy = assignedUserIds.isEmpty
final performedBy = latestAssignment == null
? '' ? ''
: (profileById[latestAssignment.userId]?.fullName ?? : assignedUserIds.map((id) => profileById[id]?.fullName ?? id).join(', ');
latestAssignment.userId);
doc.addPage( doc.addPage(
pw.Page( pw.Page(
@ -182,30 +180,43 @@ Future<Uint8List> buildTaskPdfBytes(
child: pw.Text(descriptionText), child: pw.Text(descriptionText),
), ),
pw.SizedBox(height: 12), pw.SizedBox(height: 12),
// Requested/Noted signature lines // Requested/Noted signature lines (bottom-aligned to match Performed/Received)
pw.Row( pw.Row(
crossAxisAlignment: pw.CrossAxisAlignment.end,
children: [ children: [
pw.Expanded( pw.Expanded(
child: pw.Column( child: pw.Container(
children: [ height: 56,
pw.Container(height: 28), child: pw.Column(
pw.Container(height: 1, color: pdf.PdfColors.black), mainAxisAlignment: pw.MainAxisAlignment.end,
pw.SizedBox(height: 6), children: [
pw.Text(requestedBy), pw.Container(height: 1, color: pdf.PdfColors.black),
pw.Text('Requested By'), pw.SizedBox(height: 6),
], pw.Text(
requestedBy,
style: pw.TextStyle(fontWeight: pw.FontWeight.bold),
),
pw.Text('Requested By'),
],
),
), ),
), ),
pw.SizedBox(width: 12), pw.SizedBox(width: 12),
pw.Expanded( pw.Expanded(
child: pw.Column( child: pw.Container(
children: [ height: 56,
pw.Container(height: 28), child: pw.Column(
pw.Container(height: 1, color: pdf.PdfColors.black), mainAxisAlignment: pw.MainAxisAlignment.end,
pw.SizedBox(height: 6), children: [
pw.Text(notedBy), pw.Container(height: 1, color: pdf.PdfColors.black),
pw.Text('Noted by Supervisor/Senior'), 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<Uint8List> buildTaskPdfBytes(
], ],
), ),
pw.SizedBox(height: 12), pw.SizedBox(height: 12),
// Performed/Received signature lines // Signature lines row (fixed) stays aligned regardless of name length
pw.Row( pw.Row(
children: [ children: [
pw.Expanded( pw.Expanded(
child: pw.Column( child: pw.Container(
children: [ height: 24,
pw.Container(height: 28), alignment: pw.Alignment.center,
pw.Container(height: 1, color: pdf.PdfColors.black), child: pw.Container(height: 1, color: pdf.PdfColors.black),
pw.SizedBox(height: 6),
pw.Text(performedBy),
pw.Text('Performed By'),
],
), ),
), ),
pw.SizedBox(width: 12), pw.SizedBox(width: 12),
pw.Expanded( pw.Expanded(
child: pw.Column( child: pw.Container(
children: [ height: 24,
pw.Container(height: 28), alignment: pw.Alignment.center,
pw.Container(height: 1, color: pdf.PdfColors.black), child: pw.Container(height: 1, color: pdf.PdfColors.black),
pw.SizedBox(height: 6),
pw.Text(receivedBy),
pw.Text('Received By'),
],
), ),
), ),
], ],
), ),
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),
),
],
),
], ],
); );
}, },