// ignore_for_file: must_be_immutable import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:ui/routes/app_routes.dart'; import 'package:ui/views/siswa/quiz/controllers/quiz_finish_controller.dart'; class SoalQuizSelesai extends StatelessWidget { SoalQuizSelesai({super.key}); QuizFinishController quizFinishC = Get.find(); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text("Quiz Selesai"), backgroundColor: Colors.green.shade600, foregroundColor: Colors.white, ), body: Padding( padding: const EdgeInsets.all(16.0), child: Container( width: double.infinity, decoration: BoxDecoration( color: Colors.green.shade300, borderRadius: BorderRadius.circular(30), ), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ // Container utama untuk hasil quiz Container( margin: const EdgeInsets.all(20), padding: const EdgeInsets.all(20), width: double.infinity, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(20), boxShadow: [ BoxShadow( color: Colors.black.withOpacity(0.1), blurRadius: 10, offset: const Offset(0, 5), ), ], ), child: Obx( () { if (quizFinishC.isLoading.value) { return const Center( child: CircularProgressIndicator(), ); } var data = quizFinishC.quizAttemptM?.data; if (data == null) { return const Center( child: Text( 'Data tidak tersedia', style: TextStyle( fontSize: 16, fontWeight: FontWeight.bold, ), ), ); } // Validasi agar benar + salah = total soal int totalSoal = int.tryParse(data.jumlahSoal) ?? 0; int jawabanBenar = int.tryParse(data.jawabanBenar) ?? 0; int jawabanSalah = int.tryParse(data.jawabanSalah) ?? 0; if (jawabanBenar + jawabanSalah != totalSoal) { jawabanSalah = totalSoal - jawabanBenar; } return Column( mainAxisAlignment: MainAxisAlignment.center, children: [ // Header dengan icon Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Icon( Icons.emoji_events, size: 32, color: Colors.amber.shade600, ), const SizedBox(width: 10), const Text( 'HASIL QUIZ', style: TextStyle( fontSize: 24, fontWeight: FontWeight.bold, color: Colors.black87, ), ), ], ), const SizedBox(height: 20), // Statistik pengerjaan Container( width: Get.width, decoration: BoxDecoration( color: const Color.fromARGB(255, 241, 235, 224), borderRadius: BorderRadius.circular(20), ), child: Padding( padding: const EdgeInsets.all(16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ const Text( 'Statistik Pengerjaan', style: TextStyle( fontSize: 16, fontWeight: FontWeight.bold, color: Colors.black87, ), ), const SizedBox(height: 12), Text( 'Total Soal Quiz: ${data.jumlahSoal}', style: const TextStyle( fontSize: 16, fontWeight: FontWeight.bold, color: Colors.black87, ), ), const SizedBox(height: 12), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Expanded( child: Container( decoration: BoxDecoration( color: const Color(0xFF9CFFBA), borderRadius: BorderRadius.circular(15), ), padding: const EdgeInsets.symmetric( horizontal: 8, vertical: 8, ), child: Column( children: [ const Icon( Icons.check_circle, color: Colors.green, size: 24, ), const SizedBox(height: 4), Text( "${jawabanBenar}", style: const TextStyle( fontSize: 18, fontWeight: FontWeight.bold, color: Colors.green, ), ), const Text( "Benar", style: TextStyle( fontSize: 12, fontWeight: FontWeight.w500, color: Colors.green, ), ), ], ), ), ), const SizedBox(width: 12), Expanded( child: Container( decoration: BoxDecoration( color: const Color(0xFFFF8D85), borderRadius: BorderRadius.circular(15), ), padding: const EdgeInsets.symmetric( horizontal: 8, vertical: 8, ), child: Column( children: [ const Icon( Icons.cancel, color: Colors.red, size: 24, ), const SizedBox(height: 4), Text( "${jawabanSalah}", style: const TextStyle( fontSize: 18, fontWeight: FontWeight.bold, color: Colors.red, ), ), const Text( "Salah", style: TextStyle( fontSize: 12, fontWeight: FontWeight.w500, color: Colors.red, ), ), ], ), ), ), ], ), ], ), ), ), const SizedBox(height: 20), // Skor utama Container( padding: const EdgeInsets.all(20), decoration: BoxDecoration( gradient: const LinearGradient( begin: Alignment.topLeft, end: Alignment.bottomRight, colors: [ Color(0xFF667EEA), Color(0xFF764BA2), ], ), borderRadius: BorderRadius.circular(20), boxShadow: [ BoxShadow( color: const Color(0xFF667EEA).withOpacity(0.3), blurRadius: 20, offset: const Offset(0, 10), ), ], ), child: Column( children: [ const Text( 'Skor Anda', style: TextStyle( color: Colors.white70, fontSize: 16, fontFamily: 'Poppins', ), ), const SizedBox(height: 10), Text( data.skor, style: const TextStyle( color: Colors.white, fontSize: 36, fontWeight: FontWeight.bold, ), ), ], ), ), ], ); }, ), ), const SizedBox(height: 40), // Tombol Kembali ElevatedButton( onPressed: () { Get.offAllNamed(AppRoutes.siswaDashboard); }, style: ElevatedButton.styleFrom( backgroundColor: Colors.white, foregroundColor: Colors.black, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(20), ), padding: const EdgeInsets.symmetric(horizontal: 50, vertical: 15), ), child: const Text( 'Kembali', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), ), ), ], ), ), ), ); } }