Line data Source code
1 : part of 'foss_bottom_nav_bar.dart';
2 :
3 : /// Visual overrides for a single [FossBottomNavBar]. 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 changing the theme for every other bar.
6 : ///
7 : /// A bar on the card surface with no top rule:
8 : ///
9 : /// ```dart
10 : /// FossBottomNavBar<String>(
11 : /// items: items,
12 : /// value: section,
13 : /// onChanged: onChanged,
14 : /// style: const FossBottomNavBarStyle(showTopBorder: false),
15 : /// );
16 : /// ```
17 : @immutable
18 : @FossSince('0.1.3')
19 : class FossBottomNavBarStyle {
20 : /// Creates a set of bar overrides. All fields default to null (inherit).
21 1 : const FossBottomNavBarStyle({
22 : this.backgroundColor,
23 : this.borderColor,
24 : this.selectedColor,
25 : this.unselectedColor,
26 : this.labelStyle,
27 : this.iconSize,
28 : this.minHeight,
29 : this.showTopBorder,
30 : });
31 :
32 : /// Fill of the bar, painted through the bottom safe-area inset.
33 : final Color? backgroundColor;
34 :
35 : /// Color of the hairline along the bar's top edge.
36 : final Color? borderColor;
37 :
38 : /// Glyph and label color of the current destination.
39 : final Color? selectedColor;
40 :
41 : /// Glyph and label color of the other destinations.
42 : final Color? unselectedColor;
43 :
44 : /// Text style of every label. Color is applied per state.
45 : final TextStyle? labelStyle;
46 :
47 : /// Glyph size in logical pixels.
48 : final double? iconSize;
49 :
50 : /// Minimum height of a cell in logical pixels, excluding the safe-area inset.
51 : /// A cell grows past it when the text scaler does.
52 : final double? minHeight;
53 :
54 : /// Whether the hairline along the top edge is drawn.
55 : final bool? showTopBorder;
56 :
57 : /// Returns a copy with every non-null field of [other] laid over this one.
58 : ///
59 : /// ```dart
60 : /// const base = FossBottomNavBarStyle(minHeight: 64);
61 : /// const override = FossBottomNavBarStyle(showTopBorder: false);
62 : /// base.merge(override); // minHeight kept, showTopBorder added
63 : /// ```
64 1 : FossBottomNavBarStyle merge(FossBottomNavBarStyle? other) {
65 : if (other == null) return this;
66 1 : return FossBottomNavBarStyle(
67 2 : backgroundColor: other.backgroundColor ?? backgroundColor,
68 2 : borderColor: other.borderColor ?? borderColor,
69 1 : selectedColor: other.selectedColor ?? selectedColor,
70 2 : unselectedColor: other.unselectedColor ?? unselectedColor,
71 2 : labelStyle: other.labelStyle ?? labelStyle,
72 2 : iconSize: other.iconSize ?? iconSize,
73 2 : minHeight: other.minHeight ?? minHeight,
74 2 : showTopBorder: other.showTopBorder ?? showTopBorder,
75 : );
76 : }
77 : }
|