getRectCallback method

  1. @override
RectCallback getRectCallback (RenderBox referenceBox)
override

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).

Implementation

@override
RectCallback getRectCallback(RenderBox referenceBox) {
  return () {
    RenderObject cell = referenceBox;
    AbstractNode table = cell.parent;
    final Matrix4 transform = Matrix4.identity();
    while (table is RenderObject && table is! RenderTable) {
      final RenderTable parentBox = table;
      parentBox.applyPaintTransform(cell, transform);
      assert(table == cell.parent);
      cell = table;
      table = table.parent;
    }
    if (table is RenderTable) {
      final TableCellParentData cellParentData = cell.parentData;
      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);
    }
    return Rect.zero;
  };
}