84 if (questions.isEmpty) {
88 .
translate(
'No questions available for this course'),
89 style: Theme.of(context).textTheme.bodyMedium,
99 crossAxisAlignment: CrossAxisAlignment.start,
102 LinearProgressIndicator(
105 valueColor: AlwaysStoppedAnimation<Color>(
106 Theme.of(context).primaryColor,
108 borderRadius: BorderRadius.circular(4.r),
111 SizedBox(height: 8.r),
113 mainAxisAlignment: MainAxisAlignment.spaceBetween,
116 '${AppLocalizations.of(context).translate('Question
')} ${_currentQuestionIndex + 1} of ${questions.length}',
117 style: Theme.of(context).textTheme.bodySmall?.copyWith(
118 color: Theme.of(context).hintColor,
122 '${((_currentQuestionIndex + 1) / questions.length * 100).toInt()}%',
123 style: Theme.of(context).textTheme.displaySmall?.copyWith(
124 color: Theme.of(context).colorScheme.primary,
129 SizedBox(height: 24.r),
133 currentQuestion.question ??
135 style: Theme.of(context).textTheme.displaySmall,
137 SizedBox(height: 24.r),
141 child: ListView.separated(
142 itemCount: currentQuestion.options?.length ?? 0,
143 separatorBuilder: (context, index) => SizedBox(height: 12.r),
144 itemBuilder: (context, index) {
147 return GestureDetector(
155 decoration: BoxDecoration(
157 ? Theme.of(context).primaryColor.withOpacity(0.1)
158 : Colors.transparent,
159 borderRadius: BorderRadius.circular(10.r),
166 decoration: BoxDecoration(
167 shape: BoxShape.circle,
169 ? Theme.of(context).primaryColor
170 : Colors.transparent,
173 ? Theme.of(context).primaryColor
174 : Theme.of(context).hintColor,
183 Theme.of(context).colorScheme.onPrimary,
187 SizedBox(width: 12.r),
190 currentQuestion.options?[index] ??
'',
191 style: Theme.of(context).textTheme.bodyMedium,
203 SizedBox(height: 16.r),
205 mainAxisAlignment: MainAxisAlignment.spaceBetween,
214 style: ElevatedButton.styleFrom(
215 padding: EdgeInsets.symmetric(horizontal: 20, vertical: 15),
216 shape: RoundedRectangleBorder(
217 borderRadius: BorderRadius.circular(200),
224 SizedBox(width: 100.r),
226 style: ElevatedButton.styleFrom(
227 padding: EdgeInsets.symmetric(horizontal: 20, vertical: 15),
228 shape: RoundedRectangleBorder(
229 borderRadius: BorderRadius.circular(200),
234 if (_currentQuestionIndex < questions.length - 1) {
236 _currentQuestionIndex++;
240 int correctAnswers = 0;
241 for (int i = 0; i < questions.length; i++) {
242 if (_userAnswers[i] ==
243 questions[i].correctAnswerIndex) {
248 _score = correctAnswers / questions.length;
274 (entry) => entry.value == questions[entry.key].correctAnswerIndex,
281 crossAxisAlignment: CrossAxisAlignment.center,
283 SizedBox(height: 24.r),
289 decoration: BoxDecoration(
290 shape: BoxShape.circle,
291 color: Theme.of(context).primaryColor.withOpacity(0.1),
295 mainAxisAlignment: MainAxisAlignment.center,
298 '${(_score * 100).toInt()}%',
299 style: Theme.of(context).textTheme.displayLarge?.copyWith(
300 color: Theme.of(context).primaryColor,
305 style: Theme.of(context).textTheme.bodyLarge,
311 SizedBox(height: 30.r),
317 style: Theme.of(context).textTheme.displayMedium,
320 SizedBox(height: 15.r),
322 '${AppLocalizations.of(context).translate('You answered
')} $correctAnswers ${AppLocalizations.of(context).translate('out
of')} ${questions.length} ${AppLocalizations.of(context).translate('questions correctly
')}',
323 style: Theme.of(context).textTheme.bodyMedium?.copyWith(
324 color: Theme.of(context).hintColor,
326 textAlign: TextAlign.center,
328 SizedBox(height: 32.r),
334 _quizCompleted = false;
335 _currentQuestionIndex = 0;
338 style: ElevatedButton.styleFrom(
343 shape: RoundedRectangleBorder(
344 borderRadius: BorderRadius.circular(200),
347 foregroundColor: Theme.of(context).primaryColor.withOpacity(0.8),
349 icon: Icon(Icons.refresh),
354 SizedBox(height: 16.r),
359 widget.onComplete(_score);
360 Navigator.pop(context);
362 style: ElevatedButton.styleFrom(
369 shape: RoundedRectangleBorder(
370 borderRadius: BorderRadius.circular(200),
373 icon: Icon(Icons.check_circle),