Line data Source code
1 : part of 'foss_number_field.dart';
2 :
3 : /// Visual overrides for a [FossNumberField]. Every field is optional; a null
4 : /// field falls back to the value the theme resolves for the size and state.
5 : /// Pass one to a single control via `style:` to tweak a one-off, without
6 : /// changing the theme for every other field.
7 : ///
8 : /// State-derived colors (the focus ring and error border) stay token-driven.
9 : /// To restyle those globally, retheme `FossColors`.
10 : ///
11 : /// A wider, pill-cornered control with a warmer stepper hover:
12 : ///
13 : /// ```dart
14 : /// FossNumberField(
15 : /// value: 3,
16 : /// style: const FossNumberFieldStyle(
17 : /// borderRadius: 999,
18 : /// stepperHoverColor: Color(0xFFF1F5F9),
19 : /// ),
20 : /// );
21 : /// ```
22 : @FossSince('0.1.1')
23 : @immutable
24 : class FossNumberFieldStyle {
25 : /// Creates a set of overrides. All fields default to null (inherit).
26 1 : const FossNumberFieldStyle({
27 : this.backgroundColor,
28 : this.borderColor,
29 : this.borderRadius,
30 : this.minHeight,
31 : this.textStyle,
32 : this.iconSize,
33 : this.stepperHoverColor,
34 : this.shadow,
35 : });
36 :
37 : /// Fill color of the field box.
38 : final Color? backgroundColor;
39 :
40 : /// Resting border color, used when neither focused nor invalid.
41 : final Color? borderColor;
42 :
43 : /// Corner radius in logical pixels.
44 : final double? borderRadius;
45 :
46 : /// Minimum box height in logical pixels; grows with text scale.
47 : final double? minHeight;
48 :
49 : /// Style of the numeric value and placeholder. Its color is ignored; the
50 : /// value and placeholder colors stay token-driven.
51 : final TextStyle? textStyle;
52 :
53 : /// Painted stepper glyph size in logical pixels.
54 : final double? iconSize;
55 :
56 : /// Fill painted under a stepper while it is hovered.
57 : final Color? stepperHoverColor;
58 :
59 : /// Drop shadow layers at rest; empty for none.
60 : final List<BoxShadow>? shadow;
61 :
62 : /// Returns a copy with every non-null field of [other] laid over this one.
63 : ///
64 : /// ```dart
65 : /// const base = FossNumberFieldStyle(borderRadius: 8, minHeight: 34);
66 : /// const override = FossNumberFieldStyle(minHeight: 30);
67 : /// base.merge(override); // borderRadius 8 kept, minHeight becomes 30
68 : /// ```
69 1 : FossNumberFieldStyle merge(FossNumberFieldStyle? other) {
70 : if (other == null) return this;
71 1 : return FossNumberFieldStyle(
72 2 : backgroundColor: other.backgroundColor ?? backgroundColor,
73 2 : borderColor: other.borderColor ?? borderColor,
74 2 : borderRadius: other.borderRadius ?? borderRadius,
75 2 : minHeight: other.minHeight ?? minHeight,
76 2 : textStyle: other.textStyle ?? textStyle,
77 2 : iconSize: other.iconSize ?? iconSize,
78 2 : stepperHoverColor: other.stepperHoverColor ?? stepperHoverColor,
79 2 : shadow: other.shadow ?? shadow,
80 : );
81 : }
82 : }
|