@@ -22,18 +22,12 @@ class EditHeadlinePage extends StatelessWidget {
22
22
23
23
@override
24
24
Widget build (BuildContext context) {
25
- // The list of all countries is fetched once and cached in the
26
- // ContentManagementBloc. We read it here and provide it to the
27
- // EditHeadlineBloc.
28
- final contentManagementState = context.watch <ContentManagementBloc >().state;
29
- final allCountries = contentManagementState.allCountries;
30
-
31
25
return BlocProvider (
32
26
create: (context) => EditHeadlineBloc (
33
27
headlinesRepository: context.read <DataRepository <Headline >>(),
34
28
sourcesRepository: context.read <DataRepository <Source >>(),
35
29
topicsRepository: context.read <DataRepository <Topic >>(),
36
- countries: allCountries,
30
+ countries: context. read < ContentManagementBloc >().state. allCountries,
37
31
headlineId: headlineId,
38
32
)..add (const EditHeadlineLoaded ()),
39
33
child: const _EditHeadlineView (),
@@ -106,14 +100,23 @@ class _EditHeadlineViewState extends State<_EditHeadlineView> {
106
100
),
107
101
],
108
102
),
109
- body: BlocConsumer < EditHeadlineBloc , EditHeadlineState >(
103
+ body: BlocListener < ContentManagementBloc , ContentManagementState >(
110
104
listenWhen: (previous, current) =>
111
- previous.status != current.status ||
112
- previous.initialHeadline != current.initialHeadline,
113
- listener: (context, state) {
114
- if (state.status == EditHeadlineStatus .success &&
115
- state.updatedHeadline != null &&
116
- ModalRoute .of (context)! .isCurrent) {
105
+ previous.allCountriesStatus != current.allCountriesStatus &&
106
+ current.allCountriesStatus == ContentManagementStatus .success,
107
+ listener: (context, contentState) {
108
+ context.read <EditHeadlineBloc >().add (
109
+ EditHeadlineDataUpdated (countries: contentState.allCountries),
110
+ );
111
+ },
112
+ child: BlocConsumer <EditHeadlineBloc , EditHeadlineState >(
113
+ listenWhen: (previous, current) =>
114
+ previous.status != current.status ||
115
+ previous.initialHeadline != current.initialHeadline,
116
+ listener: (context, state) {
117
+ if (state.status == EditHeadlineStatus .success &&
118
+ state.updatedHeadline != null &&
119
+ ModalRoute .of (context)! .isCurrent) {
117
120
ScaffoldMessenger .of (context)
118
121
..hideCurrentSnackBar ()
119
122
..showSnackBar (
@@ -141,14 +144,14 @@ class _EditHeadlineViewState extends State<_EditHeadlineView> {
141
144
_imageUrlController.text = state.imageUrl;
142
145
}
143
146
},
144
- builder: (context, state) {
145
- if (state.status == EditHeadlineStatus .loading) {
146
- return LoadingStateWidget (
147
- icon: Icons .newspaper,
148
- headline: l10n.loadingHeadline,
149
- subheadline: l10n.pleaseWait,
150
- );
151
- }
147
+ builder: (context, state) {
148
+ if (state.status == EditHeadlineStatus .loading) {
149
+ return LoadingStateWidget (
150
+ icon: Icons .newspaper,
151
+ headline: l10n.loadingHeadline,
152
+ subheadline: l10n.pleaseWait,
153
+ );
154
+ }
152
155
153
156
if (state.status == EditHeadlineStatus .failure &&
154
157
state.initialHeadline == null ) {
0 commit comments