minimalCell function

OutlinedBorder minimalCell(
  1. OutlinedBorder frame, {
  2. required int index,
  3. required int count,
  4. double inset = 0,
  5. Axis axis = Axis.horizontal,
})

Cell index of count laid edge to edge along axis inside frame, inset px within it: the first cell keeps the frame's start (or top) corners, the last its end (or bottom) corners, each shrunk by inset so the two outlines stay concentric, and every corner that faces a neighbour is square. The frame's kind carries over (a bevel's cut, a squircle's curve); a capsule's ends stay round.

Implementation

OutlinedBorder minimalCell(
  OutlinedBorder frame, {
  required int index,
  required int count,
  double inset = 0,
  Axis axis = Axis.horizontal,
}) {
  final whole = MinimalShapes.radiusOf(frame);
  final r = Radius.circular(
    whole >= MinimalShapes.fullRadius
        ? MinimalShapes.fullRadius
        : (whole - inset).clamp(0.0, double.infinity),
  );
  final first = index == 0;
  final last = index == count - 1;
  final BorderRadiusGeometry radius = axis == Axis.horizontal
      ? BorderRadiusDirectional.horizontal(
          start: first ? r : Radius.zero,
          end: last ? r : Radius.zero,
        )
      : BorderRadius.vertical(
          top: first ? r : Radius.zero,
          bottom: last ? r : Radius.zero,
        );
  return switch (frame) {
    final BeveledRectangleBorder s => s.copyWith(borderRadius: radius),
    final ContinuousRectangleBorder s => s.copyWith(borderRadius: radius),
    final RoundedSuperellipseBorder s => s.copyWith(borderRadius: radius),
    _ => RoundedRectangleBorder(borderRadius: radius),
  };
}