Line data Source code
1 : part of 'foss_toggle_group.dart';
2 :
3 : /// Visual overrides for a [FossToggleGroup]. Every field is optional; a null
4 : /// field falls back to the theme-resolved default. Pass one via `style:` to
5 : /// tweak a single group without changing the theme. The item colors, radius,
6 : /// and type resolve through each [FossToggle]; this carries only the group
7 : /// knobs.
8 : ///
9 : /// ```dart
10 : /// FossToggleGroup.single(
11 : /// value: view,
12 : /// onChanged: (v) => setState(() => view = v),
13 : /// style: const FossToggleGroupStyle(gap: 6),
14 : /// children: const [
15 : /// FossToggleGroupItem(value: 'list', child: Text('List')),
16 : /// FossToggleGroupItem(value: 'grid', child: Text('Grid')),
17 : /// ],
18 : /// );
19 : /// ```
20 : @immutable
21 : class FossToggleGroupStyle {
22 : /// Creates a set of group overrides. All fields default to null (inherit).
23 1 : const FossToggleGroupStyle({this.gap, this.connectedBorderColor});
24 :
25 : /// Gap between items in the standard variant, in logical pixels.
26 : final double? gap;
27 :
28 : /// Color of the shared border and seams in the outline variant.
29 : final Color? connectedBorderColor;
30 :
31 : /// Returns a copy with every non-null field of [other] laid over this one.
32 : ///
33 : /// ```dart
34 : /// const base = FossToggleGroupStyle(gap: 2);
35 : /// const override = FossToggleGroupStyle(gap: 6);
36 : /// base.merge(override); // gap becomes 6
37 : /// ```
38 1 : FossToggleGroupStyle merge(FossToggleGroupStyle? other) {
39 : if (other == null) return this;
40 1 : return FossToggleGroupStyle(
41 2 : gap: other.gap ?? gap,
42 1 : connectedBorderColor: other.connectedBorderColor ?? connectedBorderColor,
43 : );
44 : }
45 : }
|