Skip to content

Commit 21e54cc

Browse files
committed
fix: resolved the ProviderNotFoundException The HeadlinesFeedBloc instance is being passed from the HeadlinesFeedPage to the HeadlinesFilterPage using go_router's extra parameter, and the HeadlinesFilterPage has been updated to receive the BLoC instance via its constructor. The router has also been updated to pass the BLoC instance to the HeadlinesFilterPage.
1 parent 006e02a commit 21e54cc

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

lib/headlines-feed/view/headlines_feed_page.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,11 @@ class _HeadlinesFeedViewState extends State<_HeadlinesFeedView> {
142142
tooltip: l10n.headlinesFeedFilterTooltip,
143143
onPressed: () {
144144
// Navigate to the filter page route
145-
context.goNamed(Routes.feedFilterName);
145+
final headlinesFeedBloc = context.read<HeadlinesFeedBloc>();
146+
context.goNamed(
147+
Routes.feedFilterName,
148+
extra: headlinesFeedBloc,
149+
);
146150
},
147151
),
148152
if (isFilterApplied)

lib/headlines-feed/view/headlines_filter_page.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import 'package:ht_sources_client/ht_sources_client.dart';
2121
/// {@endtemplate}
2222
class HeadlinesFilterPage extends StatefulWidget {
2323
/// {@macro headlines_filter_page}
24-
const HeadlinesFilterPage({super.key});
24+
const HeadlinesFilterPage({required this.headlinesFeedBloc, super.key});
25+
26+
final HeadlinesFeedBloc headlinesFeedBloc;
2527

2628
@override
2729
State<HeadlinesFilterPage> createState() => _HeadlinesFilterPageState();
@@ -37,7 +39,7 @@ class _HeadlinesFilterPageState extends State<HeadlinesFilterPage> {
3739
void initState() {
3840
super.initState();
3941
// Initialize temporary state from the currently active filters in the BLoC
40-
final currentState = context.read<HeadlinesFeedBloc>().state;
42+
final currentState = widget.headlinesFeedBloc.state;
4143
if (currentState is HeadlinesFeedLoaded) {
4244
_tempSelectedCategories = List.from(currentState.filter.categories ?? []);
4345
_tempSelectedSources = List.from(currentState.filter.sources ?? []);

lib/router/router.dart

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:ht_main/authentication/view/authentication_page.dart';
1111
import 'package:ht_main/authentication/view/email_link_sent_page.dart';
1212
import 'package:ht_main/authentication/view/email_sign_in_page.dart';
1313
import 'package:ht_main/headline-details/view/headline_details_page.dart';
14+
import 'package:ht_main/headlines-feed/bloc/headlines_feed_bloc.dart';
1415
import 'package:ht_main/headlines-feed/view/category_filter_page.dart'; // Import new page
1516
import 'package:ht_main/headlines-feed/view/country_filter_page.dart'; // Import new page
1617
import 'package:ht_main/headlines-feed/view/headlines_feed_page.dart';
@@ -284,12 +285,15 @@ GoRouter createRouter({required ValueNotifier<AppStatus> authStatusNotifier}) {
284285
path: Routes.feedFilter, // Relative path: 'filter'
285286
name: Routes.feedFilterName,
286287
// Use MaterialPage with fullscreenDialog for modal presentation
287-
pageBuilder:
288-
(context, state) => const MaterialPage(
289-
fullscreenDialog: true,
290-
child:
291-
HeadlinesFilterPage(), // Main filter selection page
292-
),
288+
pageBuilder: (context, state) {
289+
final headlinesFeedBloc = state.extra as HeadlinesFeedBloc;
290+
return MaterialPage(
291+
fullscreenDialog: true,
292+
child: HeadlinesFilterPage(
293+
headlinesFeedBloc: headlinesFeedBloc,
294+
), // Main filter selection page
295+
);
296+
},
293297
routes: [
294298
// Sub-route for category selection
295299
GoRoute(

0 commit comments

Comments
 (0)