Skip to content

Commit 5d7e0b0

Browse files
committed
feat: add app settings models
- Added DisplaySettings model - Added supporting enums - Added JSON serialization - Added unit tests
1 parent 910fa04 commit 5d7e0b0

File tree

11 files changed

+375
-1
lines changed

11 files changed

+375
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ht_shared
22

3-
![coverage: percentage](https://img.shields.io/badge/coverage-96-green)
3+
![coverage: percentage](https://img.shields.io/badge/coverage-97-green)
44
[![style: very good analysis](https://img.shields.io/badge/style-very_good_analysis-B22C89.svg)](https://pub.dev/packages/very_good_analysis)
55
[![License: PolyForm Free Trial](https://img.shields.io/badge/License-PolyForm%20Free%20Trial-blue)](https://polyformproject.org/licenses/free-trial/1.0.0)
66

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// {@template app_accent_theme}
2+
/// Represents a selection of predefined accent color themes.
3+
///
4+
/// These themes typically define the primary accent color used for interactive
5+
/// elements, highlights, and branding touches throughout the application.
6+
/// The actual `ColorScheme` associated with each enum value would be defined
7+
/// within the application's theme configuration.
8+
/// {@endtemplate}
9+
enum AppAccentTheme {
10+
/// The default blue accent theme.
11+
defaultBlue,
12+
13+
/// A red accent theme, often suitable for news applications.
14+
newsRed,
15+
16+
/// A neutral gray/graphite accent theme.
17+
graphiteGray,
18+
19+
// Add other predefined accent themes here as needed.
20+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// {@template app_base_theme}
2+
/// Represents the available base application theme modes.
3+
///
4+
/// This determines the overall light or dark appearance of the UI,
5+
/// or allows following the device's system setting.
6+
/// {@endtemplate}
7+
enum AppBaseTheme {
8+
/// Apply the light theme.
9+
light,
10+
11+
/// Apply the dark theme.
12+
dark,
13+
14+
/// Follow the operating system's theme setting (light or dark).
15+
system,
16+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/// {@template app_font_weight}
2+
/// Represents user-selectable font weight preferences.
3+
///
4+
/// This allows users to choose the thickness of text characters, which can
5+
/// affect readability and visual style. These typically map to standard
6+
/// `FontWeight` values (e.g., `FontWeight.w300`, `FontWeight.w400`,
7+
/// `FontWeight.w700`).
8+
/// {@endtemplate}
9+
enum AppFontWeight {
10+
/// Light font weight (e.g., maps to `FontWeight.w300`).
11+
light,
12+
13+
/// Regular font weight (e.g., maps to `FontWeight.w400`).
14+
regular,
15+
16+
/// Bold font weight (e.g., maps to `FontWeight.w700`).
17+
bold,
18+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// {@template app_language}
2+
/// Represents the selected application language.
3+
///
4+
/// Typically stored as an ISO 639-1 language code (e.g., 'en', 'ar').
5+
/// The application using this client is responsible for knowing which
6+
/// language codes it supports and how to map them to localized resources.
7+
/// {@endtemplate}
8+
typedef AppLanguage = String;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export 'app_accent_theme.dart';
2+
export 'app_base_theme.dart';
3+
export 'app_font_weight.dart';
4+
export 'app_language.dart';
5+
export 'app_text_scale_factor.dart';
6+
export 'display_settings.dart';
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// {@template app_text_scale_factor}
2+
/// Represents user-selectable text size preferences, often mapped to
3+
/// system text scale factors for accessibility.
4+
///
5+
/// This allows users to increase or decrease the overall size of text
6+
/// throughout the application for better readability.
7+
/// {@endtemplate}
8+
enum AppTextScaleFactor {
9+
/// Smaller text size.
10+
small,
11+
12+
/// Default/medium text size.
13+
medium,
14+
15+
/// Larger text size.
16+
large,
17+
18+
/// Extra large text size.
19+
extraLarge,
20+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
}

lib/src/models/app-settings/display_settings.g.dart

Lines changed: 61 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/models/models.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
export 'app-settings/app_settings.dart';
12
export 'auth_success_response.dart';
23
export 'category.dart';
34
export 'country.dart';
45
export 'headline.dart';
56
export 'paginated_reponse.dart';
7+
export 'permission.dart';
68
export 'response_metadata.dart';
79
export 'source.dart';
810
export 'success_api_response.dart';

0 commit comments

Comments
 (0)