separators_util.dart 586 B

1234567891011121314
  1. import 'package:flutter/material.dart';
  2. //This method returns a newly declared list with separators. It will not
  3. //modify the original list
  4. List<Widget> addSeparators(List<Widget> listOfWidgets, Widget separator) {
  5. listOfWidgets.removeWhere((element) => (element is SizedBox));
  6. final int initialLength = listOfWidgets.length;
  7. final listOfWidgetsWithSeparators = <Widget>[];
  8. listOfWidgetsWithSeparators.addAll(listOfWidgets);
  9. for (var i = 1; i < initialLength; i++) {
  10. listOfWidgetsWithSeparators.insert((2 * i) - 1, separator);
  11. }
  12. return listOfWidgetsWithSeparators;
  13. }