@@ -13,8 +13,17 @@ import 'package:flutter_news_app_mobile_client_full_source_code/shared/services/
1313part 'headlines_search_event.dart' ;
1414part 'headlines_search_state.dart' ;
1515
16+ /// {@template headlines_search_bloc}
17+ /// A BLoC that manages the state for the headlines search feature.
18+ ///
19+ /// This BLoC is responsible for fetching search results based on a query
20+ /// and selected content type, and for injecting ad placeholders into the
21+ /// headline results. It consumes global application state from [AppBloc]
22+ /// for user settings and remote configuration.
23+ /// {@endtemplate}
1624class HeadlinesSearchBloc
1725 extends Bloc <HeadlinesSearchEvent , HeadlinesSearchState > {
26+ /// {@macro headlines_search_bloc}
1827 HeadlinesSearchBloc ({
1928 required DataRepository <Headline > headlinesRepository,
2029 required DataRepository <Topic > topicRepository,
@@ -47,6 +56,10 @@ class HeadlinesSearchBloc
4756 final InlineAdCacheService _inlineAdCacheService;
4857 static const _limit = 10 ;
4958
59+ /// Handles changes to the selected model type for search.
60+ ///
61+ /// If there's an active search term, it re-triggers the search with the
62+ /// new model type.
5063 Future <void > _onHeadlinesSearchModelTypeChanged (
5164 HeadlinesSearchModelTypeChanged event,
5265 Emitter <HeadlinesSearchState > emit,
@@ -64,6 +77,11 @@ class HeadlinesSearchBloc
6477 emit (HeadlinesSearchInitial (selectedModelType: event.newModelType));
6578 }
6679
80+ /// Handles requests to fetch search results.
81+ ///
82+ /// This method performs the actual search operation based on the search term
83+ /// and selected model type. It also handles pagination and injects ad
84+ /// placeholders into headline results.
6785 Future <void > _onSearchFetchRequested (
6886 HeadlinesSearchFetchRequested event,
6987 Emitter <HeadlinesSearchState > emit,
@@ -125,7 +143,7 @@ class HeadlinesSearchBloc
125143 user: currentUser,
126144 adConfig: appConfig.adConfig,
127145 imageStyle:
128- _appBloc.state.settings.feedPreferences. headlineImageStyle,
146+ _appBloc.state.headlineImageStyle, // Use AppBloc getter
129147 adThemeStyle: event.adThemeStyle,
130148 // Calculate the count of actual content items (headlines) already in the
131149 // feed. This is crucial for the FeedDecoratorService to correctly apply
@@ -158,7 +176,6 @@ class HeadlinesSearchBloc
158176 cursor: response.cursor,
159177 ),
160178 );
161- // Added break
162179 case ContentType .source:
163180 response = await _sourceRepository.readAll (
164181 filter: {'q' : searchTerm},
@@ -245,7 +262,7 @@ class HeadlinesSearchBloc
245262 user: currentUser,
246263 adConfig: appConfig.adConfig,
247264 imageStyle:
248- _appBloc.state.settings.feedPreferences. headlineImageStyle,
265+ _appBloc.state.headlineImageStyle, // Use AppBloc getter
249266 adThemeStyle: event.adThemeStyle,
250267 );
251268 case ContentType .topic:
0 commit comments