getRectCallback method Null safety

  1. @override
RectCallback getRectCallback(
  1. RenderBox referenceBox

The rectangle to use for the highlight effect and for clipping the splash effects if containedInkWell is true.

This method is intended to be overridden by descendants that specialize InkResponse for unusual cases. For example, TableRowInkWell implements this method to return the rectangle corresponding to the row that the widget is in.

The default behavior returns null, which is equivalent to returning the referenceBox argument's bounding box (though slightly more efficient).


RectCallback getRectCallback(RenderBox referenceBox) {
  return () {
    RenderObject cell = referenceBox;
    AbstractNode? table = cell.parent;
    final Matrix4 transform = Matrix4.identity();
    while (table is RenderObject && table is! RenderTable) {
      table.applyPaintTransform(cell, transform);
      assert(table == cell.parent);
      cell = table;
      table = table.parent;
    if (table is RenderTable) {
      final TableCellParentData cellParentData = cell.parentData! as TableCellParentData;
      assert(cellParentData.y != null);
      final Rect rect = table.getRowBox(cellParentData.y!);
      // The rect is in the table's coordinate space. We need to change it to the
      // TableRowInkWell's coordinate space.
      table.applyPaintTransform(cell, transform);
      final Offset? offset = MatrixUtils.getAsTranslation(transform);
      if (offset != null) {
        return rect.shift(-offset);