|
| 1 | +import 'package:equatable/equatable.dart'; |
| 2 | +import 'package:ht_shared/src/models/app-settings/app_settings.dart'; |
| 3 | + |
| 4 | +import 'package:json_annotation/json_annotation.dart'; |
| 5 | + |
| 6 | +part 'display_settings.g.dart'; |
| 7 | + |
| 8 | +/// {@template display_settings} |
| 9 | +/// Represents a collection of user-configurable settings related to the |
| 10 | +/// application's visual appearance and display characteristics. |
| 11 | +/// |
| 12 | +/// This model groups settings like theme mode, accent colors, font choices, |
| 13 | +/// text scaling, and font weight, allowing them to be managed and persisted |
| 14 | +/// together. |
| 15 | +/// {@endtemplate} |
| 16 | +@JsonSerializable() |
| 17 | +class DisplaySettings extends Equatable { |
| 18 | + /// {@macro display_settings} |
| 19 | + /// |
| 20 | + /// Creates a new instance of [DisplaySettings]. |
| 21 | + /// |
| 22 | + /// Provides sensible defaults for each setting if not specified: |
| 23 | + /// - `baseTheme`: [AppBaseTheme.system] |
| 24 | + /// - `accentTheme`: [AppAccentTheme.defaultBlue] |
| 25 | + /// - `fontFamily`: 'SystemDefault' (indicating usage of the platform's |
| 26 | + /// default font) |
| 27 | + /// - `textScaleFactor`: [AppTextScaleFactor.medium] |
| 28 | + /// - `fontWeight`: [AppFontWeight.regular] |
| 29 | + const DisplaySettings({ |
| 30 | + this.baseTheme = AppBaseTheme.system, // Default value |
| 31 | + this.accentTheme = AppAccentTheme.defaultBlue, // Default value |
| 32 | + this.fontFamily = 'SystemDefault', // Default value |
| 33 | + this.textScaleFactor = AppTextScaleFactor.medium, // Default value |
| 34 | + this.fontWeight = AppFontWeight.regular, // Default value |
| 35 | + }); |
| 36 | + |
| 37 | + /// Creates a [DisplaySettings] instance from a JSON map. |
| 38 | + factory DisplaySettings.fromJson(Map<String, dynamic> json) => |
| 39 | + _$DisplaySettingsFromJson(json); |
| 40 | + |
| 41 | + /// The base theme mode (light, dark, or system default). |
| 42 | + final AppBaseTheme baseTheme; |
| 43 | + |
| 44 | + /// The selected predefined accent color theme. |
| 45 | + final AppAccentTheme accentTheme; |
| 46 | + |
| 47 | + /// The name or identifier of the selected font family. |
| 48 | + /// 'SystemDefault' is used as a convention to indicate the platform's |
| 49 | + /// default font should be used. Other values would correspond to specific |
| 50 | + /// font families bundled with or available to the application. |
| 51 | + final String fontFamily; |
| 52 | + |
| 53 | + /// The preferred text size scaling factor. |
| 54 | + final AppTextScaleFactor textScaleFactor; |
| 55 | + |
| 56 | + /// The preferred font weight. |
| 57 | + final AppFontWeight fontWeight; |
| 58 | + |
| 59 | + /// Creates a copy of this [DisplaySettings] but with the given fields |
| 60 | + /// replaced with the new values. |
| 61 | + DisplaySettings copyWith({ |
| 62 | + AppBaseTheme? baseTheme, |
| 63 | + AppAccentTheme? accentTheme, |
| 64 | + String? fontFamily, |
| 65 | + AppTextScaleFactor? textScaleFactor, |
| 66 | + AppFontWeight? fontWeight, |
| 67 | + }) { |
| 68 | + return DisplaySettings( |
| 69 | + baseTheme: baseTheme ?? this.baseTheme, |
| 70 | + accentTheme: accentTheme ?? this.accentTheme, |
| 71 | + fontFamily: fontFamily ?? this.fontFamily, |
| 72 | + textScaleFactor: textScaleFactor ?? this.textScaleFactor, |
| 73 | + fontWeight: fontWeight ?? this.fontWeight, |
| 74 | + ); |
| 75 | + } |
| 76 | + |
| 77 | + @override |
| 78 | + List<Object?> get props => [ |
| 79 | + baseTheme, |
| 80 | + accentTheme, |
| 81 | + fontFamily, |
| 82 | + textScaleFactor, |
| 83 | + fontWeight, |
| 84 | + ]; |
| 85 | + |
| 86 | + /// Converts this [DisplaySettings] instance to a JSON map. |
| 87 | + Map<String, dynamic> toJson() => _$DisplaySettingsToJson(this); |
| 88 | +} |
0 commit comments