82 if (questions.isEmpty) {
85 'No questions available for this course',
86 style: Theme.of(context).textTheme.bodyMedium,
96 crossAxisAlignment: CrossAxisAlignment.start,
99 LinearProgressIndicator(
101 backgroundColor: Colors.grey.withValues(alpha: 0.2),
102 valueColor: AlwaysStoppedAnimation<Color>(
103 Theme.of(context).primaryColor,
105 borderRadius: BorderRadius.circular(4.r),
110 mainAxisAlignment: MainAxisAlignment.spaceBetween,
113 'Question ${_currentQuestionIndex + 1} of ${questions.length}',
114 style: Theme.of(context).textTheme.bodySmall?.copyWith(
115 color: Theme.of(context).hintColor,
119 '${((_currentQuestionIndex + 1) / questions.length * 100).toInt()}%',
120 style: Theme.of(context).textTheme.displaySmall?.copyWith(
121 color: Theme.of(context).colorScheme.primary,
130 currentQuestion.question ??
'No question text',
131 style: Theme.of(context).textTheme.displaySmall,
137 child: ListView.separated(
138 itemCount: currentQuestion.options?.length ?? 0,
139 separatorBuilder: (context, index) =>
SizedBox(height: 12.r),
140 itemBuilder: (context, index) {
143 return GestureDetector(
151 decoration: BoxDecoration(
153 ? Theme.of(context).primaryColor.withValues(alpha: 0.1)
154 : Colors.transparent,
155 borderRadius: BorderRadius.circular(10.r),
162 decoration: BoxDecoration(
163 shape: BoxShape.circle,
165 ? Theme.of(context).primaryColor
166 : Colors.transparent,
169 ? Theme.of(context).primaryColor
170 : Theme.of(context).hintColor,
179 Theme.of(context).colorScheme.onPrimary,
186 currentQuestion.options?[index] ??
'',
187 style: Theme.of(context).textTheme.bodyMedium,
201 mainAxisAlignment: MainAxisAlignment.spaceBetween,
210 style: ElevatedButton.styleFrom(
211 padding: EdgeInsets.symmetric(horizontal: 20, vertical: 15),
212 shape: RoundedRectangleBorder(
213 borderRadius: BorderRadius.circular(200),
221 style: ElevatedButton.styleFrom(
222 padding: EdgeInsets.symmetric(horizontal: 20, vertical: 15),
223 shape: RoundedRectangleBorder(
224 borderRadius: BorderRadius.circular(200),
229 if (_currentQuestionIndex < questions.length - 1) {
231 _currentQuestionIndex++;
235 int correctAnswers = 0;
236 for (int i = 0; i < questions.length; i++) {
237 if (_userAnswers[i] ==
238 questions[i].correctAnswerIndex) {
243 _score = correctAnswers / questions.length;
269 (entry) => entry.value == questions[entry.key].correctAnswerIndex,
276 crossAxisAlignment: CrossAxisAlignment.center,
284 decoration: BoxDecoration(
285 shape: BoxShape.circle,
286 color: Theme.of(context).primaryColor.withValues(alpha: 0.1),
290 mainAxisAlignment: MainAxisAlignment.center,
293 '${(_score * 100).toInt()}%',
294 style: Theme.of(context).textTheme.displayLarge?.copyWith(
295 color: Theme.of(context).primaryColor,
300 style: Theme.of(context).textTheme.bodyLarge,
312 style: Theme.of(context).textTheme.displayMedium,
317 'You answered $correctAnswers out of ${questions.length} questions correctly.',
318 style: Theme.of(context).textTheme.bodyMedium?.copyWith(
319 color: Theme.of(context).hintColor,
321 textAlign: TextAlign.center,
329 _quizCompleted = false;
330 _currentQuestionIndex = 0;
333 style: ElevatedButton.styleFrom(
338 shape: RoundedRectangleBorder(
339 borderRadius: BorderRadius.circular(200),
341 backgroundColor: Theme.of(context).primaryColor.withValues(alpha: 0.11),
342 foregroundColor: Theme.of(context).primaryColor.withValues(alpha: 0.8),
344 icon: Icon(Icons.refresh),
352 widget.onComplete(_score);
353 Navigator.pop(context);
355 style: ElevatedButton.styleFrom(
361 backgroundColor: Theme.of(context).primaryColor,
362 shape: RoundedRectangleBorder(
363 borderRadius: BorderRadius.circular(200),
366 icon: Icon(Icons.check_circle),
style Column(crossAxisAlignment:CrossAxisAlignment.end, children:[Container(padding:EdgeInsets.symmetric(horizontal:8.w, vertical:4.h), decoration:BoxDecoration(color:ColorPalette.tiffanyBlue.withValues(alpha:0.1), borderRadius:BorderRadius.circular(12),), child:Text(collection.type ?? '', style:Theme.of(context).textTheme.bodySmall?.copyWith(color:ColorPalette.tiffanyBlue, fontWeight:FontWeight.bold,),),),],)