Skip to content

Commit 0ce044e

Browse files
committed
fix: logic error at experiment fetching
- remove previous status, useless and confusing
1 parent 43c1149 commit 0ce044e

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

lib/controller/experiment_controller.dart

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ class ExperimentController extends GetxController {
229229
}
230230

231231
Future<List<ExperimentData>> getPhysicsExperiment() async {
232-
ExperimentStatus previous = physicsStatus;
233232
physicsStatus = ExperimentStatus.fetching;
234233
update();
235234
List<ExperimentData> toReturn = [];
@@ -247,7 +246,7 @@ class ExperimentController extends GetxController {
247246
);
248247
if (physicsCacheFile.existsSync()) {
249248
log.info(
250-
"[ExamController][getPhysicsExperiment] "
249+
"[ExperimentController][getPhysicsExperiment] "
251250
"Try to get physics experiment from cache.",
252251
);
253252
try {
@@ -269,19 +268,24 @@ class ExperimentController extends GetxController {
269268

270269
if (hasOldFormat) {
271270
log.info(
272-
"[ExamController][getPhysicsExperiment] "
273-
"Detected old String format in physics cache.",
271+
"[ExperimentController][getPhysicsExperiment] "
272+
"Old format detected, detectin old String format in physics cache.",
274273
);
275274
// Delete old cache file to force refresh
276275
physicsCacheFile.deleteSync();
277276
} else {
277+
log.info(
278+
"[ExperimentController][getPhysicsExperiment] "
279+
"Loading data from cache.",
280+
);
278281
toReturn.addAll(physicsData);
279282
physicsStatus = ExperimentStatus.cache;
280283
}
281284
} catch (e, s) {
282-
log.handle(e, s);
283-
log.warning(
284-
"[ExamController][getPhysicsExperiment] "
285+
log.handle(
286+
e,
287+
s,
288+
"[ExperimentController][getPhysicsExperiment] "
285289
"Failed to parse physics cache.",
286290
);
287291
physicsStatusError = "not_school_network";
@@ -336,7 +340,7 @@ class ExperimentController extends GetxController {
336340
log.handle(e, s);
337341
}
338342
}
339-
} else if (previous == ExperimentStatus.cache) {
343+
} else if (physicsStatus == ExperimentStatus.cache) {
340344
physicsStatus = ExperimentStatus.cache;
341345
} else {
342346
physicsStatus = ExperimentStatus.error;
@@ -346,7 +350,6 @@ class ExperimentController extends GetxController {
346350
}
347351

348352
Future<List<ExperimentData>> getOtherExperiment() async {
349-
ExperimentStatus previous = otherStatus;
350353
otherStatus = ExperimentStatus.fetching;
351354
update();
352355
List<ExperimentData> toReturn = [];
@@ -386,18 +389,23 @@ class ExperimentController extends GetxController {
386389

387390
if (hasOldFormat) {
388391
log.info(
389-
"[ExamController][getOtherExperiment] "
390-
"Detected old String format in other cache.",
392+
"[ExperimentController][getOtherExperiment] "
393+
"Old format detected, detectin old String format in physics cache.",
391394
);
392395
otherCacheFile.deleteSync();
393396
} else {
397+
log.info(
398+
"[ExperimentController][getOtherExperiment] "
399+
"Loading data from cache.",
400+
);
394401
toReturn.addAll(otherData);
395402
otherStatus = ExperimentStatus.cache;
396403
}
397404
} catch (e, s) {
398-
log.handle(e, s);
399-
log.warning(
400-
"[ExamController][getOtherExperiment] "
405+
log.handle(
406+
e,
407+
s,
408+
"[ExperimentController][getOtherExperiment] "
401409
"Failed to parse other cache.",
402410
);
403411
otherStatusError = "not_school_network";
@@ -428,6 +436,7 @@ class ExperimentController extends GetxController {
428436
log.handle(e, s);
429437
otherStatusError = "error_detect";
430438
} finally {
439+
log.info("[ExperimentController][getOtherExperiment] Update triggered");
431440
if (otherStatus == ExperimentStatus.fetched) {
432441
log.info(
433442
"[ExperimentController][getOtherExperiment] "
@@ -452,7 +461,7 @@ class ExperimentController extends GetxController {
452461
log.handle(e, s);
453462
}
454463
}
455-
} else if (previous == ExperimentStatus.cache) {
464+
} else if (otherStatus == ExperimentStatus.cache) {
456465
otherStatus = ExperimentStatus.cache;
457466
} else {
458467
otherStatus = ExperimentStatus.error;

lib/page/experiment/experiment_window.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class _ExperimentWindowState extends State<ExperimentWindow> {
5353

5454
// The status of other experiments controller
5555
var otherStatus = controller.otherStatus;
56-
56+
5757
if (physicsStatus != ExperimentStatus.error &&
5858
otherStatus != ExperimentStatus.error &&
5959
physicsStatus != ExperimentStatus.none &&
@@ -89,10 +89,10 @@ class _ExperimentWindowState extends State<ExperimentWindow> {
8989
otherStatus == ExperimentStatus.error) {
9090
return ReloadWidget(
9191
function: controller.get,
92-
errorStatus: FlutterI18n.translate(
93-
context,
94-
"${controller.physicsStatusError} ${controller.otherStatusError}",
95-
),
92+
// Check translate is ok?
93+
errorStatus:
94+
"Physics: ${FlutterI18n.translate(context, controller.physicsStatusError)}\n"
95+
"Others: ${FlutterI18n.translate(context, controller.otherStatusError)}",
9696
).center();
9797
} else if (physicsStatus == ExperimentStatus.fetched ||
9898
otherStatus == ExperimentStatus.fetched ||

0 commit comments

Comments
 (0)