Skip to content

Commit 86bea33

Browse files
committed
feat(ads): add AdThemeStyle model for native ad theming
- Create UI-agnostic data model for ad theme properties - Implement factory constructor to adapt Flutter ThemeData - Define properties for background colors, text colors, font sizes, and corner radius - Use Equatable for easy comparison and hashing
1 parent e04b5bc commit 86bea33

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

lib/ads/models/ad_theme_style.dart

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import 'package:equatable/equatable.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:ui_kit/ui_kit.dart';
4+
5+
/// {@template ad_theme_style}
6+
/// A UI-agnostic data model representing the theme properties required for
7+
/// styling native advertisements.
8+
///
9+
/// This class decouples ad styling logic from Flutter's [ThemeData],
10+
/// allowing theme-related values to be passed to service layers without
11+
/// direct UI context dependencies.
12+
/// {@endtemplate}
13+
class AdThemeStyle extends Equatable {
14+
/// {@macro ad_theme_style}
15+
const AdThemeStyle({
16+
required this.mainBackgroundColor,
17+
required this.cornerRadius,
18+
required this.callToActionTextColor,
19+
required this.callToActionBackgroundColor,
20+
required this.callToActionTextSize,
21+
required this.primaryTextColor,
22+
required this.primaryBackgroundColor,
23+
required this.primaryTextSize,
24+
required this.secondaryTextColor,
25+
required this.secondaryBackgroundColor,
26+
required this.secondaryTextSize,
27+
required this.tertiaryTextColor,
28+
required this.tertiaryBackgroundColor,
29+
required this.tertiaryTextSize,
30+
});
31+
32+
/// Factory constructor to create an [AdThemeStyle] from a Flutter [ThemeData].
33+
///
34+
/// This method acts as an adapter, extracting the relevant styling properties
35+
/// from the UI's theme and mapping them to the UI-agnostic [AdThemeStyle] model.
36+
factory AdThemeStyle.fromTheme(ThemeData theme) {
37+
final colorScheme = theme.colorScheme;
38+
final textTheme = theme.textTheme;
39+
40+
return AdThemeStyle(
41+
mainBackgroundColor: colorScheme.surface,
42+
cornerRadius: AppSpacing.sm,
43+
callToActionTextColor: colorScheme.onPrimary,
44+
callToActionBackgroundColor: colorScheme.primary,
45+
callToActionTextSize: textTheme.labelLarge?.fontSize,
46+
primaryTextColor: colorScheme.onSurface,
47+
primaryBackgroundColor: colorScheme.surface,
48+
primaryTextSize: textTheme.titleMedium?.fontSize,
49+
secondaryTextColor: colorScheme.onSurfaceVariant,
50+
secondaryBackgroundColor: colorScheme.surface,
51+
secondaryTextSize: textTheme.bodyMedium?.fontSize,
52+
tertiaryTextColor: colorScheme.onSurfaceVariant,
53+
tertiaryBackgroundColor: colorScheme.surface,
54+
tertiaryTextSize: textTheme.labelSmall?.fontSize,
55+
);
56+
}
57+
58+
/// The background color for the main ad container.
59+
final Color mainBackgroundColor;
60+
61+
/// The corner radius for the ad container.
62+
final double cornerRadius;
63+
64+
/// The text color for the call-to-action button.
65+
final Color callToActionTextColor;
66+
67+
/// The background color for the call-to-action button.
68+
final Color callToActionBackgroundColor;
69+
70+
/// The font size for the call-to-action text.
71+
final double? callToActionTextSize;
72+
73+
/// The text color for the primary text (e.g., ad headline).
74+
final Color primaryTextColor;
75+
76+
/// The background color for the primary text.
77+
final Color primaryBackgroundColor;
78+
79+
/// The font size for the primary text.
80+
final double? primaryTextSize;
81+
82+
/// The text color for the secondary text (e.g., ad body).
83+
final Color secondaryTextColor;
84+
85+
/// The background color for the secondary text.
86+
final Color secondaryBackgroundColor;
87+
88+
/// The font size for the secondary text.
89+
final double? secondaryTextSize;
90+
91+
/// The text color for the tertiary text (e.g., ad attribution).
92+
final Color tertiaryTextColor;
93+
94+
/// The background color for the tertiary text.
95+
final Color tertiaryBackgroundColor;
96+
97+
/// The font size for the tertiary text.
98+
final double? tertiaryTextSize;
99+
100+
@override
101+
List<Object?> get props => [
102+
mainBackgroundColor,
103+
cornerRadius,
104+
callToActionTextColor,
105+
callToActionBackgroundColor,
106+
callToActionTextSize,
107+
primaryTextColor,
108+
primaryBackgroundColor,
109+
primaryTextSize,
110+
secondaryTextColor,
111+
secondaryBackgroundColor,
112+
secondaryTextSize,
113+
tertiaryTextColor,
114+
tertiaryBackgroundColor,
115+
tertiaryTextSize,
116+
];
117+
}

0 commit comments

Comments
 (0)