expanded_menu_widget.dart 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. double textScaleFactor = MediaQuery.of(context).textScaleFactor;
  13. textScaleFactor < 1.0 ? textScaleFactor = 1.0 : null;
  14. //20 is height of font and 28 is total whitespace (top+bottom)
  15. final double itemHeight = (20.0 * textScaleFactor) + 28.0;
  16. const double whiteSpaceBetweenSections = 16.0;
  17. const double dividerHeightBetweenItems = 1.0;
  18. double numberOfDividers = 0.0;
  19. double combinedHeightOfItems = 0.0;
  20. for (List<BlurMenuItemWidget> group in items) {
  21. //no divider if there is only one item in the section/group
  22. if (group.length != 1) {
  23. numberOfDividers += (group.length - 1);
  24. }
  25. combinedHeightOfItems += group.length * itemHeight;
  26. }
  27. return Padding(
  28. padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
  29. child: SizedBox(
  30. height: combinedHeightOfItems +
  31. (dividerHeightBetweenItems * numberOfDividers) +
  32. (whiteSpaceBetweenSections * (items.length - 1.0)),
  33. child: ListView.separated(
  34. padding: const EdgeInsets.all(0),
  35. physics: const NeverScrollableScrollPhysics(),
  36. itemBuilder: (context, sectionIndex) {
  37. return ClipRRect(
  38. borderRadius: const BorderRadius.all(Radius.circular(8)),
  39. child: SizedBox(
  40. height: itemHeight * items[sectionIndex].length +
  41. (dividerHeightBetweenItems *
  42. (items[sectionIndex].length - 1)),
  43. child: ListView.separated(
  44. padding: const EdgeInsets.all(0),
  45. physics: const NeverScrollableScrollPhysics(),
  46. itemBuilder: (context, itemIndex) {
  47. return items[sectionIndex][itemIndex];
  48. },
  49. separatorBuilder: (context, index) {
  50. return const DividerWidget(
  51. dividerType: DividerType.bottomBar,
  52. );
  53. },
  54. itemCount: items[sectionIndex].length,
  55. ),
  56. ),
  57. );
  58. },
  59. separatorBuilder: (context, index) {
  60. return const SizedBox(height: whiteSpaceBetweenSections);
  61. },
  62. itemCount: items.length,
  63. ),
  64. ),
  65. );
  66. }
  67. }