Skip to content

Commit a47702e

Browse files
authored
Merge pull request #79 from flutter-news-app-full-source-code/fix-misc-ui-errors
Fix misc UI errors
2 parents b28774a + 33db75e commit a47702e

File tree

11 files changed

+103
-26
lines changed

11 files changed

+103
-26
lines changed

lib/entity_details/bloc/entity_details_bloc.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,10 @@ class EntityDetailsBloc extends Bloc<EntityDetailsEvent, EntityDetailsState> {
212212
feedItems: headlineResponse.items,
213213
user: currentUser,
214214
adConfig: remoteConfig.adConfig,
215-
currentFeedItemCount: state.feedItems.length,
215+
// Calculate the count of actual content items (headlines) already in the
216+
// feed. This is crucial for the FeedDecoratorService to correctly apply
217+
// ad placement rules across paginated loads.
218+
processedContentItemCount: state.feedItems.whereType<Headline>().length,
216219
);
217220

218221
emit(

lib/headlines-feed/bloc/headlines_feed_bloc.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ class HeadlinesFeedBloc extends Bloc<HeadlinesFeedEvent, HeadlinesFeedState> {
113113
feedItems: headlineResponse.items,
114114
user: currentUser,
115115
adConfig: remoteConfig.adConfig,
116-
currentFeedItemCount: state.feedItems.length,
116+
// Calculate the count of actual content items (headlines) already in the
117+
// feed. This is crucial for the FeedDecoratorService to correctly apply
118+
// ad placement rules across paginated loads.
119+
processedContentItemCount: state.feedItems.whereType<Headline>().length,
117120
);
118121

119122
emit(

lib/headlines-feed/view/headlines_feed_page.dart

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,20 @@ class _HeadlinesFeedPageState extends State<HeadlinesFeedPage> {
153153
),
154154
body: BlocBuilder<HeadlinesFeedBloc, HeadlinesFeedState>(
155155
builder: (context, state) {
156+
// Access the AppBloc to check for remoteConfig availability.
157+
final appBlocState = context.watch<AppBloc>().state;
158+
159+
// If remoteConfig is not yet loaded, show a loading indicator.
160+
// This handles the brief period after authentication but before
161+
// the remote config is fetched, preventing null access errors.
162+
if (appBlocState.remoteConfig == null) {
163+
return LoadingStateWidget(
164+
icon: Icons.settings_applications_outlined,
165+
headline: l10n.headlinesFeedLoadingHeadline,
166+
subheadline: l10n.pleaseWait,
167+
);
168+
}
169+
156170
if (state.status == HeadlinesFeedStatus.initial ||
157171
(state.status == HeadlinesFeedStatus.loading &&
158172
state.feedItems.isEmpty)) {
@@ -175,14 +189,24 @@ class _HeadlinesFeedPageState extends State<HeadlinesFeedPage> {
175189

176190
if (state.status == HeadlinesFeedStatus.success &&
177191
state.feedItems.isEmpty) {
178-
return FailureStateWidget(
179-
exception: const UnknownException(
180-
'No headlines found matching your criteria.',
181-
),
182-
onRetry: () => context.read<HeadlinesFeedBloc>().add(
183-
HeadlinesFeedFiltersCleared(),
192+
return Center(
193+
child: Column(
194+
mainAxisAlignment: MainAxisAlignment.center,
195+
children: [
196+
InitialStateWidget(
197+
icon: Icons.search_off,
198+
headline: l10n.headlinesFeedEmptyFilteredHeadline,
199+
subheadline: l10n.headlinesFeedEmptyFilteredSubheadline,
200+
),
201+
const SizedBox(height: AppSpacing.lg),
202+
ElevatedButton(
203+
onPressed: () => context.read<HeadlinesFeedBloc>().add(
204+
HeadlinesFeedFiltersCleared(),
205+
),
206+
child: Text(l10n.headlinesFeedClearFiltersButton),
207+
),
208+
],
184209
),
185-
retryButtonText: l10n.headlinesFeedClearFiltersButton,
186210
);
187211
}
188212

lib/headlines-search/bloc/headlines_search_bloc.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ class HeadlinesSearchBloc
112112
feedItems: headlines,
113113
user: currentUser,
114114
adConfig: appConfig.adConfig,
115-
currentFeedItemCount: successState.items.length,
115+
// Calculate the count of actual content items (headlines) already in the
116+
// feed. This is crucial for the FeedDecoratorService to correctly apply
117+
// ad placement rules across paginated loads.
118+
processedContentItemCount:
119+
successState.items.whereType<Headline>().length,
116120
);
117121
emit(
118122
successState.copyWith(

lib/headlines-search/view/headlines_search_page.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ class _HeadlinesSearchViewState extends State<_HeadlinesSearchView> {
187187
controller: _textController,
188188
style: appBarTheme.titleTextStyle ?? textTheme.titleMedium,
189189
decoration: InputDecoration(
190-
// TODO(fulleni): Create a similar localization extension for hint text.
191-
hintText: 'Search...',
190+
hintText: l10n.searchHintTextGeneric,
192191
hintStyle: textTheme.bodyMedium?.copyWith(
193192
color:
194193
(appBarTheme.titleTextStyle?.color ??

lib/l10n/app_localizations.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,12 @@ abstract class AppLocalizations {
998998
/// **'e.g., AI advancements, Mars rover...'**
999999
String get searchHintTextHeadline;
10001000

1001+
/// Generic hint text for search input fields
1002+
///
1003+
/// In en, this message translates to:
1004+
/// **'Search...'**
1005+
String get searchHintTextGeneric;
1006+
10011007
/// Hint text for searching categories
10021008
///
10031009
/// In en, this message translates to:

lib/l10n/app_localizations_ar.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,9 @@ class AppLocalizationsAr extends AppLocalizations {
487487
String get searchHintTextHeadline =>
488488
'مثال: تطورات الذكاء الاصطناعي, مركبة المريخ...';
489489

490+
@override
491+
String get searchHintTextGeneric => 'بحث...';
492+
490493
@override
491494
String get searchHintTextCategory => 'مثال: تكنولوجيا, رياضة, مالية...';
492495

lib/l10n/app_localizations_en.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,9 @@ class AppLocalizationsEn extends AppLocalizations {
488488
@override
489489
String get searchHintTextHeadline => 'e.g., AI advancements, Mars rover...';
490490

491+
@override
492+
String get searchHintTextGeneric => 'Search...';
493+
491494
@override
492495
String get searchHintTextCategory => 'e.g., Technology, Sports, Finance...';
493496

lib/l10n/arb/app_ar.arb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,10 @@
618618
"@searchHintTextHeadline": {
619619
"description": "Hint text for searching headlines"
620620
},
621+
"searchHintTextGeneric": "بحث...",
622+
"@searchHintTextGeneric": {
623+
"description": "Generic hint text for search input fields"
624+
},
621625
"searchHintTextCategory": "مثال: تكنولوجيا, رياضة, مالية...",
622626
"@searchHintTextCategory": {
623627
"description": "Hint text for searching categories"

lib/l10n/arb/app_en.arb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,10 @@
619619
"@searchHintTextHeadline": {
620620
"description": "Hint text for searching headlines"
621621
},
622+
"searchHintTextGeneric": "Search...",
623+
"@searchHintTextGeneric": {
624+
"description": "Generic hint text for search input fields"
625+
},
622626
"searchHintTextCategory": "e.g., Technology, Sports, Finance...",
623627
"@searchHintTextCategory": {
624628
"description": "Hint text for searching categories"

0 commit comments

Comments
 (0)