Skip to content

Commit 1dcf278

Browse files
committed
refactor(headlines-feed): introduce CountryFilterUsage enum for clarity
- Replace String usage parameter with strongly-typed CountryFilterUsage enum - Improve code readability and maintainability by using enum for specific filter cases - Update related bloc events and logic to use the new enum
1 parent be39f87 commit 1dcf278

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/headlines-feed/view/country_filter_page.dart

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ import 'package:flutter_news_app_mobile_client_full_source_code/l10n/l10n.dart';
66
import 'package:go_router/go_router.dart';
77
import 'package:ui_kit/ui_kit.dart';
88

9+
enum CountryFilterUsage {
10+
// countries with active sources
11+
hasActiveSources,
12+
13+
// countries with active headlines
14+
hasActiveHeadlines,
15+
}
16+
917
/// {@template country_filter_page}
1018
/// A page dedicated to selecting event countries for filtering headlines.
1119
///
@@ -15,14 +23,14 @@ import 'package:ui_kit/ui_kit.dart';
1523
/// {@endtemplate}
1624
class CountryFilterPage extends StatefulWidget {
1725
/// {@macro country_filter_page}
18-
const CountryFilterPage({required this.title, this.usage, super.key});
26+
const CountryFilterPage({required this.title, this.filter, super.key});
1927

2028
/// The title to display in the app bar for this filter page.
2129
final String title;
2230

23-
/// The usage context for filtering countries (e.g., 'eventCountry', 'headquarters').
31+
/// The usage context for filtering countries (e.g., 'hasActiveSources', 'hasActiveHeadlines').
2432
/// If null, fetches all countries (though this is not the primary use case for this page).
25-
final String? usage;
33+
final CountryFilterUsage? filter;
2634

2735
@override
2836
State<CountryFilterPage> createState() => _CountryFilterPageState();
@@ -65,7 +73,7 @@ class _CountryFilterPageState extends State<CountryFilterPage> {
6573
// 3. Trigger the page-specific BLoC (CountriesFilterBloc) to start
6674
// fetching the list of *all available* countries that the user can
6775
// potentially select from, using the specified usage filter.
68-
_countriesFilterBloc.add(CountriesFilterRequested(usage: widget.usage));
76+
_countriesFilterBloc.add(CountriesFilterRequested(usage: widget.filter));
6977
});
7078
}
7179

@@ -193,7 +201,7 @@ class _CountryFilterPageState extends State<CountryFilterPage> {
193201
exception:
194202
state.error ?? const UnknownException('Unknown error'),
195203
onRetry: () => _countriesFilterBloc.add(
196-
CountriesFilterRequested(usage: widget.usage),
204+
CountriesFilterRequested(usage: widget.filter),
197205
),
198206
);
199207
}

0 commit comments

Comments
 (0)