expanded_menu_widget.dart 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import 'package:flutter/material.dart';
  2. import 'package:photos/ui/components/blur_menu_item_widget.dart';
  3. import 'package:photos/ui/components/divider_widget.dart';
  4. class ExpandedMenuWidget extends StatelessWidget {
  5. final List<List<BlurMenuItemWidget>> items;
  6. // final List<int> groupingOrder;
  7. const ExpandedMenuWidget({
  8. required this.items,
  9. super.key,
  10. });
  11. @override
  12. Widget build(BuildContext context) {
  13. const double itemHeight = 48;
  14. const double whiteSpaceBetweenSections = 16;
  15. const double dividerHeightBetweenItems = 1;
  16. int numberOfDividers = 0;
  17. double combinedHeightOfItems = 0;
  18. for (List<BlurMenuItemWidget> group in items) {
  19. //no divider if there is only one item in the section/group
  20. if (group.length != 1) {
  21. numberOfDividers += (group.length - 1);
  22. }
  23. combinedHeightOfItems += group.length * itemHeight;
  24. }
  25. return Padding(
  26. padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
  27. child: SizedBox(
  28. height: combinedHeightOfItems +
  29. (dividerHeightBetweenItems * numberOfDividers) +
  30. (whiteSpaceBetweenSections * (items.length - 1)),
  31. child: ListView.separated(
  32. padding: const EdgeInsets.all(0),
  33. physics: const NeverScrollableScrollPhysics(),
  34. itemBuilder: (context, sectionIndex) {
  35. return ClipRRect(
  36. borderRadius: const BorderRadius.all(Radius.circular(8)),
  37. child: SizedBox(
  38. height: itemHeight * items[sectionIndex].length +
  39. (dividerHeightBetweenItems *
  40. (items[sectionIndex].length - 1)),
  41. child: ListView.separated(
  42. padding: const EdgeInsets.all(0),
  43. physics: const NeverScrollableScrollPhysics(),
  44. itemBuilder: (context, itemIndex) {
  45. return items[sectionIndex][itemIndex];
  46. },
  47. separatorBuilder: (context, index) {
  48. return const DividerWidget(
  49. dividerType: DividerType.bottomBar,
  50. );
  51. },
  52. itemCount: items[sectionIndex].length,
  53. ),
  54. ),
  55. );
  56. },
  57. separatorBuilder: (context, index) {
  58. return const SizedBox(height: whiteSpaceBetweenSections);
  59. },
  60. itemCount: items.length,
  61. ),
  62. ),
  63. );
  64. }
  65. }