Skip to content

Commit 320452c

Browse files
authored
Merge pull request #75 from flutter-news-app-full-source-code/Adapt-ad-config-ui-to-the-remote-config-updated-object
Adapt ad config UI to the remote config updated object
2 parents df7ecb9 + 56296bd commit 320452c

29 files changed

+627
-617
lines changed

lib/app_configuration/view/tabs/advertisements_configuration_tab.dart

Lines changed: 61 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,13 @@ 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,
81+
initiallyExpanded: expandedIndex == tileIndex && adConfig.enabled,
82+
enabled: adConfig.enabled, // Disable the tile itself
7183
children: [
7284
AdPlatformConfigForm(
7385
remoteConfig: widget.remoteConfig,
@@ -92,10 +104,13 @@ class _AdvertisementsConfigurationTabState
92104
bottom: AppSpacing.md,
93105
),
94106
expandedCrossAxisAlignment: CrossAxisAlignment.start,
95-
onExpansionChanged: (isExpanded) {
96-
_expandedTileIndex.value = isExpanded ? tileIndex : null;
97-
},
98-
initiallyExpanded: expandedIndex == tileIndex,
107+
onExpansionChanged: adConfig.enabled
108+
? (isExpanded) {
109+
_expandedTileIndex.value = isExpanded ? tileIndex : null;
110+
}
111+
: null,
112+
initiallyExpanded: expandedIndex == tileIndex && adConfig.enabled,
113+
enabled: adConfig.enabled, // Disable the tile itself
99114
children: [
100115
FeedAdSettingsForm(
101116
remoteConfig: widget.remoteConfig,
@@ -120,10 +135,13 @@ class _AdvertisementsConfigurationTabState
120135
bottom: AppSpacing.md,
121136
),
122137
expandedCrossAxisAlignment: CrossAxisAlignment.start,
123-
onExpansionChanged: (isExpanded) {
124-
_expandedTileIndex.value = isExpanded ? tileIndex : null;
125-
},
126-
initiallyExpanded: expandedIndex == tileIndex,
138+
onExpansionChanged: adConfig.enabled
139+
? (isExpanded) {
140+
_expandedTileIndex.value = isExpanded ? tileIndex : null;
141+
}
142+
: null,
143+
initiallyExpanded: expandedIndex == tileIndex && adConfig.enabled,
144+
enabled: adConfig.enabled, // Disable the tile itself
127145
children: [
128146
ArticleAdSettingsForm(
129147
remoteConfig: widget.remoteConfig,
@@ -133,6 +151,37 @@ class _AdvertisementsConfigurationTabState
133151
);
134152
},
135153
),
154+
const SizedBox(height: AppSpacing.lg),
155+
// Top-level ExpansionTile for Interstitial Ad Settings
156+
ValueListenableBuilder<int?>(
157+
valueListenable: _expandedTileIndex,
158+
builder: (context, expandedIndex, child) {
159+
const tileIndex = 3;
160+
return ExpansionTile(
161+
key: ValueKey('interstitialAdSettingsTile_$expandedIndex'),
162+
title: Text(l10n.interstitialAdSettingsTitle),
163+
childrenPadding: const EdgeInsetsDirectional.only(
164+
start: AppSpacing.lg,
165+
top: AppSpacing.md,
166+
bottom: AppSpacing.md,
167+
),
168+
expandedCrossAxisAlignment: CrossAxisAlignment.start,
169+
onExpansionChanged: adConfig.enabled
170+
? (isExpanded) {
171+
_expandedTileIndex.value = isExpanded ? tileIndex : null;
172+
}
173+
: null,
174+
initiallyExpanded: expandedIndex == tileIndex && adConfig.enabled,
175+
enabled: adConfig.enabled, // Disable the tile itself
176+
children: [
177+
InterstitialAdSettingsForm(
178+
remoteConfig: widget.remoteConfig,
179+
onConfigChanged: widget.onConfigChanged,
180+
),
181+
],
182+
);
183+
},
184+
),
136185
],
137186
);
138187
}

0 commit comments

Comments
 (0)