Skip to content

Commit e232446

Browse files
committed
fix: exception in school card
1 parent 917fc3a commit e232446

File tree

3 files changed

+47
-24
lines changed

3 files changed

+47
-24
lines changed

lib/controller/school_card_controller.dart

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
import 'dart:typed_data';
1+
//import 'dart:typed_data';
22

3+
import 'package:dio/dio.dart';
4+
import 'dart:developer' as developer;
35
import 'package:get/get.dart';
46
import 'package:jiffy/jiffy.dart';
57
import 'package:watermeter/model/xidian_ids/paid_record.dart';
68
import 'package:watermeter/repository/xidian_ids/school_card_session.dart';
79

810
class SchoolCardController extends GetxController {
11+
bool isGet = false;
12+
String? error;
13+
914
SchoolCardSession session = SchoolCardSession();
10-
late Future<Uint8List> qrcode;
15+
// late Future<Uint8List> qrcode;
1116
var money = "".obs;
1217
List<DateTime?> timeRange = [];
1318
var getPaid = <PaidRecord>[].obs;
19+
1420
@override
1521
void onInit() {
1622
super.onInit();
@@ -23,9 +29,23 @@ class SchoolCardController extends GetxController {
2329

2430
@override
2531
void onReady() async {
26-
super.onReady();
27-
await session.initSession();
28-
await updateMoney();
32+
try {
33+
super.onReady();
34+
await session.initSession();
35+
await updateMoney();
36+
} on DioException catch (e, s) {
37+
developer.log(
38+
"Network exception: ${e.message}\nStack: $s",
39+
name: "ScoreController",
40+
);
41+
error = "网络错误,可能是没联网,可能是学校服务器出现了故障:-P";
42+
} catch (e, s) {
43+
developer.log(
44+
"Other exception: $e\nStack: $s",
45+
name: "ScoreController",
46+
);
47+
error = "未知错误,感兴趣的话,请接到电脑 adb 查看日志。";
48+
}
2949
}
3050

3151
Future<void> refreshPaidRecord() async {

lib/page/home.dart

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:watermeter/page/setting/setting.dart';
44
import 'package:watermeter/page/widget.dart';
55
import 'package:watermeter/page/xdu_planet/mainpage.dart';
66
import 'package:watermeter/page/xidian_directory/xidian_directory.dart';
7+
import 'package:watermeter/repository/network_session.dart';
78

89
class PageInformation {
910
final int index;
@@ -70,25 +71,27 @@ class _HomePageState extends State<HomePage> {
7071
super.initState();
7172
_controller = PageController();
7273

73-
WidgetsBinding.instance.addPostFrameCallback((_) {
74-
showDialog(
75-
context: context,
76-
builder: (context) => AlertDialog(
77-
title: const Text("统一认证服务离线模式开启"),
78-
content: const Text(
79-
"无法连接到统一认证服务服务器,所有和其相关的服务暂时不可用。\n"
80-
"成绩查询,考试信息查询,欠费查询,校园卡查询关闭。课表显示缓存数据。其他功能暂不受影响。\n"
81-
"如有不便,敬请谅解。",
82-
),
83-
actions: [
84-
TextButton(
85-
onPressed: () => Navigator.of(context).pop(),
86-
child: const Text("确定"),
74+
if (offline) {
75+
WidgetsBinding.instance.addPostFrameCallback((_) {
76+
showDialog(
77+
context: context,
78+
builder: (context) => AlertDialog(
79+
title: const Text("统一认证服务离线模式开启"),
80+
content: const Text(
81+
"无法连接到统一认证服务服务器,所有和其相关的服务暂时不可用。\n"
82+
"成绩查询,考试信息查询,欠费查询,校园卡查询关闭。课表显示缓存数据。其他功能暂不受影响。\n"
83+
"如有不便,敬请谅解。",
8784
),
88-
],
89-
),
90-
);
91-
});
85+
actions: [
86+
TextButton(
87+
onPressed: () => Navigator.of(context).pop(),
88+
child: const Text("确定"),
89+
),
90+
],
91+
),
92+
);
93+
});
94+
}
9295
}
9396

9497
Widget _buildPhone() => Scaffold(

lib/repository/network_session.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Alice alice = Alice();
2020

2121
late Directory supportPath;
2222

23-
bool offline = true;
23+
bool offline = false;
2424

2525
class NetworkSession {
2626
@protected

0 commit comments

Comments
 (0)