list_tile.dart 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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(
  6. {BuildContext? context,
  7. Iterable<Widget>? tiles,
  8. Color? color,
  9. includeLast = false}) sync* {
  10. assert(tiles != null);
  11. assert(color != null || context != null);
  12. final Iterator<Widget> iterator = tiles!.iterator;
  13. final bool isNotEmpty = iterator.moveNext();
  14. final Decoration decoration = BoxDecoration(
  15. border: Border(
  16. bottom: Divider.createBorderSide(context, color: color),
  17. ),
  18. );
  19. Widget tile = iterator.current;
  20. while (iterator.moveNext()) {
  21. yield DecoratedBox(
  22. position: DecorationPosition.foreground,
  23. decoration: decoration,
  24. child: tile,
  25. );
  26. tile = iterator.current;
  27. }
  28. if (isNotEmpty)
  29. yield includeLast
  30. ? DecoratedBox(
  31. position: DecorationPosition.foreground,
  32. decoration: decoration,
  33. child: tile,
  34. )
  35. : tile;
  36. }