Pagination constructor

Pagination({
  1. required int page,
  2. required int pageSize,
  3. required int total,
  4. int siblingCount = 1,
  5. String? className,
  6. Map<String, Object?> props = const {},
  7. Map<String, Object?> style = const {},
  8. DartStyle? dartStyle,
  9. void onChanged(
    1. Object event,
    2. int page
    )?,
})

Creates pagination for total items.

Implementation

Pagination({
  required int page,
  required int pageSize,
  required int total,
  int siblingCount = 1,
  String? className,
  Map<String, Object?> props = const {},
  Map<String, Object?> style = const {},
  DartStyle? dartStyle,
  void Function(Object event, int page)? onChanged,
}) : super(
        'nav',
        props: mergeComponentProps(
          {...props, 'aria-label': props['aria-label'] ?? 'Pagination'},
          className: className,
          defaultStyle: const {
            'display': 'flex',
            'align-items': 'center',
            'justify-content': 'space-between',
            'gap': '12px',
          },
          dartStyle: dartStyle,
          style: style,
        ),
        children: [
          FlintElement(
            'span',
            props: const {
              'style': {'font-size': '13px', 'color': '#667085'},
            },
            children: normalizeChildren(
              _summary(page: page, pageSize: pageSize, total: total),
              const [],
            ),
          ),
          FlintElement(
            'div',
            props: const {
              'style': {
                'display': 'flex',
                'align-items': 'center',
                'gap': '6px',
              },
            },
            children: [
              _button(
                'Previous',
                page - 1,
                disabled: page <= 1,
                onChanged: onChanged,
              ),
              for (final pageNumber in _pages(
                page,
                pageSize,
                total,
                siblingCount,
              ))
                _button(
                  pageNumber.toString(),
                  pageNumber,
                  current: pageNumber == page,
                  onChanged: onChanged,
                ),
              _button(
                'Next',
                page + 1,
                disabled: page >= _pageCount(pageSize, total),
                onChanged: onChanged,
              ),
            ],
          ),
        ],
      );