Line data Source code
1 : part of 'foss_pagination.dart';
2 :
3 : /// Visual overrides for a [FossPagination]. Every field is optional; a null
4 : /// field falls back to the theme-resolved default. Pass one via `style:` to
5 : /// tweak a single row without changing the theme. The button colors, radius,
6 : /// and type resolve through [FossButton]; this carries only the row knobs.
7 : ///
8 : /// ```dart
9 : /// FossPagination(
10 : /// page: page,
11 : /// pageCount: 20,
12 : /// onPageChanged: (p) => setState(() => page = p),
13 : /// style: const FossPaginationStyle(gap: 6),
14 : /// );
15 : /// ```
16 : @immutable
17 : class FossPaginationStyle {
18 : /// Creates a set of row overrides. All fields default to null (inherit).
19 1 : const FossPaginationStyle({
20 : this.gap,
21 : this.buttonSize,
22 : this.activeVariant,
23 : this.inactiveVariant,
24 : this.ellipsisColor,
25 : this.ellipsisWidth,
26 : });
27 :
28 : /// Gap between controls, in logical pixels.
29 : final double? gap;
30 :
31 : /// Size of every control in the row.
32 : final FossButtonSize? buttonSize;
33 :
34 : /// Treatment of the current page button.
35 : final FossButtonVariant? activeVariant;
36 :
37 : /// Treatment of the other page buttons and of previous and next.
38 : final FossButtonVariant? inactiveVariant;
39 :
40 : /// Color of the ellipsis glyph.
41 : final Color? ellipsisColor;
42 :
43 : /// Width of an ellipsis slot, in logical pixels. Defaults to the width a page
44 : /// button occupies, which keeps the row's pitch even; narrowing it makes the
45 : /// row change width as ellipses come and go.
46 : final double? ellipsisWidth;
47 :
48 : /// Returns a copy with every non-null field of [other] laid over this one.
49 : ///
50 : /// ```dart
51 : /// const base = FossPaginationStyle(gap: 2);
52 : /// const override = FossPaginationStyle(gap: 6);
53 : /// base.merge(override); // gap becomes 6
54 : /// ```
55 1 : FossPaginationStyle merge(FossPaginationStyle? other) {
56 : if (other == null) return this;
57 1 : return FossPaginationStyle(
58 1 : gap: other.gap ?? gap,
59 2 : buttonSize: other.buttonSize ?? buttonSize,
60 2 : activeVariant: other.activeVariant ?? activeVariant,
61 1 : inactiveVariant: other.inactiveVariant ?? inactiveVariant,
62 1 : ellipsisColor: other.ellipsisColor ?? ellipsisColor,
63 1 : ellipsisWidth: other.ellipsisWidth ?? ellipsisWidth,
64 : );
65 : }
66 : }
|