Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch instead of lazyload on scrolling to the bottom #91

Open
Asored-D opened this issue Sep 15, 2020 · 1 comment
Open

Batch instead of lazyload on scrolling to the bottom #91

Asored-D opened this issue Sep 15, 2020 · 1 comment

Comments

@Asored-D
Copy link

I created json file which includes all paths for the images. With this file I want to work as future source in flutter_pagewise.

The function which returns the list from json for pagewise

Future<List> getDemoImagesJson(int offset, int limit) async {
  String demoImages = await DefaultAssetBundle.of(context)
      .loadString("assets/demo/demo.json");

  final jsonResult = json.decode(demoImages);
  List images = [];
  for (var i in jsonResult) {
    images.add({"id": 1, "title": "sample", "thumbnailUrl": i});
  }

  final list = List.from(images).toList();
  var listWithOffset = list.skip(offset).toList();
  final finalList = listWithOffset.getRange(0, limit).toList();
  return ImageModel.fromJsonList(finalList);
}

The ImageModel class (copied from official documentation)

class ImageModel {
  String title;
  String id;
  String thumbnailUrl;

  ImageModel.fromJson(obj) {
    this.title = obj['title'];
    this.id = obj['id'].toString();
    this.thumbnailUrl = obj['thumbnailUrl'];
  }

  static List<ImageModel> fromJsonList(jsonList) {
    return jsonList.map<ImageModel>((obj) => ImageModel.fromJson(obj)).toList();
  }
}

The PageWise Widget

PagewiseGridView.count(
  shrinkWrap: true,
  physics: ClampingScrollPhysics(),
  pageSize: 10,
  crossAxisCount: 3,
  mainAxisSpacing: 8.0,
  crossAxisSpacing: 8.0,
  padding: EdgeInsets.all(15.0),
  itemBuilder: (context, entry, index) {
    return Container(
        child: Image.asset(entry.thumbnailUrl,
            fit: BoxFit.cover));
  },
  pageFuture: (pageIndex) {
    return getDemoImagesJson(pageIndex * 10, 10);
  })

What I expect: I expect that the Widget loads only 10 images and after I scroll down to the end of the page it loads other 10 images...until all images did load.

What I get: The Widget loads all images at once (as batch). There is no lazyload effect after reaching the bottom of the page.

Where is the issue?

@Sewx
Copy link

Sewx commented Feb 11, 2022

I am also encountering this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants