Skip to content

Commit 5df7288

Browse files
authored
Merge pull request #100 from flutter-news-app-full-source-code/centralize-the-creation-and-provision-of-EntityDetailsBloc
Centralize the creation and provision of entity details bloc
2 parents 2046c08 + b894630 commit 5df7288

File tree

14 files changed

+152
-218
lines changed

14 files changed

+152
-218
lines changed

lib/account/view/manage_followed_items/countries/followed_countries_list_page.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'package:core/core.dart';
22
import 'package:flutter/material.dart';
33
import 'package:flutter_bloc/flutter_bloc.dart';
44
import 'package:flutter_news_app_mobile_client_full_source_code/account/bloc/account_bloc.dart';
5-
import 'package:flutter_news_app_mobile_client_full_source_code/entity_details/view/entity_details_page.dart';
65
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/l10n.dart';
76
import 'package:flutter_news_app_mobile_client_full_source_code/router/routes.dart';
87
import 'package:go_router/go_router.dart';
@@ -97,12 +96,12 @@ class FollowedCountriesListPage extends StatelessWidget {
9796
},
9897
),
9998
onTap: () {
100-
context.push(
101-
Routes.countryDetails,
102-
extra: EntityDetailsPageArguments(
103-
entityId: country.id,
104-
contentType: ContentType.country,
105-
),
99+
context.pushNamed(
100+
Routes.entityDetailsName,
101+
pathParameters: {
102+
'type': ContentType.country.name, // 'topic'
103+
'id': country.id,
104+
},
106105
);
107106
},
108107
);

lib/account/view/manage_followed_items/sources/followed_sources_list_page.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'package:core/core.dart';
22
import 'package:flutter/material.dart';
33
import 'package:flutter_bloc/flutter_bloc.dart';
44
import 'package:flutter_news_app_mobile_client_full_source_code/account/bloc/account_bloc.dart';
5-
import 'package:flutter_news_app_mobile_client_full_source_code/entity_details/view/entity_details_page.dart';
65
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/l10n.dart';
76
import 'package:flutter_news_app_mobile_client_full_source_code/router/routes.dart';
87
import 'package:go_router/go_router.dart';
@@ -94,12 +93,12 @@ class FollowedSourcesListPage extends StatelessWidget {
9493
},
9594
),
9695
onTap: () {
97-
context.push(
98-
Routes.sourceDetails,
99-
extra: EntityDetailsPageArguments(
100-
entityId: source.id,
101-
contentType: ContentType.source,
102-
),
96+
context.pushNamed(
97+
Routes.entityDetailsName,
98+
pathParameters: {
99+
'type': ContentType.source.name,
100+
'id': source.id,
101+
},
103102
);
104103
},
105104
);

lib/account/view/manage_followed_items/topics/followed_topics_list_page.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'package:core/core.dart';
22
import 'package:flutter/material.dart';
33
import 'package:flutter_bloc/flutter_bloc.dart';
44
import 'package:flutter_news_app_mobile_client_full_source_code/account/bloc/account_bloc.dart';
5-
import 'package:flutter_news_app_mobile_client_full_source_code/entity_details/view/entity_details_page.dart';
65
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/l10n.dart';
76
import 'package:flutter_news_app_mobile_client_full_source_code/router/routes.dart';
87
import 'package:go_router/go_router.dart';
@@ -102,12 +101,12 @@ class FollowedTopicsListPage extends StatelessWidget {
102101
},
103102
),
104103
onTap: () {
105-
context.push(
106-
Routes.topicDetails,
107-
extra: EntityDetailsPageArguments(
108-
entityId: topic.id,
109-
contentType: ContentType.topic,
110-
),
104+
context.pushNamed(
105+
Routes.entityDetailsName,
106+
pathParameters: {
107+
'type': ContentType.topic.name,
108+
'id': topic.id,
109+
},
111110
);
112111
},
113112
);

lib/entity_details/view/entity_details_page.dart

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
// ignore_for_file: no_default_cases
22

