Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/okaryo/lazy_load_indexed_stack
A Flutter package that extends IndexedStack to allow for lazy loading.
https://github.com/okaryo/lazy_load_indexed_stack
flutter indexedstack lazyload
Last synced: 17 days ago
JSON representation
A Flutter package that extends IndexedStack to allow for lazy loading.
- Host: GitHub
- URL: https://github.com/okaryo/lazy_load_indexed_stack
- Owner: okaryo
- License: mit
- Created: 2021-11-09T15:25:13.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-01-06T06:47:29.000Z (10 months ago)
- Last Synced: 2024-10-17T16:04:11.110Z (27 days ago)
- Topics: flutter, indexedstack, lazyload
- Language: Dart
- Homepage: https://pub.dev/packages/lazy_load_indexed_stack
- Size: 71.3 KB
- Stars: 37
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[![CI](https://github.com/okaryo/lazy_load_indexed_stack/actions/workflows/ci.yml/badge.svg)](https://github.com/okaryo/lazy_load_indexed_stack/actions/workflows/ci.yml)
[![Pub](https://img.shields.io/pub/v/lazy_load_indexed_stack)](https://pub.dev/packages/lazy_load_indexed_stack)# lazy_load_indexed_stack
A package that extends IndexedStack to allow for lazy loading.
## 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.## Usage
You can use `LazyLoadIndexedStack` in the same way as `IndexedStack`.```dart
class MainPage extends StatefulWidget {
@override
State createState() => _MainPageState();
}class _MainPageState extends State {
int _index = 0;@override
Widget build(final BuildContext context) {
return MaterialApp(
home: Scaffold(
body: LazyLoadIndexedStack(
index: _index,
preloadIndexes: const [3],
children: [
Page1(),
Page2(),
Page3(),
Page4(), // index3 is preloaded
],
),
bottomNavigationBar: BottomNavigationBar(
onTap: (index) {
setState(() => _index = index);
},
currentIndex: _index,
items: [
BottomNavigationBarItem1(),
BottomNavigationBarItem2(),
BottomNavigationBarItem3(),
BottomNavigationBarItem4(),
],
),
),
);
}
}
```See more details in [Example](https://pub.dev/packages/lazy_load_indexed_stack/example) or [API reference](https://pub.dev/documentation/lazy_load_indexed_stack/latest/lazy_load_indexed_stack/LazyLoadIndexedStack-class.html)!