Lazy Scroll View
A Flutter package that provides lazy-loading functionality for ListView and GridView widgets with built-in scroll detection and loading states.
Features
- 🔄 Automatic load-more detection
- 📜 Supports both ListView and GridView
- 🎯 Custom loading indicators
Usage
LazyListView
LazyListView.builder(
itemCount: items.length,
itemBuilder: (context, index) => ListTile(
title: Text('Item ${items[index]}'),
),
onLoad: () async {
// Load more data here
await fetchMoreItems();
},
isFinished: items.length >= totalItems,
);
LazyGridView
LazyGridView.builder(
itemCount: items.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
mainAxisSpacing: 8,
crossAxisSpacing: 8,
),
itemBuilder: (context, index) => Card(
child: Center(child: Text('Item ${items[index]}')),
),
onLoad: () async {
// Load more data here
await fetchMoreItems();
},
isFinished: items.length >= totalItems,
);
Properties
Common Properties
onLoad: Callback function triggered when more data should be loadedisFinished: Boolean flag indicating if all data has been loadedloadingIndicator: Custom widget to show while loadingcontroller: ScrollController for manual scroll controlscrollDirection: Axis of scrolling (vertical/horizontal)reverse: Whether to reverse the scroll directionphysics: ScrollPhysics for customizing scroll behaviorpadding: EdgeInsets for content padding
Additional Features
Separated List
LazyListView.separated(
itemCount: items.length,
itemBuilder: (context, index) => ListTile(
title: Text('Item ${items[index]}'),
),
separatorBuilder: (context, index) => Divider(),
onLoad: () async {
await fetchMoreItems();
},
);
Grid with Fixed Count
LazyGridView.count(
crossAxisCount: 3,
children: items.map((item) => ItemWidget(item)).toList(),
onLoad: () async {
await fetchMoreItems();
},
);
Screenshots
License
This project is licensed under the MIT License - see the LICENSE file for details.