Skip to content

Commit 5f11882

Browse files
committed
feat(pages): add logger to pages
Signed-off-by: OctagonalStar <[email protected]>
1 parent d18d9cc commit 5f11882

File tree

6 files changed

+60
-92
lines changed

6 files changed

+60
-92
lines changed

lib/package_replacement/storage.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class SharedPreferences {
3737
rt.logger.fine("已完成数据库缓存读取");
3838
rt.type = false;
3939
} catch (e) {
40-
rt.logger.warning("IndexDB实例获取失败[$e],回退至SharedPreferences")
40+
rt.logger.warning("IndexDB实例获取失败[$e],回退至SharedPreferences");
4141
rt.prefs = await shpr.SharedPreferences.getInstance();
4242
rt.type = true;
4343
}

lib/pages/home_page.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ class HomePage extends StatelessWidget {
1313
const HomePage({super.key});
1414
@override
1515
Widget build(BuildContext context) {
16+
context.read<Global>().uiLogger.fine("构建HomePage");
1617
final themeColor = Theme.of(context).colorScheme;
1718
final mediaQuery = MediaQuery.of(context);
1819
final FSRS fsrs = FSRS();
1920

2021
return FutureBuilder(
21-
future: fsrs.init(),
22+
future: fsrs.init(context: context),
2223
builder: (context, asyncSnapshot) {
2324
return Column(
2425
children: [
@@ -159,6 +160,7 @@ class _DailyWord extends State<DailyWord> {
159160

160161
@override
161162
Widget build(BuildContext context) {
163+
context.read<Global>().uiLogger.fine("构建DailyWord组件");
162164
MediaQueryData mediaQuery = MediaQuery.of(context);
163165
final now = DateTime.now();
164166
final seed = now.year * 10000 + now.month * 100 + now.day;
@@ -182,6 +184,7 @@ class _DailyWord extends State<DailyWord> {
182184
}
183185
playing = false;
184186
} else {
187+
context.read<Global>().uiLogger.info("跳转: DailyWord => SettingPage");
185188
Navigator.of(context).push(MaterialPageRoute(builder: (context) => SettingPage()));
186189
}
187190
},

lib/pages/learning_page.dart

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:provider/provider.dart';
3+
14
import 'package:arabic_learning/funcs/ui.dart';
25
import 'package:arabic_learning/funcs/utili.dart';
3-
import 'package:arabic_learning/sub_pages_builder/learning_pages/fsrs_pages.dart';
46
import 'package:arabic_learning/vars/global.dart';
5-
import 'package:arabic_learning/sub_pages_builder/learning_pages/learning_pages_build.dart';
6-
import 'package:flutter/material.dart';
77
import 'package:arabic_learning/vars/statics_var.dart';
8-
import 'package:provider/provider.dart';
8+
import 'package:arabic_learning/sub_pages_builder/learning_pages/fsrs_pages.dart' show ForeFSRSSettingPage;
9+
import 'package:arabic_learning/sub_pages_builder/learning_pages/learning_pages_build.dart';
910

1011
class LearningPage extends StatelessWidget {
1112
const LearningPage({super.key});
1213
@override
1314
Widget build(BuildContext context) {
15+
context.read<Global>().uiLogger.fine("构建 LearningPage");
1416
final mediaQuery = MediaQuery.of(context);
1517
return Center(
1618
child: Column(
@@ -94,6 +96,7 @@ class LearningPage extends StatelessWidget {
9496
),
9597
),
9698
onPressed: (){
99+
context.read<Global>().uiLogger.info("跳转: LearningPage => ForeFSRSSettingPage");
97100
Navigator.push(
98101
context,
99102
MaterialPageRoute(
@@ -112,6 +115,7 @@ class LearningPage extends StatelessWidget {
112115
shape: RoundedRectangleBorder(borderRadius: StaticsVar.br),
113116
),
114117
onPressed: (){
118+
context.read<Global>().uiLogger.info("跳转: LearningPage => WordCardOverViewPage");
115119
Navigator.push(
116120
context,
117121
MaterialPageRoute(
@@ -139,17 +143,22 @@ class LearningPage extends StatelessWidget {
139143

140144

141145
Future<void> shiftToStudy(BuildContext context, int studyType) async {
142-
await popSelectClasses(context, withCache: true);
143-
if(!context.mounted) return;
144-
final List<Map<String, dynamic>> words = getSelectedWords(context, doShuffle: false, doDouble: false);
146+
context.read<Global>().uiLogger.info("准备转向学习页面: studyType: $studyType");
147+
final List<List<String>> selectedClasses = await popSelectClasses(context, withCache: false);
148+
if(selectedClasses.isEmpty || !context.mounted) return;
149+
final List<Map<String, dynamic>> words = getSelectedWords(context, doShuffle: false, doDouble: false, forceSelectClasses: selectedClasses);
150+
context.read<Global>().uiLogger.info("完成单词挑拣,共${words.length}个");
145151
if(words.isEmpty) return;
152+
context.read<Global>().uiLogger.info("跳转: LearningPage => InLearningPage");
146153
final bool? finished = await Navigator.push(
147154
context,
148155
MaterialPageRoute(
149156
builder: (context) => InLearningPage(studyType: studyType, words: words),
150157
),
151158
);
152-
if((finished??false) && context.mounted) {
159+
if(!context.mounted) return;
160+
context.read<Global>().uiLogger.info("返回完成情况: $finished");
161+
if(finished??false) {
153162
context.read<Global>().saveLearningProgress(words);
154163
}
155164
}

lib/pages/setting_page.dart

Lines changed: 31 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import 'dart:convert';
2+
3+
import 'package:flutter/foundation.dart' show kIsWeb;
4+
import 'package:file_picker/file_picker.dart';
5+
import 'package:flutter/material.dart';
6+
import 'package:provider/provider.dart';
7+
import 'package:url_launcher/url_launcher.dart';
8+
29
import 'package:arabic_learning/funcs/ui.dart';
10+
import 'package:arabic_learning/vars/global.dart';
11+
import 'package:arabic_learning/sub_pages_builder/setting_pages/item_widget.dart';
312
import 'package:arabic_learning/sub_pages_builder/setting_pages/about_page.dart' show AboutPage;
413
import 'package:arabic_learning/sub_pages_builder/setting_pages/data_download_page.dart' show DownloadPage;
5-
import 'package:arabic_learning/sub_pages_builder/setting_pages/item_widget.dart';
614
import 'package:arabic_learning/sub_pages_builder/setting_pages/model_download_page.dart' show ModelDownload;
715
import 'package:arabic_learning/sub_pages_builder/setting_pages/questions_setting_page.dart' show QuestionsSettingLeadingPage;
816
import 'package:arabic_learning/sub_pages_builder/setting_pages/sync_page.dart' show DataSyncPage;
9-
import 'package:arabic_learning/vars/global.dart';
10-
import 'package:flutter/foundation.dart' show kIsWeb;
11-
import 'package:file_picker/file_picker.dart';
12-
import 'package:flutter/material.dart';
13-
import 'package:provider/provider.dart';
14-
import 'package:url_launcher/url_launcher.dart';
1517
import 'package:arabic_learning/package_replacement/fake_dart_io.dart' if (dart.library.io) 'dart:io' as io;
1618

1719
class SettingPage extends StatefulWidget {
@@ -23,6 +25,7 @@ class SettingPage extends StatefulWidget {
2325
class _SettingPage extends State<SettingPage> {
2426
@override
2527
Widget build(BuildContext context) {
28+
context.read<Global>().uiLogger.fine("构建 SettingPage");
2629
return Scaffold(
2730
appBar: AppBar(title: Text("设置")),
2831
body: Consumer<Global>(
@@ -77,8 +80,9 @@ class _SettingPage extends State<SettingPage> {
7780
DropdownMenuItem(value: 10, child: Text('星青'))
7881
],
7982
onChanged: (value) async {
83+
context.read<Global>().uiLogger.info("更新主题颜色: $value");
8084
setting['regular']['theme'] = value;
81-
Provider.of<Global>(context, listen: false).updateSetting();
85+
context.read<Global>().updateSetting();
8286
},
8387
),
8488
],
@@ -91,6 +95,7 @@ class _SettingPage extends State<SettingPage> {
9195
Switch(
9296
value: setting['regular']['darkMode'] ?? false,
9397
onChanged: (value) {
98+
context.read<Global>().uiLogger.info("更新深色模式设置: $value");
9499
setting['regular']['darkMode'] = value;
95100
context.read<Global>().updateSetting();
96101
},
@@ -110,6 +115,7 @@ class _SettingPage extends State<SettingPage> {
110115
DropdownMenuItem(value: 2, child: Text('中阿均使用备用字体')),
111116
],
112117
onChanged: (value) {
118+
context.read<Global>().uiLogger.info("更新字体设置: $value");
113119
if(value == 2 && kIsWeb) {
114120
ScaffoldMessenger.of(context).showSnackBar(
115121
SnackBar(content: Text("网页版加载中文字体需要较长时间,请先耐心等待"), duration: Duration(seconds: 3),),
@@ -129,6 +135,7 @@ class _SettingPage extends State<SettingPage> {
129135
Switch(
130136
value: setting['regular']['hideAppDownloadButton'] ?? false,
131137
onChanged: (value) {
138+
context.read<Global>().uiLogger.info("更新网页端APP下载按钮隐藏设置: $value");
132139
setting['regular']['hideAppDownloadButton'] = value;
133140
context.read<Global>().updateSetting();
134141
},
@@ -162,6 +169,7 @@ class _SettingPage extends State<SettingPage> {
162169
shape: RoundedRectangleBorder(borderRadius: BorderRadius.horizontal(left: Radius.circular(25.0)))
163170
),
164171
onPressed: () {
172+
context.read<Global>().uiLogger.info("跳转: SettingPage => DownloadPage");
165173
Navigator.of(context).push(MaterialPageRoute(builder: (context) => DownloadPage()));
166174
},
167175
icon: Icon(Icons.cloud_download),
@@ -173,12 +181,12 @@ class _SettingPage extends State<SettingPage> {
173181
shape: RoundedRectangleBorder(borderRadius: BorderRadius.horizontal(right: Radius.circular(25.0)))
174182
),
175183
onPressed: () async {
184+
context.read<Global>().uiLogger.info("选择手动导入单词");
176185
FilePickerResult? result = await FilePicker.platform.pickFiles(
177186
allowMultiple: false,
178187
type: FileType.custom,
179188
allowedExtensions: ['json'],
180189
);
181-
182190
if (result != null) {
183191
String jsonString;
184192
PlatformFile platformFile = result.files.first;
@@ -188,83 +196,21 @@ class _SettingPage extends State<SettingPage> {
188196
jsonString = await io.File(platformFile.path!).readAsString();
189197
} else {
190198
if (!context.mounted) return;
191-
showDialog(
192-
context: context,
193-
builder: (BuildContext context) {
194-
return AlertDialog(
195-
title: Text('错误'),
196-
content: Text("文件 \"${platformFile.name}\" \n无法读取:bytes和path均为null。"),
197-
actions: <Widget>[
198-
TextButton(
199-
child: Text('好吧'),
200-
onPressed: () {
201-
Navigator.of(context).pop();
202-
},
203-
),
204-
TextButton(
205-
child: Text('行吧'),
206-
onPressed: () {
207-
Navigator.of(context).pop();
208-
},
209-
),
210-
],
211-
);
212-
},
213-
);
199+
context.read<Global>().uiLogger.warning("文件导入错误: bytes和path均为null");
200+
alart(context, "文件 \"${platformFile.name}\" \n无法读取:bytes和path均为null。");
214201
return;
215202
}
203+
if (!context.mounted) return;
216204
try{
217-
if (!context.mounted) return;
205+
context.read<Global>().uiLogger.fine("文件读取完成,开始解析");
218206
Map<String, dynamic> jsonData = json.decode(jsonString);
219207
Provider.of<Global>(context, listen: false).importData(jsonData, platformFile.name);
220-
showDialog(
221-
context: context,
222-
builder: (BuildContext context) {
223-
return AlertDialog(
224-
title: Text('完成'),
225-
content: Column(
226-
mainAxisSize: MainAxisSize.min,
227-
children: [
228-
Text("文件 \"${platformFile.name}\" \n已导入。"),
229-
Text("少数情况下无法即时刷新词汇总量,可稍后再到设置页面查看~", style: TextStyle(fontSize: 8.0, color: Colors.grey))
230-
],
231-
),
232-
actions: <Widget>[
233-
TextButton(
234-
child: Text('好的'),
235-
onPressed: () {
236-
Navigator.of(context).pop();
237-
},
238-
),
239-
],
240-
);
241-
},
242-
);
208+
alart(context, "文件 \"${platformFile.name}\" \n已导入。");
209+
context.read<Global>().uiLogger.info("文件解析成功");
243210
} catch (e) {
244211
if (!context.mounted) return;
245-
showDialog(
246-
context: context,
247-
builder: (BuildContext context) {
248-
return AlertDialog(
249-
title: Text('错误'),
250-
content: Text('文件 ${platformFile.name} 无效:\n$e'),
251-
actions: <Widget>[
252-
TextButton(
253-
child: Text('好吧'),
254-
onPressed: () {
255-
Navigator.of(context).pop();
256-
},
257-
),
258-
TextButton(
259-
child: Text('行吧'),
260-
onPressed: () {
261-
Navigator.of(context).pop();
262-
},
263-
),
264-
],
265-
);
266-
}
267-
);
212+
context.read<Global>().uiLogger.severe("文件 ${platformFile.name} 无效: $e");
213+
alart(context, '文件 ${platformFile.name} 无效:\n$e');
268214
}
269215
}
270216
},
@@ -281,6 +227,7 @@ class _SettingPage extends State<SettingPage> {
281227
shape: BeveledRectangleBorder()
282228
),
283229
onPressed: (){
230+
context.read<Global>().uiLogger.info("跳转: SettingPage => QuestionsSettingLeadingPage");
284231
Navigator.of(context).push(MaterialPageRoute(builder: (context) => QuestionsSettingLeadingPage()));
285232
},
286233
child: Row(
@@ -298,6 +245,7 @@ class _SettingPage extends State<SettingPage> {
298245
shape: RoundedRectangleBorder(borderRadius: BorderRadiusGeometry.vertical(bottom: Radius.circular(25.0)))
299246
),
300247
onPressed: (){
248+
context.read<Global>().uiLogger.info("跳转: SettingPage => DataSyncPage");
301249
Navigator.of(context).push(MaterialPageRoute(builder: (context) => DataSyncPage()));
302250
},
303251
child: Row(
@@ -340,6 +288,7 @@ class _SettingPage extends State<SettingPage> {
340288
DropdownButton(
341289
value: set["audio"]["useBackupSource"],
342290
onChanged: (value) {
291+
context.read<Global>().uiLogger.info("更新音频接口: $value");
343292
if(value == 1) alart(context, "警告: \n来自\"TextReadTTS.com\"的音频不支持发音符号,且只能合成40字以内的文本。\n开启此功能请知悉。");
344293
set["audio"]["useBackupSource"] = value;
345294
context.read<Global>().updateSetting();
@@ -381,6 +330,7 @@ class _SettingPage extends State<SettingPage> {
381330
});
382331
},
383332
onChangeEnd: (value) {
333+
context.read<Global>().uiLogger.info("更新音频速度设置: $value");
384334
context.read<Global>().updateSetting();
385335
},
386336
),
@@ -424,6 +374,7 @@ class _SettingPage extends State<SettingPage> {
424374
shape: RoundedRectangleBorder(borderRadius: BorderRadiusGeometry.vertical(top: Radius.circular(25.0))),
425375
),
426376
onPressed: () {
377+
context.read<Global>().uiLogger.info("打开Github项目网站");
427378
launchUrl(Uri.parse("https://github.com/OctagonalStar/arabic_learning/"));
428379
},
429380
child: Row(
@@ -452,6 +403,7 @@ class _SettingPage extends State<SettingPage> {
452403
shape: RoundedRectangleBorder(borderRadius: BorderRadiusGeometry.vertical(bottom: Radius.circular(25.0))),
453404
),
454405
onPressed: () {
406+
context.read<Global>().uiLogger.info("跳转: SettingPage => AboutPage");
455407
Navigator.of(context).push(MaterialPageRoute(builder: (context) => AboutPage(setting: setting,)));
456408
},
457409
child: Row(

lib/pages/test_page.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:provider/provider.dart';
13

4+
import 'package:arabic_learning/vars/global.dart';
25
import 'package:arabic_learning/vars/statics_var.dart';
36
import 'package:arabic_learning/sub_pages_builder/test_pages/listening_test_page.dart';
4-
import 'package:flutter/material.dart';
57

68
class TestPage extends StatelessWidget {
79
const TestPage({super.key});
810
@override
911
Widget build(BuildContext context) {
12+
context.read<Global>().uiLogger.info("构建TestPage");
1013
final mediaQuery = MediaQuery.of(context);
1114
return Column(
1215
mainAxisAlignment: MainAxisAlignment.start,
@@ -23,6 +26,7 @@ class TestPage extends StatelessWidget {
2326
),
2427
),
2528
onPressed: () {
29+
context.read<Global>().uiLogger.info("跳转: TestPage => ForeListeningSettingPage");
2630
Navigator.push(
2731
context,
2832
MaterialPageRoute(

lib/sub_pages_builder/learning_pages/fsrs_pages.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ForeFSRSSettingPage extends StatelessWidget {
2525
}
2626
FSRS fsrs = FSRS();
2727
return FutureBuilder(
28-
future: fsrs.init(),
28+
future: fsrs.init(context: context),
2929
builder: (context, snapshot) {
3030
if (snapshot.connectionState == ConnectionState.waiting) {
3131
return Center(child: CircularProgressIndicator());
@@ -130,7 +130,7 @@ Widget difficultyButton(BuildContext context, String label, String subLabel, int
130130
if (getChosenScheme() == scheme) ElevatedButton.icon(
131131
icon: const Icon(Icons.arrow_forward, size: 24.0),
132132
onPressed: () async {
133-
await FSRS().createScheduler(scheme);
133+
await FSRS().createScheduler(scheme, context: context);
134134
if(!context.mounted) return;
135135
alart(context, "设置完成,重新进入规律学习页面即可开始", onConfirmed: (){Navigator.pop(context);});
136136
},

0 commit comments

Comments
 (0)