Buscar pacotes, repositórios e categorias de apps

Detalhes do pacotev1.2.1

lazy_load_indexed_stack

Um pacote que estende IndexedStack para permitir carregamento preguiçoso.

AndroidiOSWebmacOSWindowsLinux
Downloads em 30 dias
13,4 mil
Curtidas
101
Pontos Pub
160

Instalar pacote

flutter pub add lazy_load_indexed_stack

Visão geral do pacote

Orientação gerada a partir de informações públicas. Apenas para referência.

Um pacote Flutter que estende o IndexedStack para habilitar o carregamento preguiçoso de seus filhos. Ele garante que apenas o widget atualmente visível seja construído e renderizado, melhorando o desempenho em aplicativos com múltiplas páginas ou widgets pesados. Ideal para interfaces com abas ou navegação onde cada aba contém conteúdo complexo. O pacote gerencia eficientemente a memória ao adiar a criação dos widgets até que sejam necessários, reduzindo o tempo de carregamento inicial e o uso de recursos.

Casos de uso

  • Interfaces com abas com conteúdo pesado
  • Otimização de desempenho em layouts multi-página
  • Reduzindo o tempo inicial de carregamento do aplicativo
  • Alternância de conteúdo dinâmico
  • Navegação eficiente em memória
  • Renderização preguiçosa de widgets complexos

Principais recursos

  • Extende IndexedStack
  • Carregamento preguiçoso de filhos
  • Criação sob demanda de widget
  • Melhoria de desempenho
  • Eficiência de memória
  • Integração simples

Indicado para

  • Desenvolvedores otimizando o desempenho do aplicativo
  • Aplicativos com várias guias ou telas
  • Interfaces de usuário complexas que exigem renderização eficiente
  • Projetos usando IndexedStack
  • Equipes focadas na gestão de recursos

Considerações

  • Limitado a widgets filhos dentro do IndexedStack
  • Pode exigir gerenciamento cuidadoso do estado
  • Não adequado para necessidades de renderização imediata
  • Melhor usado com padrões de navegação previsíveis
  • Requer compreensão do ciclo de vida do widget

README original

Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.

CI Pub

lazy_load_indexed_stack

A package that extends IndexedStack to allow for lazy loading and provides enhanced control for reloading specific child widgets.

Motivation

If you use the IndexedStack with bottom navigation, all the widgets specified in the children of the IndexedStack will be built.

Moreover, if the widget requires API requests or database access, or has a complex UI, the IndexedStack build time will be significant.

Therefore, we created an extended IndexedStack that builds the required widget only when it is needed and returns the pre-built widget when it is needed again.

Features

  • Lazy Loading: The main feature of LazyLoadIndexedStack is to build children widgets only when they are needed, reducing initial load time.
  • Preloading: With the preloadIndexes parameter, you can specify indexes of children that should be built in advance, even if they are not currently visible. This is useful for preloading widgets that are likely to be needed soon.
  • Auto Disposal: The autoDisposeIndexes parameter allows specific children to be automatically disposed of when they are no longer visible. When these children are accessed again, they will be rebuilt from scratch. This is useful for cases where widgets hold significant state or require resetting when revisited.

Usage

You can use LazyLoadIndexedStack in the same way as IndexedStack, with additional options for preloading and auto dispose. If an index is included in both preloadIndexes and autoDisposeIndexes, it will be preloaded initially but disposed when it becomes invisible and rebuilt when accessed again.

Basic Example
class MainPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  int _index = 0;

  @override
  Widget build(final BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: LazyLoadIndexedStack(
          index: _index,
          preloadIndexes: [1, 2],
          autoDisposeIndexes: [2, 3],
          children: [
            Page1(), // Load by initial index
            Page2(), // Preloaded initially
            Page3(), // Preloaded initially but disposed when other index is selected
            Page4(), // Not preloaded and disposed when other index is selected
          ],
        ),
        bottomNavigationBar: BottomNavigationBar(
          onTap: (index) {
            setState(() => _index = index);
          },
          currentIndex: _index,
          items: [
            BottomNavigationBarItem1(),
            BottomNavigationBarItem2(),
            BottomNavigationBarItem3(),
            BottomNavigationBarItem4(),
          ],
        ),
      ),
    );
  }
}

See more details in Example or API reference!

Categorias

Repositório-fonte

Projetos que usam este pacote