Skip to content

Commit 6e993e2

Browse files
committed
refactor(filter): update HeadlinesFilterPage to pass savedFilter on apply
Updates `HeadlinesFilterPage` to pass the optional `SavedFilter` object when dispatching the `HeadlinesFeedFiltersApplied` event. This change is part of a fix for a race condition where a newly saved filter was not being selected. By passing the `newFilter` object directly during the "save and apply" flow, the `HeadlinesFeedBloc` can deterministically identify it without relying on the comparison logic. The `null` value is passed for "apply only" actions to signify a custom filter.
1 parent 6c92d79 commit 6e993e2

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/headlines-feed/view/headlines_filter_page.dart

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ class _HeadlinesFilterViewState extends State<_HeadlinesFilterView> {
114114
onPressed: () {
115115
// Pop the dialog first.
116116
Navigator.of(dialogContext).pop();
117-
// Apply the filter without saving it.
118-
_applyAndExit();
117+
// Apply the filter as a "custom" one-time filter.
118+
_applyAndExit(null);
119119
},
120120
),
121121
FilledButton(
@@ -164,7 +164,7 @@ class _HeadlinesFilterViewState extends State<_HeadlinesFilterView> {
164164
// Apply the newly saved filter to the HeadlinesFeedBloc. The page
165165
// is not popped here; that action is deferred until after the
166166
// dialog has been successfully dismissed.
167-
_applyFilter();
167+
_applyFilter(newFilter);
168168
},
169169
);
170170
},
@@ -180,7 +180,11 @@ class _HeadlinesFilterViewState extends State<_HeadlinesFilterView> {
180180
}
181181

182182
/// Applies the current filter selections to the feed and pops the page.
183-
void _applyFilter() {
183+
///
184+
/// If a [savedFilter] is provided, it's passed to the event to ensure
185+
/// its chip is correctly selected on the feed. Otherwise, the filter is
186+
/// treated as a "custom" one.
187+
void _applyFilter(SavedFilter? savedFilter) {
184188
final filterState = context.read<HeadlinesFilterBloc>().state;
185189
// Create a new HeadlineFilter from the current selections in the filter bloc.
186190
final newFilter = HeadlineFilter(
@@ -191,15 +195,16 @@ class _HeadlinesFilterViewState extends State<_HeadlinesFilterView> {
191195
context.read<HeadlinesFeedBloc>().add(
192196
HeadlinesFeedFiltersApplied(
193197
filter: newFilter,
198+
savedFilter: savedFilter,
194199
adThemeStyle: AdThemeStyle.fromTheme(Theme.of(context)),
195200
),
196201
);
197202
}
198203

199-
void _applyAndExit() {
204+
void _applyAndExit(SavedFilter? savedFilter) {
200205
// This helper method now separates applying the filter from exiting.
201206
// It's called for the "Apply Only" flow.
202-
_applyFilter();
207+
_applyFilter(savedFilter);
203208
context.pop();
204209
}
205210

0 commit comments

Comments
 (0)