11import '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+
29import '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' ;
312import 'package:arabic_learning/sub_pages_builder/setting_pages/about_page.dart' show AboutPage;
413import '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' ;
614import 'package:arabic_learning/sub_pages_builder/setting_pages/model_download_page.dart' show ModelDownload;
715import 'package:arabic_learning/sub_pages_builder/setting_pages/questions_setting_page.dart' show QuestionsSettingLeadingPage;
816import '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' ;
1517import 'package:arabic_learning/package_replacement/fake_dart_io.dart' if (dart.library.io) 'dart:io' as io;
1618
1719class SettingPage extends StatefulWidget {
@@ -23,6 +25,7 @@ class SettingPage extends StatefulWidget {
2325class _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 (
0 commit comments