expanded_menu_widget.dart 2.4 KB

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