Skip to content

Commit 7413d25

Browse files
committed
refactor(ad): improve UI consistency and code formatting in interstitial ad settings
- Replace CheckboxListTile with SwitchListTile for better consistency with other screens - Update checkbox labels to follow a more consistent pattern - Adjust code formatting and indentation for improved readability
1 parent ffc0c65 commit 7413d25

File tree

1 file changed

+39
-31
lines changed

1 file changed

+39
-31
lines changed

lib/app_configuration/widgets/interstitial_ad_settings_form.dart

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class _InterstitialAdSettingsFormState extends State<InterstitialAdSettingsForm>
3535
/// Controllers for transitions before showing interstitial ads, mapped by user role.
3636
/// These are used to manage text input for each role's interstitial ad frequency.
3737
late final Map<AppUserRole, TextEditingController>
38-
_transitionsBeforeShowingInterstitialAdsControllers;
38+
_transitionsBeforeShowingInterstitialAdsControllers;
3939

4040
@override
4141
void initState() {
@@ -55,17 +55,19 @@ class _InterstitialAdSettingsFormState extends State<InterstitialAdSettingsForm>
5555
widget.remoteConfig.adConfig.interstitialAdConfiguration;
5656
_transitionsBeforeShowingInterstitialAdsControllers = {
5757
for (final role in AppUserRole.values)
58-
role: TextEditingController(
59-
text: _getTransitionsBeforeInterstitial(
60-
interstitialConfig,
61-
role,
62-
).toString(),
63-
)..selection = TextSelection.collapsed(
64-
offset: _getTransitionsBeforeInterstitial(
65-
interstitialConfig,
66-
role,
67-
).toString().length,
68-
),
58+
role:
59+
TextEditingController(
60+
text: _getTransitionsBeforeInterstitial(
61+
interstitialConfig,
62+
role,
63+
).toString(),
64+
)
65+
..selection = TextSelection.collapsed(
66+
offset: _getTransitionsBeforeInterstitial(
67+
interstitialConfig,
68+
role,
69+
).toString().length,
70+
),
6971
};
7072
}
7173

@@ -85,8 +87,8 @@ class _InterstitialAdSettingsFormState extends State<InterstitialAdSettingsForm>
8587
newInterstitialValue;
8688
_transitionsBeforeShowingInterstitialAdsControllers[role]?.selection =
8789
TextSelection.collapsed(
88-
offset: newInterstitialValue.length,
89-
);
90+
offset: newInterstitialValue.length,
91+
);
9092
}
9193
}
9294
}
@@ -107,14 +109,17 @@ class _InterstitialAdSettingsFormState extends State<InterstitialAdSettingsForm>
107109
interstitialAdConfig.visibleTo[AppUserRole.premiumUser];
108110
if (premiumRoleConfig != null &&
109111
premiumRoleConfig.transitionsBeforeShowingInterstitialAds != 0) {
110-
final updatedVisibleTo = Map<AppUserRole, InterstitialAdFrequencyConfig>.from(
111-
interstitialAdConfig.visibleTo,
112-
)..[AppUserRole.premiumUser] = const InterstitialAdFrequencyConfig(
113-
transitionsBeforeShowingInterstitialAds: 0,
114-
);
112+
final updatedVisibleTo =
113+
Map<AppUserRole, InterstitialAdFrequencyConfig>.from(
114+
interstitialAdConfig.visibleTo,
115+
)
116+
..[AppUserRole.premiumUser] = const InterstitialAdFrequencyConfig(
117+
transitionsBeforeShowingInterstitialAds: 0,
118+
);
115119

116-
final updatedInterstitialAdConfig =
117-
interstitialAdConfig.copyWith(visibleTo: updatedVisibleTo);
120+
final updatedInterstitialAdConfig = interstitialAdConfig.copyWith(
121+
visibleTo: updatedVisibleTo,
122+
);
118123

119124
widget.onConfigChanged(
120125
widget.remoteConfig.copyWith(
@@ -244,16 +249,17 @@ class _InterstitialAdSettingsFormState extends State<InterstitialAdSettingsForm>
244249

245250
return Column(
246251
children: [
247-
CheckboxListTile(
248-
title: Text(l10n.visibleToRoleLabel(role.l10n(context))),
252+
SwitchListTile(
253+
// Changed from CheckboxListTile to SwitchListTile for consistency
254+
title: Text(l10n.enableInArticleAdsForRoleLabel(role.l10n(context))),
249255
value: roleConfig != null && isEnabled,
250256
onChanged: isEnabled
251257
? (value) {
252258
final newVisibleTo =
253259
Map<AppUserRole, InterstitialAdFrequencyConfig>.from(
254-
config.visibleTo,
255-
);
256-
if (value ?? false) {
260+
config.visibleTo,
261+
);
262+
if (value) {
257263
// Default value when enabling for a role
258264
newVisibleTo[role] = const InterstitialAdFrequencyConfig(
259265
transitionsBeforeShowingInterstitialAds: 5,
@@ -284,12 +290,13 @@ class _InterstitialAdSettingsFormState extends State<InterstitialAdSettingsForm>
284290
description: l10n.transitionsBeforeInterstitialAdsDescription,
285291
value: roleConfig.transitionsBeforeShowingInterstitialAds,
286292
onChanged: (value) {
287-
final newRoleConfig =
288-
roleConfig.copyWith(transitionsBeforeShowingInterstitialAds: value);
293+
final newRoleConfig = roleConfig.copyWith(
294+
transitionsBeforeShowingInterstitialAds: value,
295+
);
289296
final newVisibleTo =
290297
Map<AppUserRole, InterstitialAdFrequencyConfig>.from(
291-
config.visibleTo,
292-
)..[role] = newRoleConfig;
298+
config.visibleTo,
299+
)..[role] = newRoleConfig;
293300
widget.onConfigChanged(
294301
widget.remoteConfig.copyWith(
295302
adConfig: widget.remoteConfig.adConfig.copyWith(
@@ -300,7 +307,8 @@ class _InterstitialAdSettingsFormState extends State<InterstitialAdSettingsForm>
300307
),
301308
);
302309
},
303-
controller: _transitionsBeforeShowingInterstitialAdsControllers[role],
310+
controller:
311+
_transitionsBeforeShowingInterstitialAdsControllers[role],
304312
enabled: isEnabled,
305313
),
306314
),

0 commit comments

Comments
 (0)