Line data Source code
1 : part of 'foss_list_tile.dart';
2 :
3 : /// Visual overrides for a [FossListTile]. Every field is optional; a null field
4 : /// falls back to what the theme resolves. Pass one to a single tile via
5 : /// `style:` to tweak a one-off, without changing the theme for every other row.
6 : ///
7 : /// [backgroundColor] is a [WidgetStateProperty] resolved against the row's
8 : /// interactive state set (hovered, pressed, focused, disabled); the rest are
9 : /// plain values. [titleStyle] and [subtitleStyle] merge over the resolved text
10 : /// styles, so setting only a size keeps the token color.
11 : ///
12 : /// A roomier row with a tinted highlight:
13 : ///
14 : /// ```dart
15 : /// FossListTile(
16 : /// title: const Text('Storage'),
17 : /// onTap: openStorage,
18 : /// style: FossListTileStyle(
19 : /// minHeight: 56,
20 : /// backgroundColor: WidgetStateProperty.resolveWith((states) {
21 : /// if (states.contains(WidgetState.pressed)) {
22 : /// return const Color(0x1416A34A);
23 : /// }
24 : /// return const Color(0x00000000);
25 : /// }),
26 : /// ),
27 : /// );
28 : /// ```
29 : @immutable
30 : class FossListTileStyle {
31 : /// Creates a set of tile overrides. All fields default to null (inherit).
32 2 : const FossListTileStyle({
33 : this.backgroundColor,
34 : this.padding,
35 : this.gap,
36 : this.minHeight,
37 : this.borderRadius,
38 : this.titleStyle,
39 : this.subtitleStyle,
40 : this.iconSize,
41 : });
42 :
43 : /// Fill color per interactive state. The row is transparent at rest.
44 : final WidgetStateProperty<Color>? backgroundColor;
45 :
46 : /// Inner padding around the slots.
47 : final EdgeInsetsGeometry? padding;
48 :
49 : /// Gap between the leading slot, the text column, and the trailing slot, in
50 : /// logical pixels.
51 : final double? gap;
52 :
53 : /// Minimum row height in logical pixels; the row grows past it for a
54 : /// two-line subtitle or a taller slot.
55 : final double? minHeight;
56 :
57 : /// Uniform corner radius of the highlight fill, in logical pixels.
58 : final double? borderRadius;
59 :
60 : /// Overrides merged over the resolved title style.
61 : final TextStyle? titleStyle;
62 :
63 : /// Overrides merged over the resolved subtitle style.
64 : final TextStyle? subtitleStyle;
65 :
66 : /// Icon size for the leading and trailing slots, in logical pixels.
67 : final double? iconSize;
68 :
69 : /// Returns a copy with every non-null field of [other] laid over this one.
70 : /// Used to layer a per-instance override on the theme-resolved defaults.
71 : ///
72 : /// ```dart
73 : /// const base = FossListTileStyle(minHeight: 48, gap: 16);
74 : /// const override = FossListTileStyle(gap: 12);
75 : /// base.merge(override); // minHeight 48 kept, gap becomes 12
76 : /// ```
77 1 : FossListTileStyle merge(FossListTileStyle? other) {
78 : if (other == null) return this;
79 1 : return FossListTileStyle(
80 2 : backgroundColor: other.backgroundColor ?? backgroundColor,
81 2 : padding: other.padding ?? padding,
82 1 : gap: other.gap ?? gap,
83 2 : minHeight: other.minHeight ?? minHeight,
84 2 : borderRadius: other.borderRadius ?? borderRadius,
85 2 : titleStyle: other.titleStyle ?? titleStyle,
86 2 : subtitleStyle: other.subtitleStyle ?? subtitleStyle,
87 2 : iconSize: other.iconSize ?? iconSize,
88 : );
89 : }
90 : }
|