搜尋套件、儲存庫與 APP 分類

套件詳情v1.2.1

lazy_load_indexed_stack

一個擴展 IndexedStack 以支援延遲加載的套件。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1.3萬
喜歡數
101
Pub 分數
160

安裝套件

flutter pub add lazy_load_indexed_stack

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個擴展 IndexedStack 的 Flutter 套件,可實現其子項的延遲加載。它確保僅建構和呈現目前可見的 widget,從而提升具有多個頁面或複雜 widget 的應用效能。適用於包含複雜內容的標籤介面或導航情境。該套件透過推遲 widget 建立直到需要時才進行,有效管理記憶體,減少初始載入時間與資源使用。

適用情境

  • 內容豐富的標籤式介面
  • 多頁面佈局中的效能優化
  • 減少應用初始載入時間
  • 動態內容切換
  • 記憶體效率導航
  • 複雜組件的延遲渲染

主要特色

  • 擴展 IndexedStack
  • 子項的懶加載
  • 按需建立組件
  • 效能提升
  • 記憶體效率
  • 簡單整合

適合對象

  • 開發者優化應用效能
  • 具有多個標籤頁或螢幕的應用程式
  • 需要高效渲染的複雜UI
  • 使用 IndexedStack 的項目
  • 專注於資源管理的團隊

使用建議

  • 限制為 IndexedStack 內的子部件
  • 可能需要小心的狀態管理
  • 不適用於即時渲染需求
  • 最佳搭配可預測的導航模式使用
  • 需要理解組件生命週期

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

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!

所屬分類

原始碼儲存庫

使用此套件的專案