GithubHelp home page GithubHelp logo

quirijngb / lazy-load-scrollview Goto Github PK

View Code? Open in Web Editor NEW
108.0 108.0 26.0 136 KB

A wrapper for a Flutter ScrollView which enables lazy loading

License: BSD 2-Clause "Simplified" License

Kotlin 1.54% Swift 5.03% Objective-C 0.47% Dart 92.95%

lazy-load-scrollview's People

Contributors

ericloureiro avatar goolpe avatar mbartn avatar quirijnatpropertyme avatar quirijngb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

lazy-load-scrollview's Issues

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(),
        ),
      ],
    );
  }
}

Cannot use with RefreshIndicator

When this widget is kept under RefreshIndicator widget, the pull to refresh doesn't work. Maybe the RefreshIndicator widget is not receiving the scroll notification.
It worked when I inverted the widgets i.e kept RefreshIndicator under LazyLoadScrollView widget.

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.

onTopOfPage

Will this work if I want to append previous data when scrolling towards the top?

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.

StatelessWidget

As you know, StatefulWidget takes a lot of resources.
Is it possible to implement this library with StatelessWidget?

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

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

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?

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??

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.