Skip to content

Commit 5acba58

Browse files
committed
refactor(app_configuration): remove unnecessary AbsorbPointer and Opacity widgets
- Removed AbsorbPointer and Opacity widgets that were used to disable the form - Simplified the layout by directly returning a Column widget - This change improves the code structure and may enhance performance slightly
1 parent e5446ca commit 5acba58

File tree

1 file changed

+86
-93
lines changed

1 file changed

+86
-93
lines changed

lib/app_configuration/widgets/article_ad_settings_form.dart

Lines changed: 86 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -43,107 +43,102 @@ class _ArticleAdSettingsFormState extends State<ArticleAdSettingsForm>
4343
final adConfig = widget.remoteConfig.adConfig;
4444
final articleAdConfig = adConfig.articleAdConfiguration;
4545

46-
return AbsorbPointer(
47-
absorbing: !adConfig.enabled,
48-
child: Opacity(
49-
opacity: adConfig.enabled ? 1.0 : 0.5,
50-
child: Column(
51-
crossAxisAlignment: CrossAxisAlignment.start,
52-
children: [
53-
SwitchListTile(
54-
title: Text(l10n.enableArticleAdsLabel),
55-
value: articleAdConfig.enabled,
56-
onChanged: (value) {
57-
widget.onConfigChanged(
58-
widget.remoteConfig.copyWith(
59-
adConfig: adConfig.copyWith(
60-
articleAdConfiguration: articleAdConfig.copyWith(
46+
return Column(
47+
crossAxisAlignment: CrossAxisAlignment.start,
48+
children: [
49+
SwitchListTile(
50+
title: Text(l10n.enableArticleAdsLabel),
51+
value: articleAdConfig.enabled,
52+
onChanged: (value) {
53+
widget.onConfigChanged(
54+
widget.remoteConfig.copyWith(
55+
adConfig: adConfig.copyWith(
56+
articleAdConfiguration: articleAdConfig.copyWith(
6157
enabled: value,
6258
),
63-
),
64-
),
65-
);
66-
},
67-
),
68-
const SizedBox(height: AppSpacing.lg),
69-
ExpansionTile(
70-
title: Text(l10n.defaultInArticleAdTypeSelectionTitle),
71-
childrenPadding: const EdgeInsetsDirectional.only(
72-
start: AppSpacing.lg, // Adjusted padding for hierarchy
73-
top: AppSpacing.md,
74-
bottom: AppSpacing.md,
59+
),
7560
),
76-
expandedCrossAxisAlignment:
77-
CrossAxisAlignment.start, // Align content to start
78-
children: [
79-
Text(
80-
l10n.defaultInArticleAdTypeSelectionDescription,
81-
style: Theme.of(context).textTheme.bodySmall?.copyWith(
82-
color: Theme.of(
61+
);
62+
},
63+
),
64+
const SizedBox(height: AppSpacing.lg),
65+
ExpansionTile(
66+
title: Text(l10n.defaultInArticleAdTypeSelectionTitle),
67+
childrenPadding: const EdgeInsetsDirectional.only(
68+
start: AppSpacing.lg, // Adjusted padding for hierarchy
69+
top: AppSpacing.md,
70+
bottom: AppSpacing.md,
71+
),
72+
expandedCrossAxisAlignment:
73+
CrossAxisAlignment.start, // Align content to start
74+
children: [
75+
Text(
76+
l10n.defaultInArticleAdTypeSelectionDescription,
77+
style: Theme.of(context).textTheme.bodySmall?.copyWith(
78+
color: Theme.of(
8379
context,
8480
).colorScheme.onSurface.withOpacity(0.7),
81+
),
82+
textAlign: TextAlign.start, // Ensure text aligns to start
83+
),
84+
const SizedBox(height: AppSpacing.lg),
85+
Align(
86+
alignment: AlignmentDirectional.centerStart,
87+
child: SegmentedButton<AdType>(
88+
style: SegmentedButton.styleFrom(
89+
shape: const RoundedRectangleBorder(
90+
borderRadius: BorderRadius.zero,
8591
),
86-
textAlign: TextAlign.start, // Ensure text aligns to start
8792
),
88-
const SizedBox(height: AppSpacing.lg),
89-
Align(
90-
alignment: AlignmentDirectional.centerStart,
91-
child: SegmentedButton<AdType>(
92-
style: SegmentedButton.styleFrom(
93-
shape: const RoundedRectangleBorder(
94-
borderRadius: BorderRadius.zero,
93+
segments: AdType.values
94+
.where(
95+
(type) => type == AdType.native || type == AdType.banner,
96+
)
97+
.map(
98+
(type) => ButtonSegment<AdType>(
99+
value: type,
100+
label: Text(type.name),
95101
),
96-
),
97-
segments: AdType.values
98-
.where(
99-
(type) =>
100-
type == AdType.native || type == AdType.banner,
101-
)
102-
.map(
103-
(type) => ButtonSegment<AdType>(
104-
value: type,
105-
label: Text(type.name),
106-
),
107-
)
108-
.toList(),
109-
selected: {articleAdConfig.defaultInArticleAdType},
110-
onSelectionChanged: (newSelection) {
111-
widget.onConfigChanged(
112-
widget.remoteConfig.copyWith(
113-
adConfig: adConfig.copyWith(
114-
articleAdConfiguration: articleAdConfig.copyWith(
102+
)
103+
.toList(),
104+
selected: {articleAdConfig.defaultInArticleAdType},
105+
onSelectionChanged: (newSelection) {
106+
widget.onConfigChanged(
107+
widget.remoteConfig.copyWith(
108+
adConfig: adConfig.copyWith(
109+
articleAdConfiguration: articleAdConfig.copyWith(
115110
defaultInArticleAdType: newSelection.first,
116111
),
117-
),
118-
),
119-
);
120-
},
121-
),
122-
),
123-
],
124-
),
125-
const SizedBox(height: AppSpacing.lg),
126-
ExpansionTile(
127-
title: Text(l10n.inArticleAdSlotPlacementsTitle),
128-
childrenPadding: const EdgeInsetsDirectional.only(
129-
start: AppSpacing.lg, // Adjusted padding for hierarchy
130-
top: AppSpacing.md,
131-
bottom: AppSpacing.md,
112+
),
113+
),
114+
);
115+
},
132116
),
133-
expandedCrossAxisAlignment:
134-
CrossAxisAlignment.start, // Align content to start
135-
children: [
136-
Text(
137-
l10n.inArticleAdSlotPlacementsDescription,
138-
style: Theme.of(context).textTheme.bodySmall?.copyWith(
139-
color: Theme.of(
117+
),
118+
],
119+
),
120+
const SizedBox(height: AppSpacing.lg),
121+
ExpansionTile(
122+
title: Text(l10n.inArticleAdSlotPlacementsTitle),
123+
childrenPadding: const EdgeInsetsDirectional.only(
124+
start: AppSpacing.lg, // Adjusted padding for hierarchy
125+
top: AppSpacing.md,
126+
bottom: AppSpacing.md,
127+
),
128+
expandedCrossAxisAlignment:
129+
CrossAxisAlignment.start, // Align content to start
130+
children: [
131+
Text(
132+
l10n.inArticleAdSlotPlacementsDescription,
133+
style: Theme.of(context).textTheme.bodySmall?.copyWith(
134+
color: Theme.of(
140135
context,
141136
).colorScheme.onSurface.withOpacity(0.7),
142-
),
143-
textAlign: TextAlign.start, // Ensure text aligns to start
144-
),
145-
const SizedBox(height: AppSpacing.lg),
146-
...articleAdConfig.inArticleAdSlotConfigurations.map(
137+
),
138+
textAlign: TextAlign.start, // Ensure text aligns to start
139+
),
140+
const SizedBox(height: AppSpacing.lg),
141+
...articleAdConfig.inArticleAdSlotConfigurations.map(
147142
(slotConfig) => SwitchListTile(
148143
title: Text(slotConfig.slotType.l10n(context)),
149144
value: slotConfig.enabled,
@@ -160,19 +155,17 @@ class _ArticleAdSettingsFormState extends State<ArticleAdSettingsForm>
160155
widget.remoteConfig.copyWith(
161156
adConfig: adConfig.copyWith(
162157
articleAdConfiguration: articleAdConfig.copyWith(
163-
inArticleAdSlotConfigurations: updatedSlots,
164-
),
158+
inArticleAdSlotConfigurations: updatedSlots,
159+
),
165160
),
166161
),
167162
);
168163
},
169164
),
170165
),
171-
],
172-
),
173166
],
174167
),
175-
),
168+
],
176169
);
177170
}
178171
}

0 commit comments

Comments
 (0)