Line data Source code
1 : part of 'foss_accordion.dart';
2 :
3 : /// Visual overrides for a single accordion. 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 accordion.
6 : ///
7 : /// The focus ring stays token-driven (the `ring` role); to restyle it globally,
8 : /// retheme [FossColors].
9 : ///
10 : /// A quieter divider and a larger title:
11 : ///
12 : /// ```dart
13 : /// FossAccordion(
14 : /// style: FossAccordionStyle(
15 : /// dividerColor: Color(0x11000000),
16 : /// titleTextStyle: TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
17 : /// ),
18 : /// children: const [
19 : /// FossAccordionItem(value: 'a', title: Text('T'), child: Text('Body')),
20 : /// ],
21 : /// );
22 : /// ```
23 : @FossSince('0.1.1')
24 : @immutable
25 : class FossAccordionStyle {
26 : /// Creates a set of accordion overrides. Fields default to null (inherit).
27 1 : const FossAccordionStyle({
28 : this.titleTextStyle,
29 : this.panelTextStyle,
30 : this.chevronColor,
31 : this.dividerColor,
32 : this.headerPadding,
33 : this.panelPadding,
34 : });
35 :
36 : /// Text style of the header title.
37 : final TextStyle? titleTextStyle;
38 :
39 : /// Text style of the panel content.
40 : final TextStyle? panelTextStyle;
41 :
42 : /// Color of the header chevron.
43 : final Color? chevronColor;
44 :
45 : /// Color of the 1px hairline under each item (dropped on the last item).
46 : final Color? dividerColor;
47 :
48 : /// Padding around the header row.
49 : final EdgeInsetsGeometry? headerPadding;
50 :
51 : /// Padding around the panel content.
52 : final EdgeInsetsGeometry? panelPadding;
53 :
54 : /// Returns a copy with every non-null field of [other] laid over this one.
55 : ///
56 : /// ```dart
57 : /// const base = FossAccordionStyle(dividerColor: Color(0x14000000));
58 : /// const override = FossAccordionStyle(dividerColor: Color(0x11000000));
59 : /// base.merge(override); // dividerColor becomes 0x11000000
60 : /// ```
61 1 : FossAccordionStyle merge(FossAccordionStyle? other) {
62 : if (other == null) return this;
63 1 : return FossAccordionStyle(
64 2 : titleTextStyle: other.titleTextStyle ?? titleTextStyle,
65 2 : panelTextStyle: other.panelTextStyle ?? panelTextStyle,
66 2 : chevronColor: other.chevronColor ?? chevronColor,
67 2 : dividerColor: other.dividerColor ?? dividerColor,
68 2 : headerPadding: other.headerPadding ?? headerPadding,
69 2 : panelPadding: other.panelPadding ?? panelPadding,
70 : );
71 : }
72 : }
|