Line data Source code
1 : part of 'foss_time_picker.dart';
2 :
3 : /// Visual overrides for a single [FossTimePicker]. Every field is optional; a
4 : /// null field falls back to the value the theme resolves. Pass one via `style:`
5 : /// to tweak a one-off without retheming.
6 : ///
7 : /// [placeholderColor] and [gap] mirror `FossDatePickerStyle` so the two field
8 : /// triggers restyle together; the rest tune the wheels inside the modal. The
9 : /// dialog surface and the footer buttons restyle through the theme or their own
10 : /// styles, not through here.
11 : ///
12 : /// ```dart
13 : /// FossTimePicker(
14 : /// value: picked,
15 : /// onChanged: (time) => setState(() => picked = time),
16 : /// style: const FossTimePickerStyle(visibleItemCount: 3),
17 : /// );
18 : /// ```
19 : @FossSince('0.1.2')
20 : @immutable
21 : class FossTimePickerStyle {
22 : /// Creates a set of overrides. All fields default to null (inherit).
23 : ///
24 : /// [visibleItemCount] must be odd and at least 3, so a single row sits in the
25 : /// centre band with the same number of neighbours above and below.
26 1 : const FossTimePickerStyle({
27 : this.placeholderColor,
28 : this.gap,
29 : this.itemExtent,
30 : this.visibleItemCount,
31 : this.highlightColor,
32 : }) : assert(
33 2 : itemExtent == null || itemExtent > 0,
34 : 'itemExtent must be positive.',
35 : ),
36 : assert(
37 1 : visibleItemCount == null ||
38 3 : (visibleItemCount >= 3 && visibleItemCount % 2 == 1),
39 : 'visibleItemCount must be an odd number of 3 or more.',
40 : );
41 :
42 : /// Color of the placeholder label shown while nothing is selected.
43 : final Color? placeholderColor;
44 :
45 : /// Gap between the leading clock glyph and the trigger label, in logical
46 : /// pixels.
47 : final double? gap;
48 :
49 : /// Height of one wheel row in logical pixels, before text scaling. Defaults
50 : /// to 36, the trigger height, so the field and the sheet share one rhythm.
51 : final double? itemExtent;
52 :
53 : /// How many rows a wheel shows at once. Odd, 3 or more; defaults to 5.
54 : final int? visibleItemCount;
55 :
56 : /// Fill of the centre band behind the selected row. Defaults to the accent
57 : /// role.
58 : final Color? highlightColor;
59 :
60 : /// Returns a copy with every non-null field of [other] laid over this one.
61 1 : FossTimePickerStyle merge(FossTimePickerStyle? other) {
62 : if (other == null) return this;
63 1 : return FossTimePickerStyle(
64 2 : placeholderColor: other.placeholderColor ?? placeholderColor,
65 1 : gap: other.gap ?? gap,
66 2 : itemExtent: other.itemExtent ?? itemExtent,
67 1 : visibleItemCount: other.visibleItemCount ?? visibleItemCount,
68 2 : highlightColor: other.highlightColor ?? highlightColor,
69 : );
70 : }
71 : }
|