@@ -23,18 +23,11 @@ class EditSourcePage extends StatelessWidget {
23
23
24
24
@override
25
25
Widget build (BuildContext context) {
26
- // The lists of all countries and languages are fetched once and cached in
27
- // the ContentManagementBloc. We read them here and provide them to the
28
- // EditSourceBloc.
29
- final contentManagementState = context.read <ContentManagementBloc >().state;
30
- final allCountries = contentManagementState.allCountries;
31
- final allLanguages = contentManagementState.allLanguages;
32
-
33
26
return BlocProvider (
34
27
create: (context) => EditSourceBloc (
35
28
sourcesRepository: context.read <DataRepository <Source >>(),
36
- countries: allCountries,
37
- languages: allLanguages,
29
+ countries: context. read < ContentManagementBloc >().state. allCountries,
30
+ languages: context. read < ContentManagementBloc >().state. allLanguages,
38
31
sourceId: sourceId,
39
32
)..add (const EditSourceLoaded ()),
40
33
child: const _EditSourceView (),
@@ -104,14 +97,28 @@ class _EditSourceViewState extends State<_EditSourceView> {
104
97
),
105
98
],
106
99
),
107
- body: BlocConsumer < EditSourceBloc , EditSourceState >(
100
+ body: BlocListener < ContentManagementBloc , ContentManagementState >(
108
101
listenWhen: (previous, current) =>
109
- previous.status != current.status ||
110
- previous.initialSource != current.initialSource,
111
- listener: (context, state) {
112
- if (state.status == EditSourceStatus .success &&
113
- state.updatedSource != null &&
114
- ModalRoute .of (context)! .isCurrent) {
102
+ (previous.allCountriesStatus != current.allCountriesStatus &&
103
+ current.allCountriesStatus == ContentManagementStatus .success) ||
104
+ (previous.allLanguagesStatus != current.allLanguagesStatus &&
105
+ current.allLanguagesStatus == ContentManagementStatus .success),
106
+ listener: (context, contentState) {
107
+ context.read <EditSourceBloc >().add (
108
+ EditSourceDataUpdated (
109
+ countries: contentState.allCountries,
110
+ languages: contentState.allLanguages,
111
+ ),
112
+ );
113
+ },
114
+ child: BlocConsumer <EditSourceBloc , EditSourceState >(
115
+ listenWhen: (previous, current) =>
116
+ previous.status != current.status ||
117
+ previous.initialSource != current.initialSource,
118
+ listener: (context, state) {
119
+ if (state.status == EditSourceStatus .success &&
120
+ state.updatedSource != null &&
121
+ ModalRoute .of (context)! .isCurrent) {
115
122
ScaffoldMessenger .of (context)
116
123
..hideCurrentSnackBar ()
117
124
..showSnackBar (
@@ -138,14 +145,14 @@ class _EditSourceViewState extends State<_EditSourceView> {
138
145
_urlController.text = state.url;
139
146
}
140
147
},
141
- builder: (context, state) {
142
- if (state.status == EditSourceStatus .loading) {
143
- return LoadingStateWidget (
144
- icon: Icons .source,
145
- headline: l10n.loadingSource,
146
- subheadline: l10n.pleaseWait,
147
- );
148
- }
148
+ builder: (context, state) {
149
+ if (state.status == EditSourceStatus .loading) {
150
+ return LoadingStateWidget (
151
+ icon: Icons .source,
152
+ headline: l10n.loadingSource,
153
+ subheadline: l10n.pleaseWait,
154
+ );
155
+ }
149
156
150
157
if (state.status == EditSourceStatus .failure &&
151
158
state.initialSource == null ) {
0 commit comments