Skip to content

Commit 8d57c7d

Browse files
committed
fix(headlines-feed): prevent remote config null access on feed page
- Add a check for remoteConfig availability in AppBloc - Display a loading indicator while remoteConfig is null - This fix addresses a null access error that occurs after authentication and before remote config is fetched
1 parent e7f8e43 commit 8d57c7d

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

lib/headlines-feed/view/headlines_feed_page.dart

Lines changed: 16 additions & 2 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)) {
@@ -187,8 +201,8 @@ class _HeadlinesFeedPageState extends State<HeadlinesFeedPage> {
187201
const SizedBox(height: AppSpacing.lg),
188202
ElevatedButton(
189203
onPressed: () => context.read<HeadlinesFeedBloc>().add(
190-
HeadlinesFeedFiltersCleared(),
191-
),
204+
HeadlinesFeedFiltersCleared(),
205+
),
192206
child: Text(l10n.headlinesFeedClearFiltersButton),
193207
),
194208
],

0 commit comments

Comments
 (0)