发布于 4年前

flutter 列表添加下划线

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')
        ),
    ],
);
©2020 edoou.com   京ICP备16001874号-3