Line data Source code
1 : import 'package:amadeus_proto/constants.dart';
2 : import 'package:amadeus_proto/exercises/categories/reading/reading_provider.dart';
3 : import 'package:amadeus_proto/exercises/exercise_question.dart';
4 : import 'package:amadeus_proto/exercises/load_json.dart';
5 : import 'package:amadeus_proto/exercises/types/single_choice.dart';
6 : import 'package:amadeus_proto/exercises/widget/animation_dialog_wrapper.dart';
7 : import 'package:amadeus_proto/exercises/widget/exercise_header.dart';
8 : import 'package:amadeus_proto/exercises/widget/exercises_end_dialog.dart';
9 : import 'package:amadeus_proto/api/models/exercise_info.dart';
10 : import 'package:amadeus_proto/widget/progress_bar.dart';
11 : import 'package:flutter/material.dart';
12 : import 'package:provider/provider.dart';
13 :
14 : class AccidentalRecognitionPage extends StatefulWidget {
15 0 : const AccidentalRecognitionPage({super.key, required this.info});
16 :
17 : final ExerciseInfo info;
18 :
19 0 : @override
20 : State<AccidentalRecognitionPage> createState() =>
21 0 : _AccidentalRecognitionPageState();
22 : }
23 :
24 : class _AccidentalRecognitionPageState extends State<AccidentalRecognitionPage> {
25 : final String filepath = "assets/FigmaDesign/Asset/Partition/reading.xml";
26 :
27 0 : @override
28 : void initState() {
29 0 : super.initState();
30 0 : WidgetsBinding.instance.addPostFrameCallback((_) {
31 0 : context.read<ReadingProvider>().reset();
32 : });
33 : }
34 :
35 : /// The implementation of [AccidentalRecognitionPage.build]
36 : ///
37 : /// The build is composed by a FutureBuilder that will wait for the data
38 : /// from the [loadJsonData] asynchronous function to collect the data
39 : /// from the specific JSON file
40 : ///
41 : /// This widget display an reading exercise with a header [ExerciseHeader],
42 : /// a description [ExerciseDescription], an image that correspond to the
43 : /// actual question, and finally a [SingleChoiceExercise] with multiples
44 : /// choices.
45 : /// All those is data, is initialize by the corresponding JSON file and is
46 : /// load by the corresponding [ExerciseProvider], in this case, the provider
47 : /// is [ReadingProvider]
48 0 : @override
49 : Widget build(BuildContext context) {
50 0 : final ReadingProvider reading = context.watch<ReadingProvider>();
51 :
52 0 : WidgetsBinding.instance.addPostFrameCallback((_) {
53 0 : if (!reading.isInitialized) {
54 0 : reading.initializeData(widget.info.exerciseData);
55 0 : reading.exerciseInfo = widget.info;
56 : }
57 0 : if (!reading.displayDialog && reading.checkEndGame()) {
58 0 : reading.displayDialog = true;
59 0 : Future.delayed(Duration.zero, () {
60 0 : if (!context.mounted) return;
61 0 : showGeneralDialog(
62 : context: context,
63 : transitionDuration: const Duration(milliseconds: fastAnimation),
64 0 : pageBuilder: (context, animation1, animation2) {
65 0 : return ExerciseEndDialog<ReadingProvider>(
66 0 : leavingExerciseCallback: () {
67 0 : Navigator.of(context).pop();
68 0 : Navigator.of(context).pop();
69 : },
70 0 : resetExerciseCallback: () {
71 0 : Navigator.of(context).pop();
72 0 : Future.delayed(const Duration(milliseconds: fastAnimation),
73 0 : () {
74 0 : if (mounted) {
75 0 : reading.reset();
76 : }
77 : });
78 : },
79 0 : exerciseTitle: widget.info.exerciseData!["title"],
80 0 : exerciseCategory: widget.info.exerciseData!["category"],
81 : );
82 : },
83 : transitionBuilder:
84 0 : (context, animation, secondaryAnimation, child) {
85 0 : return ScaleTransition(
86 : scale: animation,
87 0 : child: AnimatedDialogWrapper(
88 : animation: animation,
89 : child: child,
90 : ),
91 : );
92 : });
93 : });
94 : }
95 : });
96 :
97 0 : return Scaffold(
98 : // backgroundColor: Colors.white,
99 0 : body: SafeArea(
100 0 : child: Column(children: [
101 0 : if (reading.isInitialized) const ExerciseHeader<ReadingProvider>(),
102 0 : const SizedBox(
103 : height: 10,
104 : ),
105 0 : if (reading.isInitialized)
106 0 : ProgressBar(
107 0 : totalAmount: reading.questions.length,
108 0 : progressAmount: reading.progress,
109 : width: 300,
110 : height: 15),
111 0 : const SizedBox(
112 : height: 10,
113 : ),
114 0 : if (reading.isInitialized) const ExerciseQuestion<ReadingProvider>(),
115 0 : if (reading.isInitialized)
116 0 : Container(
117 : width: 350,
118 0 : decoration: BoxDecoration(
119 0 : color: Colors.grey.withOpacity(0.1),
120 0 : border: Border.all(
121 : width: 0.3,
122 0 : color: Colors.grey.shade500,
123 : ),
124 0 : borderRadius: BorderRadius.circular(smallBorderRadius)),
125 0 : child: Image(
126 0 : image: AssetImage(reading.questions[reading.answer]),
127 : width: imageAssetWidth,
128 : height: imageAssetHeight,
129 : )),
130 0 : const SizedBox(
131 : height: 35,
132 : ),
133 0 : if (reading.isInitialized)
134 0 : const Expanded(child: SingleChoiceExercise<ReadingProvider>()),
135 : ]),
136 : ),
137 : );
138 : }
139 : }
|