list_tile.dart 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright 2014 The Flutter Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. import 'package:flutter/material.dart';
  5. Iterable<Widget> divideTiles({BuildContext context, @required Iterable<Widget> tiles, Color color, includeLast = false}) sync* {
  6. assert(tiles != null);
  7. assert(color != null || context != null);
  8. final Iterator<Widget> iterator = tiles.iterator;
  9. final bool isNotEmpty = iterator.moveNext();
  10. final Decoration decoration = BoxDecoration(
  11. border: Border(
  12. bottom: Divider.createBorderSide(context, color: color),
  13. ),
  14. );
  15. Widget tile = iterator.current;
  16. while (iterator.moveNext()) {
  17. yield DecoratedBox(
  18. position: DecorationPosition.foreground,
  19. decoration: decoration,
  20. child: tile,
  21. );
  22. tile = iterator.current;
  23. }
  24. if (isNotEmpty) yield includeLast ? DecoratedBox(
  25. position: DecorationPosition.foreground,
  26. decoration: decoration,
  27. child: tile,
  28. ) : tile;
  29. }