efficient_indexed_stack 1.0.2 copy "efficient_indexed_stack: ^1.0.2" to clipboard
efficient_indexed_stack: ^1.0.2 copied to clipboard

It's an IndexedStack that only builds the widgets that are in the range of the current index and the keepAliveDistance

example/lib/main.dart

import 'package:example/my_cool_widget.dart';
import 'package:flutter/material.dart';
import 'package:efficient_indexed_stack/efficient_indexed_stack.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  int activeIndex = 0;
  final itemCount = 30;

  int get maxIndex => itemCount - 1;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          title: Text('Active index : $activeIndex'),
          actions: [
            IconButton(
              icon: const Icon(Icons.arrow_left_rounded),
              onPressed: () => setState(() {
                activeIndex = (activeIndex - 1).clamp(0, maxIndex);
              }),
            ),
            const SizedBox(width: 24),
            IconButton(
              icon: const Icon(Icons.arrow_right_rounded),
              onPressed: () => setState(() {
                activeIndex = (activeIndex + 1).clamp(0, maxIndex);
              }),
            ),
          ],
        ),
        body: EfficientIndexedStack(
          index: activeIndex,
          itemCount: itemCount,
          keepAliveDistance: 3,
          itemBuilder: (_, index) => MyCoolWidget(
            index,
            key: GlobalKey(),
          ),
        ),
      ),
    );
  }
}
7
likes
150
points
35
downloads

Publisher

unverified uploader

Weekly Downloads

It's an IndexedStack that only builds the widgets that are in the range of the current index and the keepAliveDistance

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on efficient_indexed_stack