Line data Source code
1 : part of 'foss_radio.dart';
2 :
3 : /// Visual overrides for a single [FossRadio]. Every field is optional; a null
4 : /// field falls back to the value the theme resolves. Pass one via `style:` to
5 : /// tweak a one-off without changing the theme for every other radio.
6 : ///
7 : /// State-derived colors (the focus ring and invalid border) stay token-driven.
8 : /// To restyle those globally, retheme `FossColors`.
9 : ///
10 : /// A larger circle with a custom checked fill:
11 : ///
12 : /// ```dart
13 : /// FossRadio<String>(
14 : /// value: 'pro',
15 : /// label: 'Pro',
16 : /// style: const FossRadioStyle(
17 : /// circleSize: 22,
18 : /// dotSize: 10,
19 : /// checkedColor: Color(0xFF8A38F5),
20 : /// ),
21 : /// );
22 : /// ```
23 : @immutable
24 : class FossRadioStyle {
25 : /// Creates a set of radio overrides. All fields default to null (inherit).
26 1 : const FossRadioStyle({
27 : this.backgroundColor,
28 : this.checkedColor,
29 : this.dotColor,
30 : this.borderColor,
31 : this.shadow,
32 : this.circleSize,
33 : this.dotSize,
34 : this.gap,
35 : this.labelStyle,
36 : this.descriptionStyle,
37 : });
38 :
39 : /// Fill of the unchecked circle.
40 : final Color? backgroundColor;
41 :
42 : /// Fill of the circle when checked.
43 : final Color? checkedColor;
44 :
45 : /// Color of the inner dot when checked.
46 : final Color? dotColor;
47 :
48 : /// Resting border color of the unchecked circle.
49 : final Color? borderColor;
50 :
51 : /// Drop shadow layers on the unchecked circle; empty for none.
52 : final List<BoxShadow>? shadow;
53 :
54 : /// Diameter of the circle in logical pixels.
55 : final double? circleSize;
56 :
57 : /// Diameter of the inner dot in logical pixels.
58 : final double? dotSize;
59 :
60 : /// Gap between the circle and the texts in logical pixels.
61 : final double? gap;
62 :
63 : /// Style of the [FossRadio.label]. Its color is ignored; the title color
64 : /// stays token-driven.
65 : final TextStyle? labelStyle;
66 :
67 : /// Style of the [FossRadio.description]. Its color is ignored; the
68 : /// description color stays token-driven.
69 : final TextStyle? descriptionStyle;
70 :
71 : /// Returns a copy with every non-null field of [other] laid over this one.
72 : ///
73 : /// ```dart
74 : /// const base = FossRadioStyle(circleSize: 18, dotSize: 8);
75 : /// const override = FossRadioStyle(dotSize: 10);
76 : /// base.merge(override); // circleSize 18 kept, dotSize becomes 10
77 : /// ```
78 1 : FossRadioStyle merge(FossRadioStyle? other) {
79 : if (other == null) return this;
80 1 : return FossRadioStyle(
81 2 : backgroundColor: other.backgroundColor ?? backgroundColor,
82 2 : checkedColor: other.checkedColor ?? checkedColor,
83 2 : dotColor: other.dotColor ?? dotColor,
84 2 : borderColor: other.borderColor ?? borderColor,
85 2 : shadow: other.shadow ?? shadow,
86 2 : circleSize: other.circleSize ?? circleSize,
87 2 : dotSize: other.dotSize ?? dotSize,
88 2 : gap: other.gap ?? gap,
89 2 : labelStyle: other.labelStyle ?? labelStyle,
90 2 : descriptionStyle: other.descriptionStyle ?? descriptionStyle,
91 : );
92 : }
93 : }
|