addSection method

void addSection(
  1. Section section, {
  2. int? index,
  3. Iterable<Item>? items,
  4. bool animate = true,
})

Inserts section at index (or at the end when null). If items is non-empty they become the section's children — this initial child population is structural and does not animate per item; the section's own appearance respects animate.

Implementation

void addSection(
  Section section, {
  int? index,
  Iterable<Item>? items,
  bool animate = true,
}) {
  _checkNotDisposed();
  final sectionKey = sectionKeyOf(section);
  _tree.runBatch(() {
    _tree.insertRoot(
      TreeNode(
        key: SectionKey<K>(sectionKey),
        data: SectionPayload<Section, Item>(section),
      ),
      index: index,
      animate: animate,
    );
    if (items != null) {
      final children = <TreeNode<SecKey<K>, SecPayload<Section, Item>>>[
        for (final i in items)
          TreeNode(
            key: ItemKey<K>(itemKeyOf(i)),
            data: ItemPayload<Section, Item>(i),
          ),
      ];
      if (children.isNotEmpty) {
        _tree.setChildren(SectionKey<K>(sectionKey), children);
      }
    }
  });
}