Skip to content

Commit bf4f1eb

Browse files
committed
feat: add autoDisposeIndexes to LazyLoadIndexedStack for automatic disposal of children
- Renamed `forceReloadIndexes` to `autoDisposeIndexes` to better reflect its purpose. - Added comments and updated parameters to align with the new feature.
1 parent 06a8e83 commit bf4f1eb

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/lazy_load_indexed_stack.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class LazyLoadIndexedStack extends StatefulWidget {
88
/// The indexes of children that should be preloaded.
99
final List<int> preloadIndexes;
1010

11-
/// The indexes of children that should be forcibly reloaded.
12-
final List<int> forceReloadIndexes;
11+
/// The indexes of children that should be automatically disposed and rebuilt when accessed again.
12+
final List<int> autoDisposeIndexes;
1313

1414
/// Same as alignment attribute of original IndexedStack.
1515
final AlignmentGeometry alignment;
@@ -34,7 +34,7 @@ class LazyLoadIndexedStack extends StatefulWidget {
3434
super.key,
3535
Widget? unloadWidget,
3636
this.preloadIndexes = const [],
37-
this.forceReloadIndexes = const [],
37+
this.autoDisposeIndexes = const [],
3838
this.alignment = AlignmentDirectional.topStart,
3939
this.sizing = StackFit.loose,
4040
this.textDirection,
@@ -67,7 +67,7 @@ class LazyLoadIndexedStackState extends State<LazyLoadIndexedStack> {
6767
_children = _initialChildren();
6868
}
6969

70-
_children = _updateChildrenForReload();
70+
_children = _updateChildrenForAutoDispose();
7171

7272
_children[widget.index] = widget.children[widget.index];
7373
}
@@ -97,12 +97,12 @@ class LazyLoadIndexedStackState extends State<LazyLoadIndexedStack> {
9797
}).toList();
9898
}
9999

100-
List<Widget> _updateChildrenForReload() {
100+
List<Widget> _updateChildrenForAutoDispose() {
101101
return widget.children.asMap().entries.map((entry) {
102102
final index = entry.key;
103103
final childWidget = entry.value;
104104

105-
if (index != widget.index && widget.forceReloadIndexes.contains(index)) {
105+
if (index != widget.index && widget.autoDisposeIndexes.contains(index)) {
106106
return widget.unloadWidget;
107107
} else {
108108
return childWidget;

0 commit comments

Comments
 (0)