divideTiles static method Null safety

Iterable<Widget> divideTiles(
  1. {BuildContext? context,
  2. required Iterable<Widget> tiles,
  3. Color? color}
)

Add a one pixel border in between each tile. If color isn't specified the ThemeData.dividerColor of the context's Theme is used.

See also:

  • Divider, which you can use to obtain this effect manually.

Implementation

static Iterable<Widget> divideTiles({ BuildContext? context, required Iterable<Widget> tiles, Color? color }) {
  assert(tiles != null);
  assert(color != null || context != null);
  tiles = tiles.toList();

  if (tiles.isEmpty || tiles.length == 1) {
    return tiles;
  }

  Widget wrapTile(Widget tile) {
    return DecoratedBox(
      position: DecorationPosition.foreground,
      decoration: BoxDecoration(
        border: Border(
          bottom: Divider.createBorderSide(context, color: color),
        ),
      ),
      child: tile,
    );
  }

  return <Widget>[
    ...tiles.take(tiles.length - 1).map(wrapTile),
    tiles.last,
  ];
}