@@ -34,48 +34,8 @@ class LearningPage extends StatelessWidget {
3434 borderRadius: StaticsVar .br,
3535 ),
3636 ),
37- onPressed: () async {
38- final SharedPreferences prefs = await SharedPreferences .getInstance ();
39- final jsonString = prefs.getString ("tempConfig" ) ?? jsonEncode (StaticsVar .tempConfig);
40- final courseList = (jsonDecode (jsonString)["SelectedClasses" ] as List )
41- .cast <List >()
42- .map ((e) => e.cast <String >().toList ())
43- .toList ();
44- if (! context.mounted){
45- return ;
46- }
47- if (courseList.isEmpty){
48- ScaffoldMessenger .of (context).showSnackBar (
49- const SnackBar (
50- content: Text ('请先选择你要学习的课程' ),
51- duration: Duration (seconds: 2 ),
52- ),
53- );
54- Navigator .push (
55- context,
56- MaterialPageRoute (
57- builder: (context) => ChangeNotifierProvider (
58- create: (_) => ClassSelectModel ()..init (),
59- child: ClassSelector (),
60- ),
61- ),
62- );
63- return ;
64- }
65- PageCounterModel valSetter = PageCounterModel (courseList: courseList, wordData: context.read <Global >().wordData);
66- valSetter.init ();
67- await Navigator .push (
68- context,
69- MaterialPageRoute (
70- builder: (context) => ChangeNotifierProvider .value (
71- value: valSetter,
72- child: MixLearningPage ()
73- ),
74- ),
75- ) as List <String >? ;
76- if (valSetter.finished && context.mounted) {
77- context.read <Global >().saveLearningProgress (valSetter.selectedWords);
78- }
37+ onPressed: () {
38+ shiftToStudy (context, 0 );
7939 },
8040 child: Container (
8141 width: mediaQuery.size.width * 0.9 ,
@@ -114,7 +74,7 @@ class LearningPage extends StatelessWidget {
11474 ),
11575 ),
11676 onPressed: (){
117- // TODO: to ant-forget page
77+ // TODO: #5 to ant-forget page
11878 Navigator .push (
11979 context,
12080 MaterialPageRoute (
@@ -136,13 +96,7 @@ class LearningPage extends StatelessWidget {
13696 shape: RoundedRectangleBorder (borderRadius: BorderRadiusGeometry .vertical (top: Radius .circular (25.0 ))),
13797 ),
13898 onPressed: () {
139- // TODO: to arabic learning page
140- Navigator .push (
141- context,
142- MaterialPageRoute (
143- builder: (context) => InDevelopingPage ()
144- )
145- );
99+ shiftToStudy (context, 2 );
146100 },
147101 icon: Icon (Icons .arrow_back, size: 24.0 ),
148102 label: FittedBox (fit: BoxFit .fitWidth ,child: Text ("阿译中学习" , style: TextStyle (fontSize: 32.0 ))),
@@ -157,13 +111,7 @@ class LearningPage extends StatelessWidget {
157111 shape: RoundedRectangleBorder (borderRadius: BorderRadiusGeometry .vertical (bottom: Radius .circular (25.0 ))),
158112 ),
159113 onPressed: () {
160- // TODO: to arabic learning page
161- Navigator .push (
162- context,
163- MaterialPageRoute (
164- builder: (context) => InDevelopingPage ()
165- )
166- );
114+ shiftToStudy (context, 1 );
167115 },
168116 icon: Icon (Icons .arrow_forward, size: 24.0 ),
169117 label: FittedBox (fit: BoxFit .fitWidth ,child: Text ("中译阿学习" , style: TextStyle (fontSize: 32.0 ))),
@@ -208,14 +156,61 @@ class LearningPage extends StatelessWidget {
208156 }
209157}
210158
211- // 中阿混合学习主入口页面
212- class MixLearningPage extends StatefulWidget {
213- const MixLearningPage ({super .key});
159+
160+ void shiftToStudy (BuildContext context, int studyType) async {
161+ final SharedPreferences prefs = await SharedPreferences .getInstance ();
162+ final jsonString = prefs.getString ("tempConfig" ) ?? jsonEncode (StaticsVar .tempConfig);
163+ final courseList = (jsonDecode (jsonString)["SelectedClasses" ] as List )
164+ .cast <List >()
165+ .map ((e) => e.cast <String >().toList ())
166+ .toList ();
167+ if (! context.mounted){
168+ return ;
169+ }
170+ if (courseList.isEmpty){
171+ ScaffoldMessenger .of (context).showSnackBar (
172+ const SnackBar (
173+ content: Text ('请先选择你要学习的课程' ),
174+ duration: Duration (seconds: 2 ),
175+ ),
176+ );
177+ Navigator .push (
178+ context,
179+ MaterialPageRoute (
180+ builder: (context) => ChangeNotifierProvider (
181+ create: (_) => ClassSelectModel ()..init (),
182+ child: ClassSelector (),
183+ ),
184+ ),
185+ );
186+ return ;
187+ }
188+ PageCounterModel valSetter = PageCounterModel (courseList: courseList, wordData: context.read <Global >().wordData, isMixStudy: studyType == 0 );
189+ valSetter.init ();
190+ await Navigator .push (
191+ context,
192+ MaterialPageRoute (
193+ builder: (context) => ChangeNotifierProvider .value (
194+ value: valSetter,
195+ child: InLearningPage (studyType: studyType,)
196+ ),
197+ ),
198+ ) as List <String >? ;
199+ if (valSetter.finished && context.mounted) {
200+ context.read <Global >().saveLearningProgress (valSetter.selectedWords);
201+ }
202+ }
203+
204+
205+ // 学习主入口页面
206+ class InLearningPage extends StatefulWidget {
207+ final int studyType; // 0:Mix 1: 中译阿 2: 阿译中
208+ const InLearningPage ({super .key, required this .studyType});
214209 @override
215- State <MixLearningPage > createState () => _MixLearningPageState ();
210+ State <InLearningPage > createState () => _InLearningPageState ();
216211}
217212
218- class _MixLearningPageState extends State <MixLearningPage > {
213+ class _InLearningPageState extends State <InLearningPage > {
219214 Random rnd = Random ();
220215 List <int > testedAr = [];
221216 List <int > testedCh = [];
@@ -314,17 +309,23 @@ class _MixLearningPageState extends State<MixLearningPage> {
314309 List <int > selectedWords = context.read <PageCounterModel >().selectedWords; // 已选择的单词 [int: 在词库中的索引]
315310 int t = selectedWords[index]; // 正确答案在词库中的索引
316311 late bool testType; // true: 中文->阿拉伯, false: 阿拉伯->中文
317- if (testedAr.contains (t)) {
318- testType = true ;
319- } else if (testedCh.contains (t)){
320- testType = false ;
321- } else {
322- testType = rnd.nextBool ();
323- if (testType) {
324- testedCh.add (t);
312+ if (widget.studyType == 0 ) {
313+ if (testedAr.contains (t)) {
314+ testType = true ;
315+ } else if (testedCh.contains (t)){
316+ testType = false ;
325317 } else {
326- testedAr.add (t);
318+ testType = rnd.nextBool ();
319+ if (testType) {
320+ testedCh.add (t);
321+ } else {
322+ testedAr.add (t);
323+ }
327324 }
325+ } else if (widget.studyType == 1 ) {
326+ testType = true ;
327+ } else {
328+ testType = false ;
328329 }
329330 context.read <PageCounterModel >().currentType = testType;
330331 List <String > strList = [];
@@ -347,7 +348,7 @@ class _MixLearningPageState extends State<MixLearningPage> {
347348 rndLst.add (r);
348349 strList.add (wordData["Words" ][r][testType ? "arabic" : "chinese" ]);
349350 }
350- Widget widget = Column (
351+ Widget learningPageWidget = Column (
351352 mainAxisAlignment: MainAxisAlignment .center,
352353 children: questionConstructer (context,
353354 aindex,
@@ -359,8 +360,8 @@ class _MixLearningPageState extends State<MixLearningPage> {
359360 t.toString (),
360361 ],
361362 testType));
362- buildedCache.add (widget );
363- return widget ;
363+ buildedCache.add (learningPageWidget );
364+ return learningPageWidget ;
364365 },
365366 )
366367 )
0 commit comments