fix: update base URLs in constants and clean up unused code in various files

This commit is contained in:
Resh 2025-04-16 11:00:33 +07:00
parent 7ba660a4eb
commit db1a76cd80
5 changed files with 11 additions and 110 deletions

View File

@ -1,3 +1,3 @@
const String baseUrl = 'https://api.seals.id/'; const String baseUrl = 'http://labai.polinema.ac.id:3001/';
const String mediaUrl = 'https://api.seals.id/api/uploads/'; const String mediaUrl = 'http://labai.polinema.ac.id:3001/api/uploads/';

View File

@ -21,11 +21,9 @@ class ProgressCard extends StatelessWidget {
Future<void> _navigateToTopics( Future<void> _navigateToTopics(
BuildContext context, CompletedTopic topic) async { BuildContext context, CompletedTopic topic) async {
// Get the SectionProvider
final sectionProvider = final sectionProvider =
Provider.of<SectionProvider>(context, listen: false); Provider.of<SectionProvider>(context, listen: false);
// Show loading indicator while checking/loading data
showDialog( showDialog(
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,
@ -35,7 +33,6 @@ class ProgressCard extends StatelessWidget {
); );
try { try {
// If sections aren't loaded yet, load them
if (sectionProvider.sections.isEmpty) { if (sectionProvider.sections.isEmpty) {
final userProvider = Provider.of<UserProvider>(context, listen: false); final userProvider = Provider.of<UserProvider>(context, listen: false);
final token = await userProvider.getValidToken(); final token = await userProvider.getValidToken();
@ -47,10 +44,8 @@ class ProgressCard extends StatelessWidget {
} }
} }
// Remove loading indicator
Navigator.pop(context); Navigator.pop(context);
// Navigate to topics screen
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
@ -60,10 +55,8 @@ class ProgressCard extends StatelessWidget {
), ),
); );
} catch (e) { } catch (e) {
// Remove loading indicator
Navigator.pop(context); Navigator.pop(context);
// Show error dialog
showDialog( showDialog(
context: context, context: context,
builder: (context) => AlertDialog( builder: (context) => AlertDialog(

View File

@ -34,81 +34,6 @@ class _MatchingPairsQuestionState extends State<MatchingPairsQuestion> {
initializePairs(); initializePairs();
} }
// void initializePairs() {
// pairs = [];
// studentAnswers = {};
// originalPairMapping = {};
// originalPairIndices = {};
// if (widget.exercise is ExerciseModel) {
// // Mode Exercise
// pairs = (widget.exercise.choices as MatchingPair).pairs;
// final provider = Provider.of<ExerciseProvider>(context, listen: false);
// final currentIndex = provider.currentExerciseIndex;
// // Simpan indeks asli untuk setiap pasangan kiri
// for (int i = 0; i < pairs.length; i++) {
// originalPairIndices[pairs[i].left] = i;
// }
// originalRightPairs = pairs.map((pair) => pair.right as String).toList();
// shuffledRightPairs =
// List<String>.from(provider.shuffledRightPairsList[currentIndex]);
// } else if (widget.exercise is ReviewExerciseDetail) {
// // Mode Review
// if (widget.exercise.matchingPairs != null) {
// if (widget.exercise.answerStudent.isNotEmpty) {
// final answerPairs = widget.exercise.answerStudent.split(', ');
// // Buat pairs berdasarkan urutan jawaban siswa
// pairs = answerPairs.map((pair) {
// final parts = pair.split('-');
// return Pair(left: parts[0], right: parts[1]);
// }).toList();
// // Simpan indeks asli dan mapping untuk setiap pasangan
// for (int i = 0; i < pairs.length; i++) {
// final left = pairs[i].left;
// final right = pairs[i].right;
// originalPairIndices[left] = i;
// studentAnswers[left] = right;
// originalPairMapping[left] = right;
// }
// // Set originalRightPairs dan shuffledRightPairs sama dengan urutan jawaban siswa
// originalRightPairs =
// pairs.map((pair) => pair.right as String).toList();
// shuffledRightPairs =
// originalRightPairs.toList(); // Tidak diacak untuk review
// } else {
// // Jika tidak ada jawaban, gunakan data asli
// pairs = widget.exercise.matchingPairs!.map((reviewPair) {
// return Pair(
// left: reviewPair.leftPair,
// right: reviewPair.rightPair,
// );
// }).toList();
// // Simpan indeks asli untuk setiap pasangan
// for (int i = 0; i < pairs.length; i++) {
// originalPairIndices[pairs[i].left] = i;
// }
// originalRightPairs =
// pairs.map((pair) => pair.right as String).toList();
// shuffledRightPairs = originalRightPairs.toList();
// }
// }
// }
// // Bangun pemetaan konsisten
// for (int i = 0; i < pairs.length; i++) {
// final left = pairs[i].left;
// final right = pairs[i].right;
// originalPairMapping[left] = right;
// }
// }
void initializePairs() { void initializePairs() {
pairs = []; pairs = [];
studentAnswers = {}; studentAnswers = {};
@ -116,12 +41,10 @@ class _MatchingPairsQuestionState extends State<MatchingPairsQuestion> {
originalPairIndices = {}; originalPairIndices = {};
if (widget.exercise is ExerciseModel) { if (widget.exercise is ExerciseModel) {
// Mode Exercise
pairs = (widget.exercise.choices as MatchingPair).pairs; pairs = (widget.exercise.choices as MatchingPair).pairs;
final provider = Provider.of<ExerciseProvider>(context, listen: false); final provider = Provider.of<ExerciseProvider>(context, listen: false);
final currentIndex = provider.currentExerciseIndex; final currentIndex = provider.currentExerciseIndex;
// Simpan indeks asli untuk setiap pasangan kiri
for (int i = 0; i < pairs.length; i++) { for (int i = 0; i < pairs.length; i++) {
originalPairIndices[pairs[i].left] = i; originalPairIndices[pairs[i].left] = i;
} }
@ -130,9 +53,7 @@ class _MatchingPairsQuestionState extends State<MatchingPairsQuestion> {
shuffledRightPairs = shuffledRightPairs =
List<String>.from(provider.shuffledRightPairsList[currentIndex]); List<String>.from(provider.shuffledRightPairsList[currentIndex]);
} else if (widget.exercise is ReviewExerciseDetail) { } else if (widget.exercise is ReviewExerciseDetail) {
// Mode Review
if (widget.exercise.matchingPairs != null) { if (widget.exercise.matchingPairs != null) {
// Gunakan data asli dari exercise untuk mempertahankan urutan
pairs = widget.exercise.matchingPairs!.map((reviewPair) { pairs = widget.exercise.matchingPairs!.map((reviewPair) {
return Pair( return Pair(
left: reviewPair.leftPair, left: reviewPair.leftPair,
@ -140,17 +61,13 @@ class _MatchingPairsQuestionState extends State<MatchingPairsQuestion> {
); );
}).toList(); }).toList();
// Simpan indeks asli untuk setiap pasangan
for (int i = 0; i < pairs.length; i++) { for (int i = 0; i < pairs.length; i++) {
originalPairIndices[pairs[i].left] = i; originalPairIndices[pairs[i].left] = i;
} }
// Use the original right pairs without shuffling
originalRightPairs = pairs.map((pair) => pair.right as String).toList(); originalRightPairs = pairs.map((pair) => pair.right as String).toList();
shuffledRightPairs = shuffledRightPairs = originalRightPairs.toList();
originalRightPairs.toList(); // No shuffling for review
// Rekonstruksi jawaban siswa
if (widget.exercise.answerStudent.isNotEmpty) { if (widget.exercise.answerStudent.isNotEmpty) {
final answerPairs = widget.exercise.answerStudent.split('|'); final answerPairs = widget.exercise.answerStudent.split('|');
for (var pair in answerPairs) { for (var pair in answerPairs) {
@ -163,7 +80,6 @@ class _MatchingPairsQuestionState extends State<MatchingPairsQuestion> {
} }
} }
// Bangun pemetaan konsisten
for (int i = 0; i < pairs.length; i++) { for (int i = 0; i < pairs.length; i++) {
final left = pairs[i].left; final left = pairs[i].left;
final right = pairs[i].right; final right = pairs[i].right;
@ -194,7 +110,6 @@ class _MatchingPairsQuestionState extends State<MatchingPairsQuestion> {
bool isActive = false; bool isActive = false;
Color? color; Color? color;
// Mencari indeks asli pasangan untuk warna yang konsisten
int originalPairIndex = -1; int originalPairIndex = -1;
if (isLeft) { if (isLeft) {
@ -202,9 +117,7 @@ class _MatchingPairsQuestionState extends State<MatchingPairsQuestion> {
pair is Pair ? pair.left == option : pair.leftPair == option); pair is Pair ? pair.left == option : pair.leftPair == option);
isActive = provider.activeLeftOption == option; isActive = provider.activeLeftOption == option;
} else { } else {
// Untuk right pair, cari berdasarkan pasangan yang sudah terbentuk
if (widget.isReview) { if (widget.isReview) {
// Untuk mode review, periksa apakah opsi ini ada di jawaban siswa
final matchedLeft = studentAnswers.keys.firstWhere( final matchedLeft = studentAnswers.keys.firstWhere(
(key) => studentAnswers[key] == option, (key) => studentAnswers[key] == option,
orElse: () => '', orElse: () => '',
@ -229,20 +142,17 @@ class _MatchingPairsQuestionState extends State<MatchingPairsQuestion> {
} }
} }
// Menentukan warna berdasarkan status
if (widget.isReview) { if (widget.isReview) {
if (isLeft) { if (isLeft) {
// Untuk left pair di mode review
final matchedRight = studentAnswers[option]; final matchedRight = studentAnswers[option];
if (matchedRight != null) { if (matchedRight != null) {
isSelected = true; isSelected = true;
// Cari indeks pasangan untuk warna yang konsisten
originalPairIndex = pairs.indexWhere( originalPairIndex = pairs.indexWhere(
(pair) => (pair is Pair ? pair.left : pair.leftPair) == option); (pair) => (pair is Pair ? pair.left : pair.leftPair) == option);
color = _getPairColor(originalPairIndex); color = _getPairColor(originalPairIndex);
} }
} else { } else {
// Untuk right pair di mode review
final matchedLeft = studentAnswers.keys.firstWhere( final matchedLeft = studentAnswers.keys.firstWhere(
(key) => studentAnswers[key] == option, (key) => studentAnswers[key] == option,
orElse: () => '', orElse: () => '',
@ -250,7 +160,7 @@ class _MatchingPairsQuestionState extends State<MatchingPairsQuestion> {
if (matchedLeft.isNotEmpty) { if (matchedLeft.isNotEmpty) {
isSelected = true; isSelected = true;
// Cari indeks pasangan untuk warna yang konsisten
originalPairIndex = pairs.indexWhere((pair) => originalPairIndex = pairs.indexWhere((pair) =>
(pair is Pair ? pair.left : pair.leftPair) == matchedLeft); (pair is Pair ? pair.left : pair.leftPair) == matchedLeft);
color = _getPairColor(originalPairIndex); color = _getPairColor(originalPairIndex);
@ -331,7 +241,7 @@ class _MatchingPairsQuestionState extends State<MatchingPairsQuestion> {
final int pairIndex = entry.key; final int pairIndex = entry.key;
final dynamic pair = entry.value; final dynamic pair = entry.value;
final String left = pair is Pair ? pair.left : pair.leftPair; final String left = pair is Pair ? pair.left : pair.leftPair;
// Menggunakan shuffledRightPairs untuk right pair
final String right = shuffledRightPairs[pairIndex]; final String right = shuffledRightPairs[pairIndex];
return Padding( return Padding(

View File

@ -45,9 +45,9 @@ class SeeProgressModal extends StatelessWidget {
), ),
const SizedBox(height: 20), const SizedBox(height: 20),
GridView.builder( GridView.builder(
shrinkWrap: true, // Important to wrap GridView inside a modal shrinkWrap: true,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 5, // Number of columns crossAxisCount: 5,
mainAxisSpacing: 10, mainAxisSpacing: 10,
crossAxisSpacing: 10, crossAxisSpacing: 10,
childAspectRatio: 1, childAspectRatio: 1,
@ -57,9 +57,8 @@ class SeeProgressModal extends StatelessWidget {
final isCompleted = exerciseProvider.isExerciseCompleted(index); final isCompleted = exerciseProvider.isExerciseCompleted(index);
return ElevatedButton( return ElevatedButton(
onPressed: () { onPressed: () {
Navigator.pop(context); // Close modal Navigator.pop(context);
exerciseProvider exerciseProvider.goToExercise(index);
.goToExercise(index); // Navigate to the selected exercise
}, },
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: backgroundColor:
@ -71,7 +70,7 @@ class SeeProgressModal extends StatelessWidget {
width: 1, width: 1,
), ),
), ),
elevation: 0, // Remove shadow elevation: 0,
padding: const EdgeInsets.all(0), padding: const EdgeInsets.all(0),
minimumSize: const Size(50, 50), minimumSize: const Size(50, 50),
), ),

View File

@ -48,7 +48,6 @@ class ResultScreen extends StatelessWidget {
); );
} }
// Menggunakan compareTo untuk membandingkan level
final currentLevelNum = _extractLevelNumber(currentLevel); final currentLevelNum = _extractLevelNumber(currentLevel);
final nextLevelNum = _extractLevelNumber(nextLevel); final nextLevelNum = _extractLevelNumber(nextLevel);