You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
223 lines
5.9 KiB
Dart
223 lines
5.9 KiB
Dart
import 'package:diplomaticquarterapp/models/course/education_journey_model.dart';
|
|
import 'package:diplomaticquarterapp/services/course_service/course_service.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
enum QuestionSheetAction { skip, rewatch }
|
|
|
|
class QuestionSheet extends StatefulWidget {
|
|
final Content content;
|
|
final Function(QuestionSheetAction) onActionSelected;
|
|
|
|
const QuestionSheet({Key? key, required this.content, required this.onActionSelected}) : super(key: key);
|
|
|
|
@override
|
|
_QuestionSheetState createState() => _QuestionSheetState();
|
|
}
|
|
|
|
class _QuestionSheetState extends State<QuestionSheet> {
|
|
int? selectedAnswerId;
|
|
Answer? selectedAnswer;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AnimatedPadding(
|
|
duration: Duration(milliseconds: 300),
|
|
padding: EdgeInsets.only(
|
|
bottom: MediaQuery.of(context).viewInsets.bottom,
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
SizedBox(height: 10),
|
|
_QuestionText(questionText: widget.content.question!.text!),
|
|
SizedBox(height: 20),
|
|
...widget.content.question!.answers!.map((answer) => _AnswerOption(
|
|
answer: answer,
|
|
isSelected: selectedAnswerId == answer.id,
|
|
onSelect: () {
|
|
if (selectedAnswer == null) {
|
|
setState(() {
|
|
selectedAnswerId = answer.id;
|
|
selectedAnswer = answer;
|
|
});
|
|
}
|
|
},
|
|
)),
|
|
SizedBox(height: 20),
|
|
if (selectedAnswer != null)
|
|
_AnswerDescription(
|
|
description: selectedAnswer!.description!,
|
|
isCorrect: selectedAnswer!.isCorrect!,
|
|
),
|
|
SizedBox(height: 20),
|
|
if (selectedAnswer != null)
|
|
_ActionButtons(
|
|
onSkip: () => widget.onActionSelected(QuestionSheetAction.skip),
|
|
onRewatch: () => widget.onActionSelected(QuestionSheetAction.rewatch),
|
|
),
|
|
SizedBox(height: 10),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _QuestionText extends StatelessWidget {
|
|
final String questionText;
|
|
|
|
const _QuestionText({Key? key, required this.questionText}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Text(
|
|
questionText,
|
|
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _AnswerOption extends StatelessWidget {
|
|
final Answer answer;
|
|
final bool isSelected;
|
|
final VoidCallback onSelect;
|
|
|
|
const _AnswerOption({
|
|
Key? key,
|
|
required this.answer,
|
|
required this.isSelected,
|
|
required this.onSelect,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AnimatedContainer(
|
|
width: double.infinity,
|
|
duration: Duration(milliseconds: 300),
|
|
margin: EdgeInsets.symmetric(vertical: 5),
|
|
decoration: BoxDecoration(
|
|
border: Border.all(
|
|
color: isSelected ? (answer.isCorrect! ? Colors.green : Color(0xFFD1272D)) : Colors.grey,
|
|
width: 2,
|
|
),
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: TextButton(
|
|
onPressed: onSelect,
|
|
child: Text(
|
|
answer.text!,
|
|
style: TextStyle(fontSize: 16),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _AnswerDescription extends StatelessWidget {
|
|
final String description;
|
|
final bool isCorrect;
|
|
|
|
const _AnswerDescription({
|
|
Key? key,
|
|
required this.description,
|
|
required this.isCorrect,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: Text(
|
|
description,
|
|
style: TextStyle(
|
|
color: isCorrect ? Colors.green : Color(0xFFD1272D),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _ActionButtons extends StatelessWidget {
|
|
final VoidCallback onSkip;
|
|
final VoidCallback onRewatch;
|
|
|
|
const _ActionButtons({
|
|
Key? key,
|
|
required this.onSkip,
|
|
required this.onRewatch,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
children: [
|
|
Expanded(
|
|
child: _ActionButton(
|
|
label: "SKIP",
|
|
onPressed: onSkip,
|
|
),
|
|
),
|
|
SizedBox(width: 20),
|
|
Expanded(
|
|
child: _ActionButton(
|
|
label: "RE-WATCH",
|
|
onPressed: onRewatch,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _ActionButton extends StatelessWidget {
|
|
final String label;
|
|
final VoidCallback onPressed;
|
|
|
|
const _ActionButton({
|
|
Key? key,
|
|
required this.label,
|
|
required this.onPressed,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AnimatedContainer(
|
|
width: double.infinity,
|
|
duration: Duration(milliseconds: 300),
|
|
margin: EdgeInsets.symmetric(vertical: 5),
|
|
decoration: BoxDecoration(
|
|
border: Border.all(color: Color(0xFFD1272D), width: 2),
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: TextButton(
|
|
onPressed: onPressed,
|
|
child: Text(
|
|
label,
|
|
style: TextStyle(fontSize: 16),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
// Modified showQuestionSheet function
|
|
Future<QuestionSheetAction?> showQuestionSheet(BuildContext con, {required Content content}) {
|
|
|
|
return showModalBottomSheet<QuestionSheetAction>(
|
|
context: con,
|
|
isDismissible: false,
|
|
isScrollControlled: true,
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(20))),
|
|
builder: (context) => QuestionSheet(
|
|
content: content,
|
|
onActionSelected: (action) {
|
|
Navigator.of(context).pop(action);
|
|
},
|
|
),
|
|
);
|
|
}
|