-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpaper_simulation_exam_page.dart
More file actions
159 lines (148 loc) · 6.26 KB
/
Copy pathpaper_simulation_exam_page.dart
File metadata and controls
159 lines (148 loc) · 6.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import 'dart:async';
import 'package:cap_countdown/src/exam/exam_subject.dart';
import 'package:cap_countdown/src/pages/exam/simulation_exam_page.dart';
import 'package:cap_countdown/src/util/layout.dart';
import 'package:flutter/material.dart';
import '../../../main.dart';
class PrepareSimulationExamPage extends StatefulWidget {
final int year;
final String examName;
final ExamSubject subject;
const PrepareSimulationExamPage(
{Key? key,
required this.year,
required this.examName,
required this.subject})
: super(key: key);
@override
State<PrepareSimulationExamPage> createState() =>
_PrepareSimulationExamPageState();
}
class _PrepareSimulationExamPageState extends State<PrepareSimulationExamPage> {
@override
void initState() {
super.initState();
Timer.periodic(const Duration(seconds: 5), (timer) {
if (!mounted) return timer.cancel();
// Update the left time
setState(() {});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('準備好了嗎?'),
actions: [
const Text("模擬試題設定"),
IconButton(
onPressed: () {
showDialog(
context: context,
builder: (context) {
return StatefulBuilder(builder: (context, setState) {
return AlertDialog(
insetPadding: const EdgeInsets.all(5),
contentPadding: const EdgeInsets.all(5),
title: ListTile(
title: const Text('模擬試題設定'),
leading: const Icon(Icons.edit),
shape: Border.all(color: Colors.transparent)),
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SwitchListTile(
value: localStorage.simulationExamTiming,
onChanged: (value) {
localStorage.simulationExamTiming = value;
setState(() {});
},
title: const Text('作答時間倒計時'),
subtitle: const Text(
'若啟用則有作答時間限制,在該科作答時間結束後強制交卷;反之則無此限制。')),
SwitchListTile(
value:
localStorage.simulationExamShowAnsBtn,
onChanged: (value) {
localStorage.simulationExamShowAnsBtn =
value;
setState(() {});
},
title: const Text('即時對答案'),
subtitle: const Text(
'為每道試題增加一個「對答案」答案按鈕,可單獨提交該題答案,並查看詳解。'))
])),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: const Text('確定'))
],
);
});
});
},
icon: const Icon(Icons.settings))
],
),
body: Stack(
children: [
Padding(
padding: const EdgeInsets.all(15),
child: ResponsiveLayout(builder: (context, breakpoint) {
return Column(
children: [
Image.asset('assets/images/materials/awards.png',
height: breakpoint.isPad
? MediaQuery.of(context).size.height * 0.6
: null),
const SizedBox(height: 12),
_buildDescriptionText(),
const Divider(),
Text('準備好紙筆,點下方按鈕就立即開始囉!\n加油!',
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.bodyLarge),
],
);
}),
),
Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: const EdgeInsets.all(20.0),
child: FloatingActionButton.extended(
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => SimulationExamPage(
year: widget.year,
examName: widget.examName,
subject: widget.subject,
)));
},
label: const Text('開始測驗', style: TextStyle(fontSize: 18)),
),
),
)
],
),
);
}
Column _buildDescriptionText() {
final optionalQuestionLength = widget.subject.getOptionalQuestions().length;
final now = DateTime.now().toLocal();
final end = now.add(widget.subject.duration);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'這是 ${widget.examName}${widget.subject.name}試題,共有 $optionalQuestionLength 題選擇題,每題都只有一個正確或最佳的答案。',
style: Theme.of(context).textTheme.bodyLarge),
Text(
'測驗時間從 ${now.hour.toString().padLeft(2, '0')}:${now.minute.toString().padLeft(2, '0')} 到 ${end.hour.toString().padLeft(2, '0')}:${end.minute.toString().padLeft(2, '0')},共 ${widget.subject.duration.inMinutes} 分鐘。',
style: Theme.of(context).textTheme.bodyLarge),
],
);
}
}