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

Installation

Add this to your package's pubspec.yaml file:

dependencies:
  lazy_scroll_view: ^1.0.0

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 loaded
  • isFinished: Boolean flag indicating if all data has been loaded
  • loadingIndicator: Custom widget to show while loading
  • controller: ScrollController for manual scroll control
  • scrollDirection: Axis of scrolling (vertical/horizontal)
  • reverse: Whether to reverse the scroll direction
  • physics: ScrollPhysics for customizing scroll behavior
  • padding: 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

LazyListView Demo

License

This project is licensed under the MIT License - see the LICENSE file for details.

Libraries

lazy_scroll_view