A wrapper for a Flutter ScrollView which enables lazy loading

Overview

Lazy load scrollview

A wrapper for a ScrollView that will enable lazy loading

Usage

Add lazy_load_scrollview dependency to your pubspec.yaml:

dependencies:
  lazy_load_scrollview: 1.3.0

In your Dart code, import package:lazy_load_scrollview/lazy_load_scrollview.dart Then you can wrap your ListView, GridView, RefreshIndicator etc with the LazyLoadScrollView. Make sure you add an endOfPageListener which will receive the call when the bottom of the list has been reached.

import 'package:lazy_load_scrollview/lazy_load_scrollview.dart';


@override
Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: LazyLoadScrollView(
        onEndOfPage: () => loadMore(),
        child: ListView.builder(
          itemCount: data.length,
          itemBuilder: (context, position) {
            return Text("Position $position");
          },
        ),
      ),
    );
}

Class definition

LazyLoadScrollView(
  endOfPageListener: () => loadMore(), // The callback when reaching the end of the list
  scrollOffset: 100 // Pixels from the bottom that should trigger a callback 
  child: Widget, // A subclass of `ScrollView`
);
Comments
  • CustomScrollView implementation

    CustomScrollView implementation

    Does it work with CustomScrollView and related SliverList? I wrapped the CustomScrollView with the LazyLoadScrollView, but I can only obtain the first pagination. After that the onEndOfPage method does not get called anymore.

    opened by Slaine066 6
  • onEndOfPage called more than once

    onEndOfPage called more than once

    Hi, I've used this plugin inside of a StreamBuilder without issues however when I try to use it inside a custom StatefulWidget the onEndOfPage callback gets called more than once.

    Here the example app,

    import 'dart:convert';
    
    import 'package:flutter/material.dart';
    import 'package:http/http.dart';
    import 'package:lazy_load_scrollview/lazy_load_scrollview.dart';
    
    main() {
      runApp(MaterialApp(
        home: Scaffold(
          appBar: AppBar(
            title: Text('LazyLoading'),
          ),
          body: Home(),
        ),
      ));
    }
    
    class Home extends StatefulWidget {
      final int pageSize;
    
      Home({this.pageSize = 10});
    
      @override
      State<StatefulWidget> createState() => HomeState();
    }
    
    class HomeState extends State<Home> {
      List<Map> documents;
      bool loading;
      int currentPage;
      Client client;
    
      @override
      void initState() {
        super.initState();
        documents = [];
        loading = false;
        currentPage = 0;
        client = Client();
        () async {
          await _loadMore();
        }();
      }
    
    // 'http://monster6.disco.unimib.it/API/documents/search/?s=informatica&paging=${widget.pageSize}&offset=${currentPage > 0 ? currentPage * widget.pageSize : ''}'
      Future<void> _loadMore() async {
        print('loading more!');
        setState(() {
          loading = true;
        });
        final response = await client.get(
          Uri.http(
            'monster6.disco.unimib.it',
            '/API/documents/search',
            {
              's': 'informatica',
              'paging': '${widget.pageSize}',
              'offset':
                  currentPage > 0 ? '${currentPage * widget.pageSize + 1}' : null
            },
          ),
        );
        print(jsonDecode(response.body));
        final results = List<Map>.from(
            jsonDecode(response.body)['documentsAleph']['documents']);
        if (mounted) {
          setState(() {
            loading = false;
            documents.addAll(results);
            currentPage++;
          });
        }
      }
    
      @override
      Widget build(BuildContext context) {
        return Stack(
          children: <Widget>[
            Positioned.fill(
              child: LazyLoadScrollView(
                child: ListView.builder(
                  itemCount: documents.length,
                  itemBuilder: (context, index) {
                    return AspectRatio(
                      aspectRatio: 2,
                      child: Card(
                        child: Text(documents[index]['title'] ?? 'null'),
                      ),
                    );
                  },
                ),
                onEndOfPage: () {
                  _loadMore();
                },
                scrollOffset: 600,
              ),
            ),
            Positioned(
              top: 0,
              left: 0,
              right: 0,
              child: loading ? LinearProgressIndicator() : Container(),
            ),
          ],
        );
      }
    }
    
    opened by GregorySech 6
  • RefreshIndicator stops working when

    RefreshIndicator stops working when

    RfreshIndicator stops working when LazyLoadScrollView is added to the tree. This makes it really inconvenient as Most ListViews fetching data have a RefreshIndicator. It would be nice if RehreshIndicator still works with LazyLoad

    opened by Sameerkash 3
  • can't add a RefreshIndicator as a parent to the listview.builder and child to LazyLoadScrollView

    can't add a RefreshIndicator as a parent to the listview.builder and child to LazyLoadScrollView

    Hey there, recently I've been working on this package.. and I tried to put my ListView.builder inside the LazyLoadScrollView, OK that's worked fine. BUT... when I tried to wrap my ListView.builder by RefreshIndicator it gives me an error and that because the child accepts only ScrollView Widget...

    .
    .
    .
    .
    // rest of the code
    
                return LazyLoadScrollView(
                  onEndOfPage: () {
                    BlocProvider.of<FetchProductsBloc>(context).add(
                      FetchProducts(count: 20),
                    );
                  },
                  child: ListView.builder(
                    itemCount: state.count,
                    itemBuilder: (context, index) {
                      return ListTile(
                        title: Text('Loaded Data $index'),
                      );
                    },
                  ),
                );
    .
    .
    .
    .
    
    

    HOW can I wrap the (listview with lazy load scrollview) with a refresh indicator too?? Any solutions??

    opened by devmuaz 3
  • onEndOfPage( ) triggers for every scrollview in the widget tree

    onEndOfPage( ) triggers for every scrollview in the widget tree

    this is how my widget tree looks

    LazyLoadScrollView(
    onEndOfPage: ( ) { }
    child: SingleChildScrollView(      //vertical scroll view
    
    child : Column( 
    . . . . . 
    CarouselSlider (                         //horizontalScrollview
    . . . . . 
    ),
    ),);
    

    onEndOfPage gets triggered for horizontal scroll view too which is not ideal for pagination, which is what I'm using it for, I tried using different scorllControllers, but nothing seems to be working, Is there any way I can make this work, or can this be implemented in the package?

    Thanks.

    opened by Sameerkash 2
  • when reaches the bottom, does infinite loop calls.

    when reaches the bottom, does infinite loop calls.

    When scrolling and reaches the bottom, does infinite loop calls. Should verify if position.pixels == position.maxScrollExtent and if true do another call.

    opened by jahiron 1
  • Add support for RefreshIndicator

    Add support for RefreshIndicator

    This change makes the use of RefreshIndicator with LazyLoadScrollView possible.

    E.g.

    LazyLoadScrollView(
          onEndOfPage: () {
            //...
          },
          child: RefreshIndicator(
            onRefresh: () async {
              print('On refresh');
              return;
            },
            child: ListView.builder(
                //...
                ),
          ),
        );
    
    opened by mbartn 1
  • Do not scroll on the web !?

    Do not scroll on the web !?

    In Flutter Android everything is fine. But I tested it on a small Flutter Web project and the package didn't work. Do you have any special configuration?

    opened by catalunha 0
  • Updated example and v2 of lazy_load_scrollview

    Updated example and v2 of lazy_load_scrollview

    Hello ! I didn't know of the existence of this package and ended up creating listview notifier similar to this but slightly different. In any case, I'd like to offer it up as a PR. To improve I took both my ideas and your ideas and kind of squashed them together as well as implemented a few things from the issues here.

    Here are a few things the new:

    • lazyloadscrollview takes an optional ScrollController now that will work in place of bubbling notifier events (this is useful to avoid predicates)
    • Added notificationPredicate #15
    • Added an example on how to add animation when reached the end #2
    • lazyloadscrollview can now work in both directions of a listview
    • Added debounce timer that will prevent the callback from firiing a bunch of times

    Breaking change:

    • the lazyloadscrollview takes a builder instead of a child. This builder passes through isLoadingBefore and isLoadingAfter that tell the user when the respective async op is running.
    • Renamed onEndOfPage to to onLoadAfter

    I'd love to get your opinion on this big change. Leaving it as a draft for now

    opened by Nolence 2
  • Check for notification level depth

    Check for notification level depth

    Hi please can you add a level depth check into _onNotifcation method. If you have a list with animated widget that scroll vertically this method is calle endlessly and also _loadMore.

    The changes to do are these: At row 61 of lazy_load_scrollview.dart

    if (widget.scrollDirection == notification.metrics.axis) {

    should turn into

    if (widget.scrollDirection == notification.metrics.axis && defaultScrollNotificationPredicate(notification)) {

    This check if the scroll came from the real list scroll and not from a scrollable item into it.

    Regards Massimo

    opened by carmas123 1
Owner
Quirijn Groot Bluemink
~Lead Mobile Engineer - Flutter - Android ~GDG organiser
Quirijn Groot Bluemink
CRUD Table Flutter consists of a Lazy loading function, resizable columns, and integrated CRUD Form.

CRUD Table Flutter CRUD Table Flutter is a package for crating CURD-UI for your entity/object/class easily. It consists of a Lazy loading function, re

null 10 Dec 31, 2022
This Country Selector UI Library written by Dart and Fluter and supports three locales with country's name, achieves lazy loading, and country card animation on listview

Country Selector Widget This Country Selector Widget UI Library written by Dart and Fluter and supports three locales with country's name, achieves la

Klaus 6 Nov 15, 2022
Flutter package. A wrapper for scrollable widgets that enables smooth scrolling with a mouse on all platforms.

Dynamic Mouse Scroll A wrapper for scrollable widgets that enables smooth scrolling with a mouse on all platforms. First gif: Scrolling slowly. Second

null 3 Dec 15, 2022
FlutterBoost is a Flutter plugin which enables hybrid integration of Flutter for your existing native apps with minimum efforts

中文文档 中文介绍 Release Note v3.0-preview.17 PS: Before updating the beta version, please read the CHANGELOG to see if there are any BREAKING CHANGE Flutter

Alibaba 6.3k Dec 30, 2022
Call Kit is a prebuilt feature-rich call component, which enables you to build one-on-one and group voice/video calls into your app with only a few lines of code.

Call Kit (ZegoUIKitPrebuiltCall) Call Kit is a prebuilt feature-rich call component, which enables you to build one-on-one and group voice/video calls

ZEGOCLOUD 9 Dec 26, 2022
Portfolio template for lazy people like you and me 🚀

Looking for collaborators and maintainers. Feel free to connect! Developer Portfolio ⚡️ It's minimal, beautiful and responsive! Don't have or don't kn

SHOURYA SHIKHAR 32 Dec 30, 2022
best flutter / dart practices + Custom Painter + Sliver App Bar + Custom Scrollview

Weekly Budget Flutter App A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get yo

Mohamed Awnallah 4 Oct 21, 2021
Flutter Scrollable Widgets like ListView,GridView or powerful CustomScrollView can't nest inner scrollview

Introduction Flutter Scrollable Widgets like ListView,GridView or powerful CustomScrollView can't nest inner scrollview. If Nested, inner scrollview w

jaysonss 5 Aug 28, 2022
A Flutter widget for Scrollview, pop when overscroll

overscroll_pop A Flutter widget for Scrollview, pop when overscroll like Instagram, Pinterest, ... Getting Started Include the package to your project

null 22 Dec 21, 2022
A _Flutter_ package that provides a diagonal scrollview.

Diagonal ScrollView for Flutter THE PACKAGE IS DISCONTINUED! Use InteractiveViewer instead. A Flutter package that allows to scroll in both, horizonta

Ranfi Castillo de Aza 35 Dec 12, 2021
This example uses a ScrollView, JSON Rest API, Navigation, Alert Pop Up, Progress Indicator, Globals, Images in a shared asset folder, and 100% Shared Code

This example uses a ScrollView, JSON Rest API, Navigation, Alert Pop Up, Progress Indicator, Globals, Images in a shared asset folder, and 100% Shared Code. Now with the ability to login with FaceID, TouchID, and Fingerprint Reader on Android.

Rody Davis 672 Jan 6, 2023
Open source Flutter-based GUI application that enables you to interact with Amphitheatre

Amphitheatre Desktop Amphitheatre Desktop is an open source Flutter-based application that enables you to interact with Amphitheatre using a GUI inste

Amphitheatre 17 Dec 16, 2022
Intel Corporation 238 Dec 24, 2022
Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.

Flet Flet is a framework that enables you to easily build realtime web, mobile and desktop apps in your favorite language and securely share them with

Flet 3.6k Jan 9, 2023
A state management library that enables concise, fluid, readable and testable business logic code.

Creator is a state management library that enables concise, fluid, readable, and testable business logic code. Read and update state with compile time

Xianzhe Liang 181 Dec 24, 2022
Rajagiri connect is a networking platform that enables the students of Rajagiri to form a social network among themselves, enabling them to connect with their seniors, juniors and faculty for sharing of information and resources.

Rajagiri Connect Rajagiri connect is a networking platform that enables the students of Rajagiri to form a social network among themselves, enabling t

Muhammad Amaan 2 Nov 27, 2022
Flet enables developers to easily build realtime web, mobile and desktop apps in Ruby. No frontend experience required

Flet If bundler is not being used to manage dependencies, install the gem by executing: $ gem install flet Flet Flet is a framework that enables you

AdamMusa 29 Jan 3, 2023
A loading more list which supports ListView,GridView,WaterfallFlow and Slivers.

loading_more_list A loading more list which supports ListView,GridView,WaterfallFlow and Slivers. Language: English | 中文简体 Web demo for LoadingMoreLis

FlutterCandies 292 Dec 19, 2022
Fancy list loading effect or The Shimmer Effect in Flutter

Shimmer Effect in Shimmer Effect is really cool placeholder effect that you can show when you are loading data in the form of a list. To do it in flut

Ronak Punase 31 Oct 18, 2022