Skip to content

Commit 56a41d0

Browse files
committed
refactor(router): remove redundant AccountBloc provider
- Remove BlocProvider.value(value: accountBloc) from multiple places in the router - This change removes unnecessary duplication of the AccountBloc provider - The AccountBloc should be provided higher up in the widget tree (e.g., in AppShell or App) - This refactor simplifies the router configuration and improves performance
1 parent 5edcb6e commit 56a41d0

File tree

1 file changed

+0
-17
lines changed

1 file changed

+0
-17
lines changed

lib/router/router.dart

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ import 'package:flutter_news_app_mobile_client_full_source_code/entity_details/v
2626
import 'package:flutter_news_app_mobile_client_full_source_code/headline-details/bloc/headline_details_bloc.dart';
2727
import 'package:flutter_news_app_mobile_client_full_source_code/headline-details/bloc/similar_headlines_bloc.dart';
2828
import 'package:flutter_news_app_mobile_client_full_source_code/headline-details/view/headline_details_page.dart';
29-
import 'package:flutter_news_app_mobile_client_full_source_code/headlines-feed/bloc/countries_filter_bloc.dart';
3029
import 'package:flutter_news_app_mobile_client_full_source_code/headlines-feed/bloc/headlines_feed_bloc.dart';
31-
import 'package:flutter_news_app_mobile_client_full_source_code/headlines-feed/bloc/sources_filter_bloc.dart';
32-
import 'package:flutter_news_app_mobile_client_full_source_code/headlines-feed/bloc/topics_filter_bloc.dart';
3330
import 'package:flutter_news_app_mobile_client_full_source_code/headlines-feed/view/country_filter_page.dart';
3431
import 'package:flutter_news_app_mobile_client_full_source_code/headlines-feed/view/headlines_feed_page.dart';
3532
import 'package:flutter_news_app_mobile_client_full_source_code/headlines-feed/view/headlines_filter_page.dart';
@@ -276,7 +273,6 @@ GoRouter createRouter({
276273
final adThemeStyle = AdThemeStyle.fromTheme(Theme.of(context));
277274
return MultiBlocProvider(
278275
providers: [
279-
BlocProvider.value(value: accountBloc),
280276
BlocProvider(
281277
create: (context) =>
282278
EntityDetailsBloc(
@@ -333,15 +329,8 @@ GoRouter createRouter({
333329
final headlineFromExtra = state.extra as Headline?;
334330
final headlineIdFromPath = state.pathParameters['id'];
335331

336-
// Ensure accountBloc is available if needed by HeadlineDetailsPage
337-
// or its descendants for actions like saving.
338-
// If AccountBloc is already provided higher up (e.g., in AppShell or App),
339-
// this specific BlocProvider.value might not be strictly necessary here,
340-
// but it's safer to ensure it's available for this top-level route.
341-
// We are using the `accountBloc` instance created at the top of `createRouter`.
342332
return MultiBlocProvider(
343333
providers: [
344-
BlocProvider.value(value: accountBloc),
345334
BlocProvider(
346335
create: (context) => HeadlineDetailsBloc(
347336
headlinesRepository: context.read<DataRepository<Headline>>(),
@@ -366,14 +355,11 @@ GoRouter createRouter({
366355
// Return the shell widget which contains the AdaptiveScaffold
367356
return MultiBlocProvider(
368357
providers: [
369-
BlocProvider.value(value: accountBloc),
370358
BlocProvider(
371359
create: (context) {
372360
return HeadlinesFeedBloc(
373361
headlinesRepository: context
374362
.read<DataRepository<Headline>>(),
375-
userContentPreferencesRepository: context
376-
.read<DataRepository<UserContentPreferences>>(),
377363
feedDecoratorService: feedDecoratorService,
378364
appBloc: context.read<AppBloc>(),
379365
inlineAdCacheService: inlineAdCacheService,
@@ -417,7 +403,6 @@ GoRouter createRouter({
417403

418404
return MultiBlocProvider(
419405
providers: [
420-
BlocProvider.value(value: accountBloc),
421406
BlocProvider(
422407
create: (context) => HeadlineDetailsBloc(
423408
headlinesRepository: context
@@ -513,7 +498,6 @@ GoRouter createRouter({
513498
final headlineIdFromPath = state.pathParameters['id'];
514499
return MultiBlocProvider(
515500
providers: [
516-
BlocProvider.value(value: accountBloc),
517501
BlocProvider(
518502
create: (context) => HeadlineDetailsBloc(
519503
headlinesRepository: context
@@ -695,7 +679,6 @@ GoRouter createRouter({
695679
final headlineIdFromPath = state.pathParameters['id'];
696680
return MultiBlocProvider(
697681
providers: [
698-
BlocProvider.value(value: accountBloc),
699682
BlocProvider(
700683
create: (context) => HeadlineDetailsBloc(
701684
headlinesRepository: context

0 commit comments

Comments
 (0)