11import 'dart:convert' ;
22import 'dart:ui' ;
3- import 'package:arabic_learning/vars/global.dart' ;
4- import 'package:arabic_learning/vars/statics_var.dart' ;
3+
54import 'package:flutter/material.dart' ;
65import 'package:provider/provider.dart' ;
7- import 'utili.dart' ;
6+
7+ import 'package:arabic_learning/vars/global.dart' ;
8+ import 'package:arabic_learning/vars/statics_var.dart' ;
9+ import 'package:arabic_learning/funcs/utili.dart' ;
810
911// 该文件主要包含了对于UI有关的函数及多次在不同地方使用的Widget类或者函数
1012
@@ -34,20 +36,22 @@ import 'utili.dart';
3436/// List<Map<String, dynamic>> words = getSelectedWords(context , forceSelectClasses: value);
3537/// ```
3638Future <List <List <String >>> popSelectClasses (BuildContext context, {bool withCache = false }) async {
39+ context.read <Global >().uiLogger.info ("弹出课程选择(ClassSelectPage),withCache: $withCache " );
3740 late final List <List <String >> beforeSelectedClasses;
3841 if (withCache) {
3942 final String tpcPrefs = context.read <Global >().prefs.getString ("tempConfig" ) ?? jsonEncode (StaticsVar .tempConfig);
4043 beforeSelectedClasses = (jsonDecode (tpcPrefs)["SelectedClasses" ] as List )
4144 .cast <List >()
4245 .map ((e) => e.cast <String >().toList ())
4346 .toList ();
47+ context.read <Global >().uiLogger.fine ("已缓存课程选择: $beforeSelectedClasses " );
4448 } else {
4549 beforeSelectedClasses = [];
4650 }
4751 List <List <String >>? selectedClasses = await showModalBottomSheet <List <List <String >>>(
4852 context: context,
4953 // 假装圆角... :)
50- shape: RoundedSuperellipseBorder (side: BorderSide (width: 1.0 , color: Theme .of (context).colorScheme.onSurface.withAlpha (150 )), borderRadius: StaticsVar .br),
54+ shape: RoundedRectangleBorder (side: BorderSide (width: 1.0 , color: Theme .of (context).colorScheme.onSurface.withAlpha (150 )), borderRadius: StaticsVar .br),
5155 isDismissible: false ,
5256 isScrollControlled: context.read <Global >().isWideScreen,
5357 enableDrag: true ,
@@ -60,7 +64,9 @@ Future<List<List<String>>> popSelectClasses(BuildContext context, {bool withCach
6064 Map <String , dynamic > tpcMap = jsonDecode (tpcPrefs);
6165 tpcMap["SelectedClasses" ] = selectedClasses;
6266 context.read <Global >().prefs.setString ("tempConfig" , jsonEncode (tpcMap));
67+ context.read <Global >().uiLogger.info ("课程选择缓存完成" );
6368 }
69+ if (context.mounted) context.read <Global >().uiLogger.fine ("选择的课程: $selectedClasses " );
6470 return selectedClasses ?? [];
6571}
6672
@@ -76,7 +82,8 @@ Future<List<List<String>>> popSelectClasses(BuildContext context, {bool withCach
7682/// [isClassSelected] :需要一个函数判断该课程是否被选中
7783///
7884/// 一般情况下该函数只会在 [ClassSelectPage] 中被使用,若非必要你不应该使用此函数
79- List <Widget > classesSelectionList (BuildContext context, MediaQueryData mediaQuery, Function (List <String >) onChanged, bool Function (List <String >) isClassSelected) {
85+ List <Widget > classesSelectionList (BuildContext context, Function (List <String >) onChanged, bool Function (List <String >) isClassSelected) {
86+ context.read <Global >().uiLogger.fine ("构建课程选择列表" );
8087 Map <String , dynamic > wordData = context.read <Global >().wordData;
8188 List <Widget > widgetList = [];
8289 for (String sourceName in wordData["Classes" ].keys) {
@@ -125,10 +132,12 @@ List<Widget> classesSelectionList(BuildContext context, MediaQueryData mediaQuer
125132 }
126133 }
127134 if (widgetList.isEmpty) {
135+ context.read <Global >().uiLogger.warning ("用户未导入可用词库" );
128136 widgetList.add (
129137 Center (child: Text ('啥啥词库都没导入,你学个啥呢?\n 自己去 设置 -> 数据设置 -> 导入词库' , style: TextStyle (fontSize: 24.0 , color: Colors .redAccent),))
130138 );
131139 }
140+ context.read <Global >().uiLogger.info ("课程选择列表构建完成" );
132141 return widgetList;
133142}
134143
@@ -149,7 +158,8 @@ List<Widget> classesSelectionList(BuildContext context, MediaQueryData mediaQuer
149158/// alart(context, "你点击了按钮",onConfirmed: (){i++}, delayConfirm: Duration(seconds: 1));
150159/// }
151160/// ```
152- void alart (context, String e, {Function ? onConfirmed, Duration delayConfirm = const Duration (milliseconds: 0 )}) {
161+ void alart (BuildContext context, String e, {Function ? onConfirmed, Duration delayConfirm = const Duration (milliseconds: 0 )}) {
162+ context.read <Global >().uiLogger.info ("构建弹出窗口: 携带信息: $e ;确认参数: ${onConfirmed != null }; 延迟: ${delayConfirm .inMilliseconds }" );
153163 showDialog (
154164 context: context,
155165 builder: (BuildContext context) {
@@ -179,6 +189,39 @@ void alart(context, String e, {Function? onConfirmed, Duration delayConfirm = co
179189 );
180190}
181191
192+ /// 弹出详解页面
193+ void viewAnswer (BuildContext context, Map <String , dynamic > wordData) async {
194+ context.read <Global >().uiLogger.info ("弹出详解页面" );
195+ MediaQueryData mediaQuery = MediaQuery .of (context);
196+ showBottomSheet (
197+ context: context,
198+ shape: RoundedSuperellipseBorder (side: BorderSide (width: 1.0 , color: Theme .of (context).colorScheme.onSurface), borderRadius: StaticsVar .br),
199+ enableDrag: true ,
200+ builder: (context) {
201+ return Container (
202+ padding: EdgeInsets .only (top: mediaQuery.size.height * 0.05 ),
203+ decoration: BoxDecoration (
204+ color: Theme .of (context).colorScheme.onPrimary,
205+ borderRadius: StaticsVar .br,
206+ ),
207+ child: Column (
208+ children: [
209+ Expanded (child: WordCard (word: wordData)),
210+ ElevatedButton (
211+ onPressed: () {Navigator .pop (context);},
212+ style: ElevatedButton .styleFrom (
213+ fixedSize: Size (mediaQuery.size.width * 0.8 , mediaQuery.size.height * 0.1 ),
214+ shape: RoundedRectangleBorder (borderRadius: StaticsVar .br)
215+ ),
216+ child: Text ("我知道了" ),
217+ )
218+ ],
219+ ),
220+ );
221+ },
222+ );
223+ }
224+
182225// Base Widgets 较为基础的Widget
183226
184227/// 文本框容器
@@ -537,7 +580,7 @@ class ClassSelectPage extends StatelessWidget {
537580 children: [
538581 Expanded (
539582 child: ListView (
540- children: classesSelectionList (context, mediaQuery, onClassChanged, isClassSelected)
583+ children: classesSelectionList (context, onClassChanged, isClassSelected)
541584 ),
542585 ),
543586 ElevatedButton (
@@ -653,13 +696,16 @@ class _ChoiceQuestions extends State<ChoiceQuestions> {
653696
654697 @override
655698 Widget build (BuildContext context) {
699+ context.read <Global >().uiLogger.info ("构建选择题页面: 主单词: ${widget .mainWord };选项: ${widget .choices }" );
656700 MediaQueryData mediaQuery = MediaQuery .of (context);
657701 int showingMode = widget.bottonLayout;
658702 // showingMode 0: 1 Row, 1: 2 Rows, 2: 4 Rows
659703 if (showingMode == - 1 ){
704+ context.read <Global >().uiLogger.fine ("未指定布局,开始计算" );
660705 bool overFlowPossible = false ;
661706 for (int i = 1 ; i < 4 ; i++ ) {
662707 if (widget.choices[i].length * 16 > mediaQuery.size.width * (context.read <Global >().isWideScreen ? 0.21 : 0.8 )){
708+ context.read <Global >().uiLogger.fine ("在 [${widget .choices [i ]}] 可能溢出,采用密集布局" );
663709 overFlowPossible = true ;
664710 break ;
665711 }
@@ -678,6 +724,7 @@ class _ChoiceQuestions extends State<ChoiceQuestions> {
678724 showingMode = 1 ;
679725 }
680726 }
727+ context.read <Global >().uiLogger.info ("最终采用布局方案: $showingMode " );
681728 }
682729 return Material (
683730 child: Center (
@@ -696,6 +743,7 @@ class _ChoiceQuestions extends State<ChoiceQuestions> {
696743 ),
697744 onPressed: () async {
698745 if (playing || ! widget.allowAudio) {
746+ context.read <Global >().uiLogger.warning ("${playing ? "正在播放" : "不准许音频" },中断TTS" );
699747 return ;
700748 }
701749 setLocalState (() {
@@ -759,6 +807,7 @@ class WordCardQuestion extends StatelessWidget {
759807
760808 @override
761809 Widget build (BuildContext context) {
810+ context.read <Global >().uiLogger.info ("构建单词卡片页面,主单词: ${word ["arabic" ]}" );
762811 MediaQueryData mediaQuery = MediaQuery .of (context);
763812 return Material (
764813 child: Column (
@@ -804,6 +853,7 @@ class _SpellQuestion extends State<SpellQuestion> {
804853
805854 @override
806855 Widget build (BuildContext context) {
856+ context.read <Global >().uiLogger.info ("构建拼写题页面,主单词: ${widget .word ["arabic" ]}" );
807857 MediaQueryData mediaQuery = MediaQuery .of (context);
808858 return Material (
809859 child: Column (
@@ -854,6 +904,7 @@ class _SpellQuestion extends State<SpellQuestion> {
854904 SizedBox (height: mediaQuery.size.height * 0.05 ),
855905 ElevatedButton (
856906 onPressed: () {
907+ context.read <Global >().uiLogger.info ("提交单词检查: [${controller .text }]" );
857908 check (controller.text);
858909 },
859910 style: ElevatedButton .styleFrom (
0 commit comments