Prechádzať zdrojové kódy

Used a nested List of BlurMenuItemWidget as items instead of passing groupingOrder to ExpandedMenuWidget

ashilkn 2 rokov pred
rodič
commit
171ecb8805

+ 16 - 19
lib/ui/components/bottom_action_bar/expanded_menu_widget.dart

@@ -3,15 +3,10 @@ import 'package:photos/ui/components/blur_menu_item_widget.dart';
 import 'package:photos/ui/components/divider_widget.dart';
 
 class ExpandedMenuWidget extends StatelessWidget {
-  final List<BlurMenuItemWidget> items;
-  final List<int> groupingOrder;
+  final List<List<BlurMenuItemWidget>> items;
+  // final List<int> groupingOrder;
   const ExpandedMenuWidget({
     required this.items,
-
-    /// To specify the grouping of items. Eg: [2,2] for 2 sections with 2 items
-    /// each, [4,1,2] for 3 sections with 4, 1 and 2 items respectively.
-    /// Make sure sum of ints in this.groupingOrder is equal to length of this.items
-    required this.groupingOrder,
     super.key,
   });
 
@@ -20,21 +15,23 @@ class ExpandedMenuWidget extends StatelessWidget {
     const double itemHeight = 48;
     const double whiteSpaceBetweenSections = 16;
     const double dividerHeightBetweenItems = 1;
-    int totalItemIndex = 0;
     int numberOfDividers = 0;
+    double combinedHeightOfItems = 0;
 
-    for (int group in groupingOrder) {
+    for (List<BlurMenuItemWidget> group in items) {
       //no divider if there is only one item in the section/group
-      if (group != 1) {
-        numberOfDividers += (group - 1);
+      if (group.length != 1) {
+        numberOfDividers += (group.length - 1);
       }
+      combinedHeightOfItems += group.length * itemHeight;
     }
+
     return Padding(
       padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
       child: SizedBox(
-        height: (itemHeight * items.length) +
+        height: combinedHeightOfItems +
             (dividerHeightBetweenItems * numberOfDividers) +
-            (whiteSpaceBetweenSections * (groupingOrder.length - 1)),
+            (whiteSpaceBetweenSections * (items.length - 1)),
         child: ListView.separated(
           padding: const EdgeInsets.all(0),
           physics: const NeverScrollableScrollPhysics(),
@@ -42,21 +39,21 @@ class ExpandedMenuWidget extends StatelessWidget {
             return ClipRRect(
               borderRadius: const BorderRadius.all(Radius.circular(8)),
               child: SizedBox(
-                height: itemHeight * groupingOrder[sectionIndex] +
+                height: itemHeight * items[sectionIndex].length +
                     (dividerHeightBetweenItems *
-                        (groupingOrder[sectionIndex] - 1)),
+                        (items[sectionIndex].length - 1)),
                 child: ListView.separated(
                   padding: const EdgeInsets.all(0),
                   physics: const NeverScrollableScrollPhysics(),
-                  itemBuilder: (context, _) {
-                    return items[totalItemIndex++];
+                  itemBuilder: (context, itemIndex) {
+                    return items[sectionIndex][itemIndex];
                   },
                   separatorBuilder: (context, index) {
                     return const DividerWidget(
                       dividerType: DividerType.bottomBar,
                     );
                   },
-                  itemCount: groupingOrder[sectionIndex],
+                  itemCount: items[sectionIndex].length,
                 ),
               ),
             );
@@ -64,7 +61,7 @@ class ExpandedMenuWidget extends StatelessWidget {
           separatorBuilder: (context, index) {
             return const SizedBox(height: whiteSpaceBetweenSections);
           },
-          itemCount: groupingOrder.length,
+          itemCount: items.length,
         ),
       ),
     );

+ 7 - 8
lib/ui/viewer/gallery/collection_page.dart

@@ -128,14 +128,13 @@ class _CollectionPageState extends State<CollectionPage> {
                   selectedFiles: _selectedFiles,
                   expandedMenu: ExpandedMenuWidget(
                     items: [
-                      BlurMenuItemWidget(
-                        leadingIcon: Icons.add_outlined,
-                        labelText: "One",
-                        menuItemColor: colorScheme.fillFaint,
-                      ),
-                    ],
-                    groupingOrder: const [
-                      1,
+                      [
+                        BlurMenuItemWidget(
+                          leadingIcon: Icons.add_outlined,
+                          labelText: "One",
+                          menuItemColor: colorScheme.fillFaint,
+                        ),
+                      ],
                     ],
                   ),
                   text: _selectedFiles.files.length.toString() + ' selected',