@@ -19,18 +19,12 @@ class CreateHeadlinePage extends StatelessWidget {
19
19
20
20
@override
21
21
Widget build (BuildContext context) {
22
- // The list of all countries is fetched once and cached in the
23
- // ContentManagementBloc. We read it here and provide it to the
24
- // CreateHeadlineBloc.
25
- final contentManagementState = context.watch <ContentManagementBloc >().state;
26
- final allCountries = contentManagementState.allCountries;
27
-
28
22
return BlocProvider (
29
23
create: (context) => CreateHeadlineBloc (
30
24
headlinesRepository: context.read <DataRepository <Headline >>(),
31
25
sourcesRepository: context.read <DataRepository <Source >>(),
32
26
topicsRepository: context.read <DataRepository <Topic >>(),
33
- countries: allCountries,
27
+ countries: context. read < ContentManagementBloc >().state. allCountries,
34
28
)..add (const CreateHeadlineDataLoaded ()),
35
29
child: const _CreateHeadlineView (),
36
30
);
@@ -79,12 +73,21 @@ class _CreateHeadlineViewState extends State<_CreateHeadlineView> {
79
73
),
80
74
],
81
75
),
82
- body: BlocConsumer <CreateHeadlineBloc , CreateHeadlineState >(
83
- listenWhen: (previous, current) => previous.status != current.status,
84
- listener: (context, state) {
85
- if (state.status == CreateHeadlineStatus .success &&
86
- state.createdHeadline != null &&
87
- ModalRoute .of (context)! .isCurrent) {
76
+ body: BlocListener <ContentManagementBloc , ContentManagementState >(
77
+ listenWhen: (previous, current) =>
78
+ previous.allCountriesStatus != current.allCountriesStatus &&
79
+ current.allCountriesStatus == ContentManagementStatus .success,
80
+ listener: (context, contentState) {
81
+ context.read <CreateHeadlineBloc >().add (
82
+ CreateHeadlineDataUpdated (countries: contentState.allCountries),
83
+ );
84
+ },
85
+ child: BlocConsumer <CreateHeadlineBloc , CreateHeadlineState >(
86
+ listenWhen: (previous, current) => previous.status != current.status,
87
+ listener: (context, state) {
88
+ if (state.status == CreateHeadlineStatus .success &&
89
+ state.createdHeadline != null &&
90
+ ModalRoute .of (context)! .isCurrent) {
88
91
ScaffoldMessenger .of (context)
89
92
..hideCurrentSnackBar ()
90
93
..showSnackBar (
@@ -107,14 +110,14 @@ class _CreateHeadlineViewState extends State<_CreateHeadlineView> {
107
110
);
108
111
}
109
112
},
110
- builder: (context, state) {
111
- if (state.status == CreateHeadlineStatus .loading) {
112
- return LoadingStateWidget (
113
- icon: Icons .newspaper,
114
- headline: l10n.loadingData,
115
- subheadline: l10n.pleaseWait,
116
- );
117
- }
113
+ builder: (context, state) {
114
+ if (state.status == CreateHeadlineStatus .loading) {
115
+ return LoadingStateWidget (
116
+ icon: Icons .newspaper,
117
+ headline: l10n.loadingData,
118
+ subheadline: l10n.pleaseWait,
119
+ );
120
+ }
118
121
119
122
if (state.status == CreateHeadlineStatus .failure &&
120
123
state.sources.isEmpty &&
0 commit comments