import 'package:flutter/material.dart';
class XListDivider extends StatelessWidget {
final List<Widget> tiles;
final double indent;
XListDivider({@required this.tiles, this.indent = 16.0});
@override
Widget build(BuildContext context) {
List<Widget> children = [];
for (var i = 0; i < tiles.length; i++) {
children.add(tiles[i]);
if (i != tiles.length - 1) {
children.add(Divider(
height: 0.1,
indent: indent,
));
}
}
return Column(
children: children,
);
}
static List<Widget> divideTiles(
{@required List<Widget> tiles, indent = 16.0}) {
List<Widget> result = [];
for (var i = 0; i < tiles.length; i++) {
result.add(tiles[i]);
if (i != tiles.length - 1) {
result.add(Divider(
height: 0.1,
indent: indent,
));
}
}
return result;
}
}
// 使用方式
XListDivider(
tiles: <Widget>[
Container(
child: Text('111')
),
Container(
child: Text('2222')
),
],
);