@@ -9,6 +9,7 @@ import 'package:styled_widget/styled_widget.dart';
99import 'package:watermeter/controller/experiment_controller.dart' ;
1010import 'package:watermeter/page/experiment/experiment_info_card.dart' ;
1111import 'package:watermeter/page/homepage/refresh.dart' ;
12+ import 'package:watermeter/page/public_widget/loading_alerter.dart' ;
1213import 'package:watermeter/page/public_widget/public_widget.dart' ;
1314import 'package:watermeter/page/public_widget/timeline_widget/timeline_title.dart' ;
1415import 'package:watermeter/page/public_widget/timeline_widget/timeline_widget.dart' ;
@@ -47,168 +48,199 @@ class _ExperimentWindowState extends State<ExperimentWindow> {
4748 ),
4849 body: Builder (
4950 builder: (context) {
50- if ((controller.physicsStatus == ExperimentStatus .fetched ||
51- controller.physicsStatus == ExperimentStatus .cache) ||
52- (controller.otherStatus == ExperimentStatus .fetched ||
53- controller.otherStatus == ExperimentStatus .cache)) {
54- var doing = controller.doing (now);
55- var unDone = controller.isNotStarted (now);
56- var done = controller.isFinished (now);
57- return TimelineWidget (
58- isTitle: [
59- /// Show cache notice
60- if (controller.physicsStatus == ExperimentStatus .cache ||
61- controller.otherStatus == ExperimentStatus .cache)
62- false ,
63- if (controller.physicsStatus == ExperimentStatus .error) false ,
64- if (controller.otherStatus == ExperimentStatus .error) false ,
65- false , if (doing.isNotEmpty) ...[true , false ],
66- true ,
67- false ,
68- true ,
69- // false,
70- false ,
71- ],
72- children: [
73- if (controller.physicsStatus == ExperimentStatus .cache ||
74- controller.otherStatus == ExperimentStatus .cache)
75- ExperimentInfoCard (
76- title: FlutterI18n .translate (
77- context,
78- "experiment.cache_hint" ,
79- translationParams: {
80- "info" : [
81- if (controller.physicsStatus ==
82- ExperimentStatus .cache)
83- FlutterI18n .translate (
84- context,
85- "experiment.physics_experiment" ,
86- ),
87- if (controller.otherStatus ==
88- ExperimentStatus .cache)
89- FlutterI18n .translate (
90- context,
91- "experiment.other_experiment" ,
92- ),
93- ].join (" & " ),
94- },
95- ),
96- ),
51+ // The status of physics experiments controller
52+ var physicsStatus = controller.physicsStatus;
9753
98- if (controller.physicsStatus == ExperimentStatus .error)
99- ExperimentInfoCard (
100- title: FlutterI18n .translate (
101- context,
102- "experiment.error_physics" ,
103- translationParams: {
104- "info" : FlutterI18n .translate (
105- context,
106- controller.physicsStatusError,
107- ),
108- },
109- ),
110- ),
111- if (controller.otherStatus == ExperimentStatus .error)
112- ExperimentInfoCard (
113- title: FlutterI18n .translate (
114- context,
115- "experiment.error_other" ,
116- translationParams: {
117- "info" : FlutterI18n .translate (
118- context,
119- controller.otherStatusError,
120- ),
121- },
122- ),
123- ),
124- ExperimentInfoCard (
125- title: FlutterI18n .translate (
126- context,
127- "experiment.score_hint_0" ,
128- translationParams: {
129- "info" : FlutterI18n .translate (
130- context,
131- controller.otherStatusError,
132- ),
133- },
134- ),
135- ),
136- if (doing.isNotEmpty) ...[
137- TimelineTitle (
138- title: FlutterI18n .translate (
139- context,
140- "experiment.ongoing" ,
141- ),
142- ),
143- Column (
144- children: List .generate (
145- doing.length,
146- (index) => ExperimentInfoCard (data: doing[index]),
54+ // The status of other experiments controller
55+ var otherStatus = controller.otherStatus;
56+
57+ if (physicsStatus != ExperimentStatus .error &&
58+ otherStatus != ExperimentStatus .error &&
59+ physicsStatus != ExperimentStatus .none &&
60+ otherStatus != ExperimentStatus .none) {
61+ final isLoading =
62+ physicsStatus == ExperimentStatus .fetching ||
63+ otherStatus == ExperimentStatus .fetching;
64+ return Stack (
65+ children: [
66+ Column (
67+ children: [
68+ AnimatedContainer (
69+ height: isLoading ? kTextTabBarHeight : 0 ,
70+ duration: const Duration (milliseconds: 300 ),
71+ curve: Curves .easeInOut,
14772 ),
148- ),
149- ],
150- TimelineTitle (
151- title: FlutterI18n .translate (
152- context,
153- "experiment.not_finished" ,
154- ),
73+ Expanded (child: buildExperimentList (controller)),
74+ ],
15575 ),
156- unDone.isNotEmpty
157- ? Column (
158- children: List .generate (
159- unDone.length,
160- (index) => ExperimentInfoCard (data: unDone[index]),
161- ),
162- )
163- : TimelineTitle (
164- title: FlutterI18n .translate (
165- context,
166- "experiment.all_finished" ,
167- ),
168- ),
169- TimelineTitle (
170- title: FlutterI18n .translate (
76+ LoadingAlerter (
77+ isLoading: isLoading,
78+ hint: FlutterI18n .translate (
17179 context,
172- "experiment.finished " ,
80+ "experiment.fetching_hint " ,
17381 ),
82+ opacity: 0.15 ,
83+ showOverlay: true ,
17484 ),
175- // ExperimentInfoCard(
176- // title: FlutterI18n.translate(
177- // context,
178- // "experiment.score_sum",
179- // translationParams: {"sum": controller.sum.toString()},
180- // ),
181- // ),
182- done.isNotEmpty
183- ? Column (
184- children: List .generate (
185- done.length,
186- (index) => ExperimentInfoCard (data: done[index]),
187- ),
188- )
189- : TimelineTitle (
190- title: FlutterI18n .translate (
191- context,
192- "experiment.none_finished" ,
193- ),
194- ),
19585 ],
19686 );
197- } else if (controller.physicsStatus == ExperimentStatus .error &&
198- controller.otherStatus == ExperimentStatus .error) {
199- return ReloadWidget (
200- function: controller.get ,
201- errorStatus: FlutterI18n .translate (
202- context,
203- "${controller .physicsStatusError } ${controller .otherStatusError }" ,
204- ),
205- ).center ();
20687 } else {
207- return CircularProgressIndicator ().center ();
88+ if (physicsStatus == ExperimentStatus .error &&
89+ otherStatus == ExperimentStatus .error) {
90+ return ReloadWidget (
91+ function: controller.get ,
92+ errorStatus: FlutterI18n .translate (
93+ context,
94+ "${controller .physicsStatusError } ${controller .otherStatusError }" ,
95+ ),
96+ ).center ();
97+ } else if (physicsStatus == ExperimentStatus .fetched ||
98+ otherStatus == ExperimentStatus .fetched ||
99+ physicsStatus == ExperimentStatus .cache ||
100+ otherStatus == ExperimentStatus .cache) {
101+ return buildExperimentList (controller);
102+ } else {
103+ return const Center (child: CircularProgressIndicator ());
104+ }
208105 }
209106 },
210107 ),
211108 ),
212109 );
213110 }
111+
112+ Widget buildExperimentList (ExperimentController controller) {
113+ var doing = controller.doing (now);
114+ var unDone = controller.isNotStarted (now);
115+ var done = controller.isFinished (now);
116+ return TimelineWidget (
117+ isTitle: [
118+ /// Show cache notice
119+ if (controller.physicsStatus == ExperimentStatus .cache ||
120+ controller.otherStatus == ExperimentStatus .cache)
121+ false ,
122+ if (controller.physicsStatus == ExperimentStatus .error) false ,
123+ if (controller.otherStatus == ExperimentStatus .error) false ,
124+ false , if (doing.isNotEmpty) ...[true , false ],
125+ true ,
126+ false ,
127+ true ,
128+ // false,
129+ false ,
130+ ],
131+ children: [
132+ if (controller.physicsStatus == ExperimentStatus .cache ||
133+ controller.otherStatus == ExperimentStatus .cache)
134+ ExperimentInfoCard (
135+ title: FlutterI18n .translate (
136+ context,
137+ "experiment.cache_hint" ,
138+ translationParams: {
139+ "info" : [
140+ if (controller.physicsStatus == ExperimentStatus .cache)
141+ FlutterI18n .translate (
142+ context,
143+ "experiment.physics_experiment" ,
144+ ),
145+ if (controller.otherStatus == ExperimentStatus .cache)
146+ FlutterI18n .translate (
147+ context,
148+ "experiment.other_experiment" ,
149+ ),
150+ ].join (" & " ),
151+ },
152+ ),
153+ ),
154+
155+ if (controller.physicsStatus == ExperimentStatus .error)
156+ ExperimentInfoCard (
157+ title: FlutterI18n .translate (
158+ context,
159+ "experiment.error_physics" ,
160+ translationParams: {
161+ "info" : FlutterI18n .translate (
162+ context,
163+ controller.physicsStatusError,
164+ ),
165+ },
166+ ),
167+ ),
168+ if (controller.otherStatus == ExperimentStatus .error)
169+ ExperimentInfoCard (
170+ title: FlutterI18n .translate (
171+ context,
172+ "experiment.error_other" ,
173+ translationParams: {
174+ "info" : FlutterI18n .translate (
175+ context,
176+ controller.otherStatusError,
177+ ),
178+ },
179+ ),
180+ ),
181+ ExperimentInfoCard (
182+ title: FlutterI18n .translate (
183+ context,
184+ "experiment.score_hint_0" ,
185+ translationParams: {
186+ "info" : FlutterI18n .translate (
187+ context,
188+ controller.otherStatusError,
189+ ),
190+ },
191+ ),
192+ ),
193+ if (doing.isNotEmpty) ...[
194+ TimelineTitle (
195+ title: FlutterI18n .translate (context, "experiment.ongoing" ),
196+ ),
197+ Column (
198+ children: List .generate (
199+ doing.length,
200+ (index) => ExperimentInfoCard (data: doing[index]),
201+ ),
202+ ),
203+ ],
204+ TimelineTitle (
205+ title: FlutterI18n .translate (context, "experiment.not_finished" ),
206+ ),
207+ unDone.isNotEmpty
208+ ? Column (
209+ children: List .generate (
210+ unDone.length,
211+ (index) => ExperimentInfoCard (data: unDone[index]),
212+ ),
213+ )
214+ : TimelineTitle (
215+ title: FlutterI18n .translate (
216+ context,
217+ "experiment.all_finished" ,
218+ ),
219+ ),
220+ TimelineTitle (
221+ title: FlutterI18n .translate (context, "experiment.finished" ),
222+ ),
223+ // ExperimentInfoCard(
224+ // title: FlutterI18n.translate(
225+ // context,
226+ // "experiment.score_sum",
227+ // translationParams: {"sum": controller.sum.toString()},
228+ // ),
229+ // ),
230+ done.isNotEmpty
231+ ? Column (
232+ children: List .generate (
233+ done.length,
234+ (index) => ExperimentInfoCard (data: done[index]),
235+ ),
236+ )
237+ : TimelineTitle (
238+ title: FlutterI18n .translate (
239+ context,
240+ "experiment.none_finished" ,
241+ ),
242+ ),
243+ ],
244+ );
245+ }
214246}
0 commit comments