@@ -18,7 +18,14 @@ import 'package:ui_kit/ui_kit.dart';
1818/// {@endtemplate}
1919class CountryFilterPage extends StatefulWidget {
2020 /// {@macro country_filter_page}
21- const CountryFilterPage ({super .key});
21+ const CountryFilterPage ({required this .title, this .usage, super .key});
22+
23+ /// The title to display in the app bar for this filter page.
24+ final String title;
25+
26+ /// The usage context for filtering countries (e.g., 'eventCountry', 'headquarters').
27+ /// If null, fetches all countries (though this is not the primary use case for this page).
28+ final String ? usage;
2229
2330 @override
2431 State <CountryFilterPage > createState () => _CountryFilterPageState ();
@@ -27,7 +34,7 @@ class CountryFilterPage extends StatefulWidget {
2734/// State for the [CountryFilterPage] .
2835///
2936/// Manages the local selection state ([_pageSelectedCountries] ) and interacts
30- /// with [CountriesFilterBloc] for data fetching and pagination .
37+ /// with [CountriesFilterBloc] for data fetching.
3138class _CountryFilterPageState extends State <CountryFilterPage > {
3239 /// Stores the countries selected by the user *on this specific page*.
3340 /// This state is local to the `CountryFilterPage` lifecycle.
@@ -37,10 +44,6 @@ class _CountryFilterPageState extends State<CountryFilterPage> {
3744 /// from the main filter page when this page loads.
3845 late Set <Country > _pageSelectedCountries;
3946
40- /// Scroll controller to detect when the user reaches the end of the list
41- /// for pagination.
42- final _scrollController = ScrollController ();
43-
4447 @override
4548 void initState () {
4649 super .initState ();
@@ -61,39 +64,18 @@ class _CountryFilterPageState extends State<CountryFilterPage> {
6164
6265 // 3. Trigger the page-specific BLoC (CountriesFilterBloc) to start
6366 // fetching the list of *all available* countries that the user can
64- // potentially select from. The BLoC handles fetching, pagination,
65- // loading states, and errors for the *list of options*.
66- context.read <CountriesFilterBloc >().add (CountriesFilterRequested ());
67+ // potentially select from, using the specified usage filter.
68+ context.read <CountriesFilterBloc >().add (
69+ CountriesFilterRequested (usage: widget.usage),
70+ );
6771 });
68- // Add listener for pagination logic.
69- _scrollController.addListener (_onScroll);
7072 }
7173
7274 @override
7375 void dispose () {
74- _scrollController
75- ..removeListener (_onScroll)
76- ..dispose ();
7776 super .dispose ();
7877 }
7978
80- /// Callback function for scroll events.
81- ///
82- /// Checks if the user has scrolled near the bottom of the list and triggers
83- /// fetching more countries via the BLoC if available.
84- void _onScroll () {
85- if (! _scrollController.hasClients) return ;
86- final maxScroll = _scrollController.position.maxScrollExtent;
87- final currentScroll = _scrollController.offset;
88- final bloc = context.read <CountriesFilterBloc >();
89- // Fetch more when nearing the bottom, if BLoC has more and isn't already loading more
90- if (currentScroll >= (maxScroll * 0.9 ) &&
91- bloc.state.hasMore &&
92- bloc.state.status != CountriesFilterStatus .loadingMore) {
93- bloc.add (CountriesFilterLoadMoreRequested ());
94- }
95- }
96-
9779 @override
9880 Widget build (BuildContext context) {
9981 final l10n = AppLocalizationsX (context).l10n;
@@ -103,7 +85,7 @@ class _CountryFilterPageState extends State<CountryFilterPage> {
10385 return Scaffold (
10486 appBar: AppBar (
10587 title: Text (
106- l10n.headlinesFeedFilterEventCountryLabel,
88+ widget.title, // Use the dynamic title
10789 style: textTheme.titleLarge,
10890 ),
10991 actions: [
@@ -148,8 +130,9 @@ class _CountryFilterPageState extends State<CountryFilterPage> {
148130 state.countries.isEmpty) {
149131 return FailureStateWidget (
150132 exception: state.error ?? const UnknownException ('Unknown error' ),
151- onRetry: () =>
152- context.read <CountriesFilterBloc >().add (CountriesFilterRequested ()),
133+ onRetry: () => context.read <CountriesFilterBloc >().add (
134+ CountriesFilterRequested (usage: widget.usage),
135+ ),
153136 );
154137 }
155138
@@ -163,45 +146,13 @@ class _CountryFilterPageState extends State<CountryFilterPage> {
163146 );
164147 }
165148
166- // Handle loaded state (success or loading more )
149+ // Handle loaded state (success)
167150 return ListView .builder (
168- controller: _scrollController,
169151 padding: const EdgeInsets .symmetric (
170152 vertical: AppSpacing .paddingSmall,
171153 ).copyWith (bottom: AppSpacing .xxl),
172- itemCount:
173- state.countries.length +
174- ((state.status == CountriesFilterStatus .loadingMore ||
175- (state.status == CountriesFilterStatus .failure &&
176- state.countries.isNotEmpty))
177- ? 1
178- : 0 ),
154+ itemCount: state.countries.length,
179155 itemBuilder: (context, index) {
180- if (index >= state.countries.length) {
181- if (state.status == CountriesFilterStatus .loadingMore) {
182- return const Padding (
183- padding: EdgeInsets .symmetric (vertical: AppSpacing .lg),
184- child: Center (child: CircularProgressIndicator ()),
185- );
186- } else if (state.status == CountriesFilterStatus .failure) {
187- return Padding (
188- padding: const EdgeInsets .symmetric (
189- vertical: AppSpacing .md,
190- horizontal: AppSpacing .lg,
191- ),
192- child: Center (
193- child: Text (
194- l10n.loadMoreError,
195- style: textTheme.bodySmall? .copyWith (
196- color: colorScheme.error,
197- ),
198- ),
199- ),
200- );
201- }
202- return const SizedBox .shrink ();
203- }
204-
205156 final country = state.countries[index];
206157 final isSelected = _pageSelectedCountries.contains (country);
207158
0 commit comments