Skip to content

BUG: When touched item or drag item, the list undergoes a large number of rebuild!!!! #120

@leo596566

Description

@leo596566

When clicking, long-pressing, or dragging a list item, the entire list will undergo a large number of rebuilds, resulting in sluggishness. I don't know if this is normal or a bug. I think the performance can be optimized.

Expectation: If clicking on the list does not trigger the sorting event, the list should not be rebuilt.

AnimatedReorderableListView(
                  physics: const BouncingScrollPhysics(),
                  key: GlobalKey(),
                  dragStartDelay: const Duration(milliseconds: 400),
                  onReorder: (int oldIndex, int newIndex) {
                    final Map<PlanEditItemData, int> lockedItemPositions = {
                      for (int i = 0; i < list.length; i++)
                        if (lockedItems.contains(list[i])) list[i]: i
                    };
                    setState(() {
                      final PlanEditItemData user = list.removeAt(oldIndex);
                      list.insert(newIndex, user);
                      for (var entry in lockedItemPositions.entries) {
                        list.remove(entry.key);
                        list.insert(
                            entry.value,
                            entry.key); // Insert based on original position (id in this case)
                      }
                    });
                  },
                  proxyDecorator: proxyDecorator,
                  itemBuilder: (BuildContext context, int index) {
                     # HEREWhen touched item or drag item, the list undergoes a large number of rebuild !!!! 
                      print('rebuild !!! ');
                      return _item(index, context);
                  },
                  nonDraggableItems: nonDraggableItems,
                  lockedItems: lockedItems,
                  isSameItem: (a, b) => a.id == b.id,
                );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions