EQLazyLoadIndexedStack constructor

EQLazyLoadIndexedStack({
  1. Key? key,
  2. required EQLazyStackController controller,
  3. required List<Widget> children,
  4. AlignmentGeometry alignment = AlignmentDirectional.topStart,
  5. StackFit sizing = StackFit.loose,
  6. TextDirection? textDirection,
  7. Widget? child,
})

Implementation

EQLazyLoadIndexedStack(
    {super.key,
    required EQLazyStackController controller,
    required this.children,
    this.alignment = AlignmentDirectional.topStart,
    this.sizing = StackFit.loose,
    this.textDirection,
    super.child})
    : super(
        listenable: controller,
        builder: (context, _) {
          final currentIndex = controller.currentIndex;
          final loadedIndexes = controller.loadedIndexes;
          final visibleChildren =
              List<Widget>.filled(children.length, const SizedBox.shrink());

          for (final i in loadedIndexes) {
            if (i < children.length) {
              visibleChildren[i] = KeyedSubtree(
                key: ValueKey('lc$i'),
                child: TickerMode(
                  enabled: i == currentIndex,
                  child: children[i],
                ),
              );
            }
          }

          return IndexedStack(
            index: currentIndex,
            alignment: alignment,
            textDirection: textDirection,
            sizing: sizing,
            children: visibleChildren,
          );
        },
      );