buildDisplayRow function

DataRow buildDisplayRow({
  1. required BuildContext context,
  2. required BPObservation observation,
  3. required int index,
  4. required VoidCallback onEdit,
  5. required VoidCallback onDelete,
})

Creates a read-only DataRow for displaying a single BPObservation.

This row shows the observation's timestamp, systolic pressure, diastolic pressure, heart rate, feeling, and notes. It also provides an edit button (onEdit) and a delete button (onDelete) for user interactions.

The index can help identify the observation's position in the parent list. The context is used for resolving localizations, themes, or showing UI feedback (e.g. snack bars).

Returns:

  • A DataRow populated with various DataCell widgets representing the observation's fields.

Implementation

DataRow buildDisplayRow({
  required BuildContext context,
  required BPObservation observation,
  required int index,
  required VoidCallback onEdit,
  required VoidCallback onDelete,
}) {
  return DataRow(
    cells: [
      // Timestamp cell.

      DataCell(
        Text(DateFormat('yyyy-MM-dd HH:mm:ss').format(observation.timestamp)),
      ),

      // Systolic cell.

      DataCell(Text(parseNumericInput(observation.systolic))),

      // Diastolic cell.

      DataCell(Text(parseNumericInput(observation.diastolic))),

      // Heart rate cell.

      DataCell(Text(parseNumericInput(observation.heartRate))),

      // Feeling cell.

      DataCell(Text(observation.feeling)),

      // Notes cell (with a max width to limit horizontal space usage).

      DataCell(
        Container(
          constraints: const BoxConstraints(maxWidth: 200),
          child: Text(
            observation.notes,
            overflow: TextOverflow.ellipsis,
            maxLines: 3,
          ),
        ),
      ),

      // Actions cell: edit and delete icons.

      DataCell(
        Row(
          mainAxisSize: MainAxisSize.min,
          children: [
            IconButton(
              icon: const Icon(Icons.edit),
              onPressed: onEdit,
            ),
            IconButton(
              icon: const Icon(Icons.delete),
              onPressed: onDelete,
            ),
          ],
        ),
      ),
    ],
  );
}