expressivePaintFocusRing function

void expressivePaintFocusRing(
  1. Canvas canvas,
  2. Rect rect,
  3. OutlinedBorder shape, {
  4. required Color color,
  5. required double thickness,
  6. required double offset,
  7. TextDirection? textDirection,
  8. bool inward = false,
  9. Color? gap,
})

Strokes the focus ring, thickness wide in color, round shape laid on rect: offset out from its edge (the stroke's centre that plus half the stroke), concentric with a rounded rectangle (each corner's radius grown by the same, a square corner kept square), the shape's own outline grown outward otherwise.

inward (rows stacked flush, as Material's web list items do) draws it inside rect instead, its outer edge on the part's edge and its corners the part's less half the stroke: a ring a neighbour painted after it can never cover. An inward ring lies on the face, so where the face is filled gap puts an opaque band of offset in that colour (the surface) between the ring and the rest of the face, concentric, as the outward ring's offset leaves one: a ring the fill matches (a selected segment in primary reads as secondary does) still shows.

Implementation

void expressivePaintFocusRing(
  Canvas canvas,
  Rect rect,
  OutlinedBorder shape, {
  required Color color,
  required double thickness,
  required double offset,
  TextDirection? textDirection,
  bool inward = false,
  Color? gap,
}) {
  if (inward && gap != null) {
    _strokeAround(
      canvas,
      rect,
      shape,
      out: -thickness - offset / 2,
      width: offset,
      color: gap,
      textDirection: textDirection,
    );
  }
  _strokeAround(
    canvas,
    rect,
    shape,
    out: inward ? -thickness / 2 : offset + thickness / 2,
    width: thickness,
    color: color,
    textDirection: textDirection,
  );
}