Line data Source code
1 : part of 'foss_avatar.dart';
2 :
3 : /// Visual overrides for a single [FossAvatar]. 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 avatar.
6 : ///
7 : /// ```dart
8 : /// FossAvatar(
9 : /// fallback: const Text('VL'),
10 : /// style: const FossAvatarStyle(fallbackColor: Color(0xFFE5E7EB)),
11 : /// );
12 : /// ```
13 : @immutable
14 : class FossAvatarStyle {
15 : /// Creates a set of avatar overrides. All fields default to null (inherit).
16 1 : const FossAvatarStyle({
17 : this.backgroundColor,
18 : this.fallbackColor,
19 : this.fallbackTextStyle,
20 : });
21 :
22 : /// Fill of the circle behind the image.
23 : final Color? backgroundColor;
24 :
25 : /// Fill of the fallback layer shown when the image is absent or loading.
26 : final Color? fallbackColor;
27 :
28 : /// Style of the [FossAvatar.fallback] text. Merged over the token default.
29 : final TextStyle? fallbackTextStyle;
30 :
31 : /// Returns a copy with every non-null field of [other] laid over this one.
32 1 : FossAvatarStyle merge(FossAvatarStyle? other) {
33 : if (other == null) return this;
34 1 : return FossAvatarStyle(
35 2 : backgroundColor: other.backgroundColor ?? backgroundColor,
36 1 : fallbackColor: other.fallbackColor ?? fallbackColor,
37 2 : fallbackTextStyle: other.fallbackTextStyle ?? fallbackTextStyle,
38 : );
39 : }
40 : }
|