Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revamp: quiz list page #181

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,81 +1,183 @@
import 'package:bebras_pandai/models/quiz_participation.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:go_router/go_router.dart';
import 'package:intl/intl.dart';

import '../../../../../core/bases/widgets/atoms/button.dart';
import '../../../../../models/quiz_participation.dart';

class QuizCard extends StatelessWidget {
QuizCard(this.weeklyQuizParticipant, this.date, this.score, this.level);
// this.context);
const QuizCard(this.weeklyQuizParticipant, this.date, this.score, this.level,
this.maxAttempts, this.countAttempts, this.startAt, this.endAt,
{super.key});
// this.context);

final WeeklyQuizParticipation weeklyQuizParticipant;
final String date;
final DateTime? date;
final String score;
final String level;
final int maxAttempts;
final int countAttempts;
final DateTime startAt;
final DateTime endAt;

// final BuildContext context;

@override
Widget build(BuildContext context) {
final currentDate = DateTime.now();
final inDateRange =
currentDate.isAfter(startAt) && currentDate.isBefore(endAt);

return InkWell(
onTap: () async {
await context.push(
Uri(
path: '/quiz_start',
queryParameters: {
'quiz_participant_id': weeklyQuizParticipant.id,
},
).toString(),
);
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 18),
margin: const EdgeInsets.only(bottom: 12),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
margin: const EdgeInsets.only(bottom: 16),
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(
color: Colors.blue[50],
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.2),
spreadRadius: 1,
blurRadius: 4,
offset: const Offset(0, 2),
),
],
borderRadius: BorderRadius.circular(8),
),
child: Column(children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Container(
padding: const EdgeInsets.only(right: 20),
child: Text(
weeklyQuizParticipant.quiz_title,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 12),
child: Column(
children: [
Row(
children: [
Expanded(
flex: 7,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
weeklyQuizParticipant.quiz_title,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
),
),
const SizedBox(
height: 8,
),
Text(
'Nilai: $score',
style: const TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
const SizedBox(
height: 8,
),
Row(
children: [
const Icon(
FontAwesomeIcons.clock,
size: 12,
color: Colors.blueGrey,
),
const SizedBox(width: 4),
Text(
'Dikerjakan Pada: ${date != null ? DateFormat('dd/MM/yyyy HH:mm ').format(date!) : '-'}',
style: const TextStyle(
fontSize: 12,
color: Colors.blueGrey,
),
),
],
),
const SizedBox(height: 4),
Text(
'Sisa coba lagi: ${maxAttempts - countAttempts}/$maxAttempts',
style: const TextStyle(
fontSize: 12,
color: Color(0xFF1BB8E1),
),
),
],
),
),
),
Text(
'Nilai: $score',
style: const TextStyle(fontSize: 12),
)
],
),
const SizedBox(
height: 8,
),
Row(
children: [
Text(
'Kategori: $level',
style: const TextStyle(fontSize: 12),
)
],
Expanded(
flex: 3,
child: Button(
isDisabled: countAttempts > maxAttempts || !inDateRange,
onTap: () async {
await context.push(
Uri(
path: '/quiz_start',
queryParameters: {
'quiz_participant_id': weeklyQuizParticipant.id,
},
).toString(),
);
},
customButtonColor: const Color(0xFF1BB8E1),
customTextColor: Colors.white,
text: 'Kerjakan',
fontSize: 12,
innerVerticalPadding: 8,
innerHorizontalPadding: 8,
borderRadius: 4,
),
),
],
),
const SizedBox(
height: 8,
),
buildInfoWidget(startAt, endAt, currentDate)
],
),
),
);
}
}

Widget buildInfoWidget(DateTime startAt, DateTime endAt, DateTime currentDate) {
if (currentDate.isBefore(startAt)) {
return Row(
children: [
const Icon(
FontAwesomeIcons.circleInfo,
size: 12,
color: Color(0xFF1BB8E1),
),
const SizedBox(width: 4),
Text(
'Dapat mulai dikerjakan pada: ${DateFormat('dd/MM/yyyy HH:mm').format(startAt)}',
style: const TextStyle(
fontSize: 12,
color: Color(0xFF1BB8E1),
),
const SizedBox(
height: 8,
),
],
);
} else if (currentDate.isAfter(endAt)) {
return Row(
children: [
const Icon(
FontAwesomeIcons.circleInfo,
size: 12,
color: Color(0xFF1BB8E1),
),
const SizedBox(width: 4),
Text(
'Selesai pada: ${DateFormat('dd/MM/yyyy HH:mm').format(endAt)}',
style: const TextStyle(
fontSize: 12,
color: Color(0xFF1BB8E1),
),
Row(
children: [
Text(
'Dikerjakan: $date',
style: const TextStyle(fontSize: 12),
)
],
)
]),
),
),
],
);
} else {
return Container();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class _QuizDownloadPageState extends State<QuizDownloadPage> {
Align(
alignment: Alignment.centerLeft,
child: Text(
'Latihan yang pernah diikuti',
'Ayo kerjakan!',
style: FontTheme.blackSubtitleBold(),
),
),
Expand All @@ -173,12 +173,18 @@ class _QuizDownloadPageState extends State<QuizDownloadPage> {
.map((quiz) => QuizCard(
quiz,
quiz.attempts.isNotEmpty
? quiz.attempts[quiz.attempts.length - 1].startAt.toString()
: '-',
? DateTime.parse(quiz
.attempts[quiz.attempts.length - 1].startAt
.toString())
: null,
quiz.attempts.isNotEmpty
? quiz.attempts[quiz.attempts.length - 1].score.toString()
: '??',
quiz.challenge_group,
quiz.quiz_max_attempts,
quiz.attempts.length,
DateTime.parse(quiz.quiz_start_at),
DateTime.parse(quiz.quiz_end_at),
))
.toList(),
);
Expand Down
2 changes: 1 addition & 1 deletion app/lib/models/quiz_participation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class WeeklyQuizParticipation extends Equatable {
String id,
Map<String, dynamic> json,
) {
var attempts = json['attempts'];
final attempts = json['attempts'];
return WeeklyQuizParticipation(
id: id,
quiz_start_at: json['quiz_start_at'] as String,
Expand Down
Loading