@@ -20,18 +20,11 @@ class CreateSourcePage extends StatelessWidget {
20
20
21
21
@override
22
22
Widget build (BuildContext context) {
23
- // The lists of all countries and languages are fetched once and cached in
24
- // the ContentManagementBloc. We read them here and provide them to the
25
- // CreateSourceBloc.
26
- final contentManagementState = context.read <ContentManagementBloc >().state;
27
- final allCountries = contentManagementState.allCountries;
28
- final allLanguages = contentManagementState.allLanguages;
29
-
30
23
return BlocProvider (
31
24
create: (context) => CreateSourceBloc (
32
25
sourcesRepository: context.read <DataRepository <Source >>(),
33
- countries: allCountries,
34
- languages: allLanguages,
26
+ countries: context. read < ContentManagementBloc >().state. allCountries,
27
+ languages: context. read < ContentManagementBloc >().state. allLanguages,
35
28
),
36
29
child: const _CreateSourceView (),
37
30
);
@@ -80,12 +73,26 @@ class _CreateSourceViewState extends State<_CreateSourceView> {
80
73
),
81
74
],
82
75
),
83
- body: BlocConsumer <CreateSourceBloc , CreateSourceState >(
84
- listenWhen: (previous, current) => previous.status != current.status,
85
- listener: (context, state) {
86
- if (state.status == CreateSourceStatus .success &&
87
- state.createdSource != null &&
88
- ModalRoute .of (context)! .isCurrent) {
76
+ body: BlocListener <ContentManagementBloc , ContentManagementState >(
77
+ listenWhen: (previous, current) =>
78
+ (previous.allCountriesStatus != current.allCountriesStatus &&
79
+ current.allCountriesStatus == ContentManagementStatus .success) ||
80
+ (previous.allLanguagesStatus != current.allLanguagesStatus &&
81
+ current.allLanguagesStatus == ContentManagementStatus .success),
82
+ listener: (context, contentState) {
83
+ context.read <CreateSourceBloc >().add (
84
+ CreateSourceDataUpdated (
85
+ countries: contentState.allCountries,
86
+ languages: contentState.allLanguages,
87
+ ),
88
+ );
89
+ },
90
+ child: BlocConsumer <CreateSourceBloc , CreateSourceState >(
91
+ listenWhen: (previous, current) => previous.status != current.status,
92
+ listener: (context, state) {
93
+ if (state.status == CreateSourceStatus .success &&
94
+ state.createdSource != null &&
95
+ ModalRoute .of (context)! .isCurrent) {
89
96
ScaffoldMessenger .of (context)
90
97
..hideCurrentSnackBar ()
91
98
..showSnackBar (
@@ -108,14 +115,14 @@ class _CreateSourceViewState extends State<_CreateSourceView> {
108
115
);
109
116
}
110
117
},
111
- builder: (context, state) {
112
- if (state.status == CreateSourceStatus .loading) {
113
- return LoadingStateWidget (
114
- icon: Icons .source,
115
- headline: l10n.loadingData,
116
- subheadline: l10n.pleaseWait,
117
- );
118
- }
118
+ builder: (context, state) {
119
+ if (state.status == CreateSourceStatus .loading) {
120
+ return LoadingStateWidget (
121
+ icon: Icons .source,
122
+ headline: l10n.loadingData,
123
+ subheadline: l10n.pleaseWait,
124
+ );
125
+ }
119
126
120
127
if (state.status == CreateSourceStatus .failure) {
121
128
return FailureStateWidget (
0 commit comments