build method
Describes the part of the UI represented by this widget.
Implementation
@override
Widget build(BuildContext context) {
final theme = ThemeScope.of(context);
final clampedPage = page.clamp(1, math.max(1, pageCount)).toInt();
final labelStyle = _copyStyle(theme.labelSmall)..foreground(theme.muted);
final controls = <Widget>[];
if (showEdges) {
controls.add(
Button(
label: 'First',
size: ButtonSize.small,
variant: ButtonVariant.ghost,
enabled: clampedPage > 1,
onPressed: onChanged == null ? null : () => onChanged?.call(1),
),
);
}
controls.add(
Button(
label: 'Prev',
size: ButtonSize.small,
variant: ButtonVariant.ghost,
enabled: clampedPage > 1,
onPressed: onChanged == null
? null
: () => onChanged?.call(clampedPage - 1),
),
);
controls.add(
Text('Page $clampedPage / ${math.max(1, pageCount)}', style: labelStyle),
);
controls.add(
Button(
label: 'Next',
size: ButtonSize.small,
variant: ButtonVariant.ghost,
enabled: clampedPage < pageCount,
onPressed: onChanged == null
? null
: () => onChanged?.call(clampedPage + 1),
),
);
if (showEdges) {
controls.add(
Button(
label: 'Last',
size: ButtonSize.small,
variant: ButtonVariant.ghost,
enabled: clampedPage < pageCount,
onPressed: onChanged == null
? null
: () => onChanged?.call(pageCount),
),
);
}
return Row(gap: gap, children: controls);
}