Skip to content

Commit 72ee519

Browse files
committed
complete TODO #ATC & #CTA learning
add number for todos TAG 0.1.5
1 parent dbf8345 commit 72ee519

File tree

4 files changed

+83
-81
lines changed

4 files changed

+83
-81
lines changed

lib/change_notifier_models.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import 'package:shared_preferences/shared_preferences.dart';
77
class PageCounterModel extends ChangeNotifier {
88
List<List<String>> courseList;
99
Map<String, dynamic> wordData;
10-
PageCounterModel({required this.courseList, required this.wordData});
10+
bool isMixStudy;
11+
PageCounterModel({required this.courseList, required this.wordData, required this.isMixStudy});
1112

1213

1314
int _currentPage = 0;
@@ -37,7 +38,7 @@ class PageCounterModel extends ChangeNotifier {
3738
for(List<String> c in courseList) {
3839
selectedWords.addAll(wordData["Classes"][c[0]][c[1]].cast<int>());
3940
}
40-
selectedWords = [...selectedWords, ...selectedWords];
41+
if(isMixStudy) selectedWords = [...selectedWords, ...selectedWords];
4142
selectedWords.shuffle();
4243
}
4344

lib/learning_page.dart

Lines changed: 75 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -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
)

lib/test_page.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class TestPage extends StatelessWidget {
2929
),
3030
),
3131
onPressed: () {
32-
// TODO: to write test page
32+
// TODO: #3 to write test page
3333
Navigator.push(
3434
context,
3535
MaterialPageRoute(
@@ -68,7 +68,7 @@ class TestPage extends StatelessWidget {
6868
),
6969
),
7070
onPressed: () {
71-
// TODO: to listen test page
71+
// TODO: #7 to listen test page
7272
Navigator.push(
7373
context,
7474
MaterialPageRoute(
@@ -113,7 +113,7 @@ class TestPage extends StatelessWidget {
113113
),
114114
),
115115
onPressed: () {
116-
// TODO: to history page
116+
// TODO: #4 to history page
117117
Navigator.push(
118118
context,
119119
MaterialPageRoute(
@@ -147,7 +147,7 @@ class TestPage extends StatelessWidget {
147147
),
148148
),
149149
onPressed: () {
150-
// TODO: to keyboard page
150+
// TODO: #6 to keyboard page
151151
Navigator.push(
152152
context,
153153
MaterialPageRoute(

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
1616
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
1717
# In Windows, build-name is used as the major, minor, and patch parts
1818
# of the product and file versions while build-number is used as the build suffix.
19-
version: 0.1.1+2
19+
version: 0.1.5+1
2020

2121
environment:
2222
sdk: ^3.9.2

0 commit comments

Comments
 (0)