You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+9-9
Original file line number
Diff line number
Diff line change
@@ -7,9 +7,9 @@ A package that extends IndexedStack to allow for lazy loading and provides enhan
7
7
8
8
## Motivation
9
9
10
-
If you use the IndexedStack with bottom navigation, all the widgets specified in the children of the IndexedStack will be built.
10
+
If you use the IndexedStack with bottom navigation, all the widgets specified in the children of the IndexedStack will be built.
11
11
12
-
Moreover, if the widget requires API requests or database access, or has a complex UI, the IndexedStack build time will be significant.
12
+
Moreover, if the widget requires API requests or database access, or has a complex UI, the IndexedStack build time will be significant.
13
13
14
14
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.
15
15
@@ -19,7 +19,7 @@ Therefore, we created an extended IndexedStack that builds the required widget o
19
19
***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.
20
20
21
21
## Usage
22
-
You can use `LazyLoadIndexedStack` in the same way as `IndexedStack`, with additional options for preloading and auto dispose.
22
+
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.
23
23
24
24
### Basic Example
25
25
```dart
@@ -37,13 +37,13 @@ class _MainPageState extends State<MainPage> {
37
37
home: Scaffold(
38
38
body: LazyLoadIndexedStack(
39
39
index: _index,
40
-
preloadIndexes: const [3],
41
-
autoDisposeIndexes: const [1, 2],
40
+
preloadIndexes: [1, 2],
41
+
autoDisposeIndexes: [2, 3],
42
42
children: [
43
-
Page1(),
44
-
Page2(), // index 1 will be auto dispose
45
-
Page3(), // index 2 will also auto dispose
46
-
Page4(), // index 3 is preloaded
43
+
Page1(), // Load by initial index
44
+
Page2(), // Preloaded initially
45
+
Page3(), // Preloaded initially but disposed when other index is selected
46
+
Page4(), // Not preloaded and disposed when other index is selected
0 commit comments