Skip to content

Commit 3c018b3

Browse files
committed
feat(app_configuration): add global ad switch and interstitial ad settings
- Add AdConfigForm for global ad configuration - Include InterstitialAdSettingsForm in the ad settings section - Disable expansion of ad platform configurations if global ads are off - Adjust the layout to accommodate the new global ad switch
1 parent c747966 commit 3c018b3

File tree

1 file changed

+57
-12
lines changed

1 file changed

+57
-12
lines changed

lib/app_configuration/view/tabs/advertisements_configuration_tab.dart

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import 'package:core/core.dart';
22
import 'package:flutter/material.dart';
3+
import 'package:flutter_news_app_web_dashboard_full_source_code/app_configuration/widgets/ad_config_form.dart';
34
import 'package:flutter_news_app_web_dashboard_full_source_code/app_configuration/widgets/ad_platform_config_form.dart';
45
import 'package:flutter_news_app_web_dashboard_full_source_code/app_configuration/widgets/article_ad_settings_form.dart';
56
import 'package:flutter_news_app_web_dashboard_full_source_code/app_configuration/widgets/feed_ad_settings_form.dart';
7+
import 'package:flutter_news_app_web_dashboard_full_source_code/app_configuration/widgets/interstitial_ad_settings_form.dart';
68
import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/l10n.dart';
79
import 'package:ui_kit/ui_kit.dart';
810

@@ -46,10 +48,17 @@ class _AdvertisementsConfigurationTabState
4648
@override
4749
Widget build(BuildContext context) {
4850
final l10n = AppLocalizationsX(context).l10n;
51+
final adConfig = widget.remoteConfig.adConfig;
4952

5053
return ListView(
5154
padding: const EdgeInsets.all(AppSpacing.lg),
5255
children: [
56+
// Global Ad Configuration (AdConfigForm now includes the global switch)
57+
AdConfigForm(
58+
remoteConfig: widget.remoteConfig,
59+
onConfigChanged: widget.onConfigChanged,
60+
),
61+
const SizedBox(height: AppSpacing.lg),
5362
// Top-level ExpansionTile for Ad Platform Configuration
5463
ValueListenableBuilder<int?>(
5564
valueListenable: _expandedTileIndex,
@@ -64,10 +73,12 @@ class _AdvertisementsConfigurationTabState
6473
bottom: AppSpacing.md,
6574
),
6675
expandedCrossAxisAlignment: CrossAxisAlignment.start,
67-
onExpansionChanged: (isExpanded) {
68-
_expandedTileIndex.value = isExpanded ? tileIndex : null;
69-
},
70-
initiallyExpanded: expandedIndex == tileIndex,
76+
onExpansionChanged: adConfig.enabled
77+
? (isExpanded) {
78+
_expandedTileIndex.value = isExpanded ? tileIndex : null;
79+
}
80+
: null, // Disable expansion if global ads are off
81+
initiallyExpanded: expandedIndex == tileIndex && adConfig.enabled,
7182
children: [
7283
AdPlatformConfigForm(
7384
remoteConfig: widget.remoteConfig,
@@ -92,10 +103,12 @@ class _AdvertisementsConfigurationTabState
92103
bottom: AppSpacing.md,
93104
),
94105
expandedCrossAxisAlignment: CrossAxisAlignment.start,
95-
onExpansionChanged: (isExpanded) {
96-
_expandedTileIndex.value = isExpanded ? tileIndex : null;
97-
},
98-
initiallyExpanded: expandedIndex == tileIndex,
106+
onExpansionChanged: adConfig.enabled
107+
? (isExpanded) {
108+
_expandedTileIndex.value = isExpanded ? tileIndex : null;
109+
}
110+
: null, // Disable expansion if global ads are off
111+
initiallyExpanded: expandedIndex == tileIndex && adConfig.enabled,
99112
children: [
100113
FeedAdSettingsForm(
101114
remoteConfig: widget.remoteConfig,
@@ -120,10 +133,12 @@ class _AdvertisementsConfigurationTabState
120133
bottom: AppSpacing.md,
121134
),
122135
expandedCrossAxisAlignment: CrossAxisAlignment.start,
123-
onExpansionChanged: (isExpanded) {
124-
_expandedTileIndex.value = isExpanded ? tileIndex : null;
125-
},
126-
initiallyExpanded: expandedIndex == tileIndex,
136+
onExpansionChanged: adConfig.enabled
137+
? (isExpanded) {
138+
_expandedTileIndex.value = isExpanded ? tileIndex : null;
139+
}
140+
: null, // Disable expansion if global ads are off
141+
initiallyExpanded: expandedIndex == tileIndex && adConfig.enabled,
127142
children: [
128143
ArticleAdSettingsForm(
129144
remoteConfig: widget.remoteConfig,
@@ -133,6 +148,36 @@ class _AdvertisementsConfigurationTabState
133148
);
134149
},
135150
),
151+
const SizedBox(height: AppSpacing.lg),
152+
// Top-level ExpansionTile for Interstitial Ad Settings
153+
ValueListenableBuilder<int?>(
154+
valueListenable: _expandedTileIndex,
155+
builder: (context, expandedIndex, child) {
156+
const tileIndex = 3;
157+
return ExpansionTile(
158+
key: ValueKey('interstitialAdSettingsTile_$expandedIndex'),
159+
title: Text(l10n.interstitialAdSettingsTitle),
160+
childrenPadding: const EdgeInsetsDirectional.only(
161+
start: AppSpacing.lg,
162+
top: AppSpacing.md,
163+
bottom: AppSpacing.md,
164+
),
165+
expandedCrossAxisAlignment: CrossAxisAlignment.start,
166+
onExpansionChanged: adConfig.enabled
167+
? (isExpanded) {
168+
_expandedTileIndex.value = isExpanded ? tileIndex : null;
169+
}
170+
: null, // Disable expansion if global ads are off
171+
initiallyExpanded: expandedIndex == tileIndex && adConfig.enabled,
172+
children: [
173+
InterstitialAdSettingsForm(
174+
remoteConfig: widget.remoteConfig,
175+
onConfigChanged: widget.onConfigChanged,
176+
),
177+
],
178+
);
179+
},
180+
),
136181
],
137182
);
138183
}

0 commit comments

Comments
 (0)