letsar/flutter_staggered_grid_view

Allow itemBuilder to return nullable Widget and handle it like ListView.builder

MominRaza opened this issue · 0 comments

This message is from Flutter's deafult ListView.builder

It is legal for itemBuilder to return null. If it does, the scroll view will stop calling itemBuilder, even if it has yet to reach itemCount.

Do same in MasonryGridView.extent and in other widgets if possible.

Use case:
It comes handy in infinite scrolling where we don't know page length.

ListView.builder(
  itemBuilder: (context, index) {
    final page = index ~/ 10 + 1;

    return ref.watch(postsProvider(page)).when(
          data: (posts) {
            if (posts.length <= index) return null;  //here i'm returning null, this is not possible with MasonryGridView.extent
            return PostItem(post: posts[index]);
          },
          error: (_, __) => const SizedBox(),
          loading: () => const PostItemSkeleton(),
        );
  },
),