PageableLayoutWidgetBuilder<PageKey, Item> typedef

PageableLayoutWidgetBuilder<PageKey, Item> = Widget Function(BuildContext context, PageableView<PageKey, Item> pageable, VoidCallback fetchFirstPage, VoidCallback fetchNextPage, VoidCallback retry)

Signature for builder functions that build a widget based on the current pageable state and control callbacks.

This function type is used to build custom widgets that react to pagination state changes.

Generic parameters:

  • PageKey: The type of the page key used in pagination (e.g., int, String).
  • Item: The type of the items being paginated.

Parameters:

  • context: The current BuildContext.
  • pageable: The current PageableView state containing loaded pages, next page key, loading and error flags, etc.
  • fetchFirstPage: Callback to trigger fetching the first page of data.
  • fetchNextPage: Callback to trigger fetching the next page of data.
  • retry: Callback to retry a failed fetch request.

Returns a Widget that reflects the current pagination state.

Example:

PageableLayoutWidgetBuilder<int, MyItem> builder = (context, pageable, fetchFirstPage, fetchNextPage, retry) {
  if (pageable.status.isLoadingFirstPage) {
    return const CircularProgressIndicator();
  } else if (pageable.status.isFirstPageError) {
    return ElevatedButton(
      onPressed: retry,
      child: const Text('Try Again'),
    );
  }
  return ListView.builder(
    itemCount: state.pages.values.fold(0, (sum, list) => sum + list.length),
    itemBuilder: (context, index) {
      final items = state.pages.values.expand((e) => e).toList();
      return ListTile(title: Text(items[index].toString()));
    },
  );
};

Implementation

typedef PageableLayoutWidgetBuilder<PageKey, Item> = Widget Function(
  BuildContext context,
  PageableView<PageKey, Item> pageable,
  VoidCallback fetchFirstPage,
  VoidCallback fetchNextPage,
  VoidCallback retry,
);