Skip to content

Releases: rithik-dev/paginated_items_builder

v1.2.4

08 Oct 19:41
Compare
Choose a tag to compare
  • Added issue tracker link
  • Updated README.md
  • Updated example app
  • Updated dependencies

v1.2.3

07 Jun 19:31
Compare
Choose a tag to compare
  • Fixed ShimmerConfig initialization error

v1.2.2

07 Jun 12:44
Compare
Choose a tag to compare
  • Fixed linter warnings
  • Updated dependencies
  • Updated config.. (Added more elements in config)

v1.2.0

14 Apr 21:58
Compare
Choose a tag to compare

[MAJOR]

  • Added a new ItemsFetchScope i.e. onErrorRefresh, which comes in play if an error occurs
  • Added error handling in the builder
  • Added showLoaderOnResetGetter param on the builder itself
  • gridDelegate is now customizable if ItemsDisplayType is grid.
  • Fixed LoaderShimmer err for null configs
  • Added logErrors param to PaginatedItemsBuilderConfig
  • Minor fixes to PaginatedItemsResponse
  • Added callbacks for emptyTextBuilder, emptyWidgetBuilder for more customization
  • Added callbacks for errorTextBuilder, errorWidgetBuilder for more customization
  • Optimizations done to the main widget
  • Added check for null response
  • Updated pagination items state handler
  • Added remaining list/grid view params that can now be passed directly
  • Update dart doc comments
  • Updated example app
  • Fixed README.md

v1.1.0

01 Apr 14:28
Compare
Choose a tag to compare
  • Added error logs
  • Optimized initializing PaginatedItemsBuilder
  • Added showLoaderOnResetBuilder in PaginationItemsStateHandler to update showLoaderOnReset param for builders with internal state management.
  • Updated example app
  • Updated README.md

v1.0.9

31 Mar 17:14
Compare
Choose a tag to compare
  • Added ignore pointer to disable onTap for loaders

v1.0.8

31 Mar 14:05
Compare
Choose a tag to compare
  • Added isLoading param to LoaderShimmer

v1.0.7

31 Mar 13:42
Compare
Choose a tag to compare
  • Added some helper getters/functions in PaginatedItemsResponse.
  • Added ItemsFetchScope i.e. defines the scope from which fetchPageData in PaginatedItemsBuilder was called.
  • Exposed LoaderShimmer as a widget to wrap around your own widgets.
  • Updated noItemsTextGetter definition
  • Updated example app
  • Updated README.md

v1.0.5

28 Mar 22:19
Compare
Choose a tag to compare

[MAJOR]

  • Added access/update to list elements by using [] syntax on PaginatedItemsResponse directly.
  • Added custom refresh icon builder parameter
  • Added mockItemKey param for getting mock item with this key, if T is not used.
  • Added disable refresh indicator param
  • Fixed scroll controller assignment
  • Fixed triggering fetchData multiple times by custom implementation. Removed VisibilityDetector as dependency.
  • Fixed a bug where fetchData was called twice if PaginationItemsStateHandler was used as parent
  • Updated example app
  • Updated README.md

v1.0.0

26 Jan 11:23
Compare
Choose a tag to compare

PaginatedItemsBuilder For Flutter

pub package
likes
popularity
pub points

Easier to display items in a list/grid view from your controllers directly or handling state internally with support for pagination.
Saves the results in state to avoid unnecessary api calls everytime screen is pushed.

Screenshots

    

Usage

To use this plugin, add paginated_items_builder as a dependency in your pubspec.yaml file.

  dependencies:
    flutter:
      sdk: flutter
    paginated_items_builder:

First and foremost, import the widget.

import 'package:paginated_items_builder/paginated_items_builder.dart';

You can now add an PaginatedItemsBuilder widget to your widget tree.

Here, let's consider a list of products.

First, in the controller, let's define a variable for handling the products response.
(typically inside the specific controller) and a public getter to access it in the UI.

PaginatedItemsResponse<Product>? _productsResponse;

PaginatedItemsResponse<Product>? get productsResponse => _productsResponse;

Now, define a function to handle the state of the list, function that handles calling the api and
getting the results.

Future<void> updateProducts({
  bool reset = false,
  bool showLoaderOnReset = false,
}) async {
  if (reset && showLoaderOnReset) {
    _productsResponse = null;
    notifyListeners();
  }

  final res = await apiFunction(
    // startKey is optional and only required when you have pagination support in api
    startKey: reset ? null : _productsResponse?.paginationKey,
  );
  if (reset || _productsResponse == null) {
    _productsResponse = res;
  } else {
    _productsResponse!.update(res);
  }
  notifyListeners();
}

The apiFunction can be defined as:

Future<PaginatedResponse<Product>?> apiFunction({
  // can be string or int (page number) or any other type.
  String? startKey,
}) async {
  // startKey necessary if pagination support
  final res = await _api.getProducts(startKey: startKey);

  return PaginatedItemsResponse<Product>(

    // list of items
    listItems: res.data?.products,

    // only required to pass if pagination supported, else null. (can be of any type)
    paginationKey: res.data?.paginationKey,

    // unique id, should only be passed in the repository function.
    // required for functions like `updateItem`, `findByUid`
    // and avoiding duplication of items in list (compares uid)
    idGetter: (product) => product.id,

  );
}

Now, can use this widget like shown in the widget tree:
(No need to handle a refresh indicator separately. It is already present.)

When the reset from fetchPageData fn is true, your code should handle the logic to update
and replace the existing contents. Basically update all items. Much like a pull-down refresh.

The same code is called when user pulls down to refresh on the view with [reset: true] to update all items.

PaginatedItemsBuilder<Product>(
    fetchPageData: (reset) => controller.updateProducts(
        reset: reset,
        showLoaderOnReset: reset,
    ),
    response: controller.productsResponse,
    itemBuilder: (context, index, item) => Text('Item$index : $item'),
),

Want to show items as a grid? Change the cross axis count? Pass in a custom scroll controller?
Well, there are a lot of parameters that can be customized in PaginatedItemsBuilder

See the example directory for a complete sample app.

Created & Maintained By Rithik Bhandari