33
import 'package:core/core.dart';
4-
import 'package:data_repository/data_repository.dart';
54
import 'package:flutter/material.dart';
65
import 'package:flutter_bloc/flutter_bloc.dart';
7-
import 'package:flutter_news_app_mobile_client_full_source_code/account/bloc/account_bloc.dart';
86
import 'package:flutter_news_app_mobile_client_full_source_code/ads/ad_service.dart';
97
import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/ad_placeholder.dart';
108
import 'package:flutter_news_app_mobile_client_full_source_code/ads/models/ad_theme_style.dart';
@@ -14,7 +12,6 @@ import 'package:flutter_news_app_mobile_client_full_source_code/entity_details/b
1412
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/app_localizations.dart';
1513
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/l10n.dart';
1614
import 'package:flutter_news_app_mobile_client_full_source_code/router/routes.dart';
17-
import 'package:flutter_news_app_mobile_client_full_source_code/shared/shared.dart';
1815
import 'package:flutter_news_app_mobile_client_full_source_code/shared/widgets/feed_core/feed_core.dart';
1916
import 'package:go_router/go_router.dart';
2017
import 'package:ui_kit/ui_kit.dart';
@@ -31,47 +28,11 @@ class EntityDetailsPageArguments {
3128

3229
class EntityDetailsPage extends StatelessWidget {
3330
const EntityDetailsPage({required this.args, super.key});
34-
3531
final EntityDetailsPageArguments args;
3632

37-
static Route<void> route({required EntityDetailsPageArguments args}) {
38-
return MaterialPageRoute<void>(
39-
builder: (_) => EntityDetailsPage(args: args),
40-
);
41-
}
42-
4333
@override
4434
Widget build(BuildContext context) {
45-
return BlocProvider<EntityDetailsBloc>(
46-
// Explicitly type BlocProvider
47-
create: (context) {
48-
final topicsRepository = context.read<DataRepository<Topic>>();
49-
final sourcesRepository = context.read<DataRepository<Source>>();
50-
final countriesRepository = context.read<DataRepository<Country>>();
51-
final feedDecoratorService = FeedDecoratorService(
52-
topicsRepository: topicsRepository,
53-
sourcesRepository: sourcesRepository,
54-
);
55-
final entityDetailsBloc =
56-
EntityDetailsBloc(
57-
headlinesRepository: context.read<DataRepository<Headline>>(),
58-
topicRepository: topicsRepository,
59-
sourceRepository: sourcesRepository,
60-
countryRepository: countriesRepository,
61-
accountBloc: context.read<AccountBloc>(),
62-
appBloc: context.read<AppBloc>(),
63-
feedDecoratorService: feedDecoratorService,
64-
)..add(
65-
EntityDetailsLoadRequested(
66-
entityId: args.entityId,
67-
contentType: args.contentType,
68-
adThemeStyle: AdThemeStyle.fromTheme(Theme.of(context)),
69-
),
70-
);
71-
return entityDetailsBloc;
72-
},
73-
child: EntityDetailsView(args: args),
74-
);
35+
return EntityDetailsView(args: args);
7536
}
7637
}
7738

lib/headline-details/view/headline_details_page.dart

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import 'package:flutter/material.dart';
77
import 'package:flutter_bloc/flutter_bloc.dart';
88
import 'package:flutter_news_app_mobile_client_full_source_code/account/bloc/account_bloc.dart';
99
import 'package:flutter_news_app_mobile_client_full_source_code/app/bloc/app_bloc.dart';
10-
import 'package:flutter_news_app_mobile_client_full_source_code/entity_details/view/entity_details_page.dart';
1110
import 'package:flutter_news_app_mobile_client_full_source_code/headline-details/bloc/headline_details_bloc.dart';
1211
import 'package:flutter_news_app_mobile_client_full_source_code/headline-details/bloc/similar_headlines_bloc.dart';
1312
import 'package:flutter_news_app_mobile_client_full_source_code/l10n/l10n.dart';
@@ -422,12 +421,12 @@ class _HeadlineDetailsPageState extends State<HeadlineDetailsPage> {
422421
..add(
423422
InkWell(
424423
onTap: () {
425-
context.push(
426-
Routes.sourceDetails,
427-
extra: EntityDetailsPageArguments(
428-
entityId: headline.id,
429-
contentType: ContentType.headline,
430-
),
424+
context.pushNamed(
425+
Routes.entityDetailsName,
426+
pathParameters: {
427+
'type': ContentType.source.name,
428+
'id': headline.source.id,
429+
},
431430
);
432431
},
433432
borderRadius: BorderRadius.circular(AppSpacing.sm),
@@ -450,12 +449,12 @@ class _HeadlineDetailsPageState extends State<HeadlineDetailsPage> {
450449
..add(
451450
InkWell(
452451
onTap: () {
453-
context.push(
454-
Routes.topicDetails,
455-
extra: EntityDetailsPageArguments(
456-
entityId: headline.topic.id,
457-
contentType: ContentType.topic,
458-
),
452+
context.pushNamed(
453+
Routes.entityDetailsName,
454+
pathParameters: {
455+
'type': ContentType.topic.name,
456+
'id': headline.topic.id,
457+
},
459458
);
460459
},
461460
borderRadius: BorderRadius.circular(AppSpacing.sm),
@@ -474,6 +473,34 @@ class _HeadlineDetailsPageState extends State<HeadlineDetailsPage> {
474473
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
475474
),
476475
),
476+
)
477+
..add(
478+
InkWell(
479+
onTap: () {
480+
context.pushNamed(
481+
Routes.entityDetailsName,
482+
pathParameters: {
483+
'type': ContentType.country.name,
484+
'id': headline.eventCountry.id,
485+
},
486+
);
487+
},
488+
borderRadius: BorderRadius.circular(AppSpacing.sm),
489+
child: Chip(
490+
avatar: Icon(
491+
Icons.location_city_outlined,
492+
size: chipAvatarSize,
493+
color: chipAvatarColor,
494+
),
495+
label: Text(headline.eventCountry.name),
496+
labelStyle: chipLabelStyle,
497+
backgroundColor: chipBackgroundColor,
498+
padding: chipPadding,
499+
shape: chipShape,
500+
visualDensity: VisualDensity.compact,
501+
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
502+
),
503+
),
477504
);
478505

479506
return chips;

lib/headlines-search/widgets/category_item_widget.dart

Lines changed: 0 additions & 35 deletions
This file was deleted.

lib/headlines-search/widgets/country_item_widget.dart

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'package:core/core.dart';
22
import 'package:flutter/material.dart';
3-
import 'package:flutter_news_app_mobile_client_full_source_code/entity_details/view/entity_details_page.dart';
43
import 'package:flutter_news_app_mobile_client_full_source_code/router/routes.dart';
54
import 'package:go_router/go_router.dart';
65

@@ -21,12 +20,9 @@ class CountryItemWidget extends StatelessWidget {
2120
? Text(country.isoCode, maxLines: 1, overflow: TextOverflow.ellipsis)
2221
: null,
2322
onTap: () {
24-
context.push(
25-
Routes.countryDetails,
26-
extra: EntityDetailsPageArguments(
27-
entityId: country.id,
28-
contentType: ContentType.country,
29-
),
23+
context.pushNamed(
24+
Routes.entityDetailsName,
25+
pathParameters: {'type': ContentType.country.name, 'id': country.id},
3026
);
3127
},
3228
);

lib/headlines-search/widgets/source_item_widget.dart

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'package:core/core.dart';
22
import 'package:flutter/material.dart';
3-
import 'package:flutter_news_app_mobile_client_full_source_code/entity_details/view/entity_details_page.dart';
43
import 'package:flutter_news_app_mobile_client_full_source_code/router/routes.dart';
54
import 'package:go_router/go_router.dart';
65

@@ -22,12 +21,9 @@ class SourceItemWidget extends StatelessWidget {
2221
)
2322
: null,
2423
onTap: () {
25-
context.push(
26-
Routes.sourceDetails,
27-
extra: EntityDetailsPageArguments(
28-
entityId: source.id,
29-
contentType: ContentType.source,
30-
),
24+
context.pushNamed(
25+
Routes.entityDetailsName,
26+
pathParameters: {'type': ContentType.source.name, 'id': source.id},
3127
);
3228
},
3329
);

lib/headlines-search/widgets/topic_item_widget.dart

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import 'package:core/core.dart';
22
import 'package:flutter/material.dart';
3-
import 'package:flutter_news_app_mobile_client_full_source_code/entity_details/view/entity_details_page.dart';
43
import 'package:flutter_news_app_mobile_client_full_source_code/router/routes.dart';
54
import 'package:go_router/go_router.dart';
65

@@ -22,12 +21,9 @@ class TopicItemWidget extends StatelessWidget {
2221
)
2322
: null,
2423
onTap: () {
25-
context.push(
26-
Routes.topicDetails,
27-
extra: EntityDetailsPageArguments(
28-
entityId: topic.id,
29-
contentType: ContentType.topic,
30-
),
24+
context.pushNamed(
25+
Routes.entityDetailsName,
26+
pathParameters: {'type': ContentType.topic.name, 'id': topic.id},
3127
);
3228
},
3329
);

0 commit comments

Comments
 (0)