Line data Source code
1 : import 'package:amadeus_proto/constants.dart';
2 : import 'package:amadeus_proto/exercises/end_dialog.dart';
3 : import 'package:amadeus_proto/exercises/lesson/lesson_page_provider.dart';
4 : import 'package:amadeus_proto/exercises/load_json.dart';
5 : import 'package:amadeus_proto/exercises/providers/single_choice_provider.dart';
6 : import 'package:amadeus_proto/exercises/widget/animation_dialog_wrapper.dart';
7 : import 'package:amadeus_proto/exercises/widget/exercises_end_dialog.dart';
8 : import 'package:amadeus_proto/exercises/widget/pressable_button.dart';
9 : import 'package:amadeus_proto/exercises/widget/previous_button.dart';
10 : import 'package:amadeus_proto/widget/progress_bar.dart';
11 : import 'package:flutter/material.dart';
12 : import 'package:provider/provider.dart';
13 : import 'package:simple_sheet_music/simple_sheet_music.dart';
14 :
15 : class ExerciseLessonPage extends StatefulWidget {
16 0 : const ExerciseLessonPage({super.key, required this.data});
17 :
18 : final dynamic data;
19 :
20 0 : @override
21 0 : State<ExerciseLessonPage> createState() => _ExerciseLessonPageState();
22 : }
23 :
24 : class _ExerciseLessonPageState extends State<ExerciseLessonPage> {
25 : bool quitLesson = false;
26 :
27 0 : @override
28 : void initState() {
29 0 : super.initState();
30 0 : WidgetsBinding.instance.addPostFrameCallback((_) {
31 0 : context.read<LessonProvider>().reset();
32 : });
33 : }
34 :
35 0 : @override
36 : Widget build(BuildContext context) {
37 0 : final LessonProvider provider = context.watch<LessonProvider>();
38 :
39 0 : WidgetsBinding.instance.addPostFrameCallback((_) async {
40 0 : if (!provider.isInitialized) {
41 0 : provider.initializeData(widget.data);
42 : }
43 : });
44 :
45 0 : if (quitLesson) {
46 0 : Future.delayed(Duration.zero, () {
47 0 : if (!context.mounted) return;
48 0 : showGeneralDialog(
49 : context: context,
50 : transitionDuration: const Duration(milliseconds: fastAnimation),
51 0 : pageBuilder: (context, animation1, animation2) {
52 0 : return EndDialog<LessonProvider>(
53 0 : leavingCallback: () {
54 : // provider.reset();
55 0 : Navigator.of(context).pop();
56 0 : Navigator.of(context).pop();
57 : },
58 0 : resetCallback: () {
59 0 : Navigator.of(context).pop();
60 0 : Future.delayed(const Duration(milliseconds: fastAnimation),
61 0 : () {
62 0 : if (mounted) {
63 0 : provider.reset();
64 0 : quitLesson = false;
65 : }
66 : });
67 : },
68 0 : title: provider.lessonTitle,
69 : );
70 : },
71 0 : transitionBuilder: (context, animation, secondaryAnimation, child) {
72 0 : return ScaleTransition(
73 : scale: animation,
74 0 : child: AnimatedDialogWrapper(
75 : animation: animation,
76 : child: child,
77 : ),
78 : );
79 : });
80 : });
81 : }
82 :
83 : // if (provider.isInitialized)
84 0 : return Scaffold(
85 0 : body: LayoutBuilder(
86 0 : builder: (context, constraints) => Container(
87 0 : decoration: BoxDecoration(border: Border.all()),
88 0 : child: (provider.isInitialized)
89 0 : ? Column(
90 0 : children: [
91 : const SizedBox(height: 35),
92 0 : Row(children: [
93 : const PreviousButton(),
94 0 : Text(
95 0 : provider.lessonTitle,
96 : style: const TextStyle(
97 : color: Colors.black,
98 : fontSize: largeTextSize,
99 : fontWeight: FontWeight.bold),
100 : ),
101 : ]),
102 : const SizedBox(
103 : height: 10,
104 : ),
105 0 : ProgressBar(
106 0 : totalAmount: provider.numberPages - 1,
107 0 : progressAmount: provider.index,
108 : width: 300,
109 : height: 15),
110 : const SizedBox(
111 : height: 10,
112 : ),
113 : const Spacer(),
114 0 : AnimatedSwitcher(
115 : duration: const Duration(milliseconds: fastAnimation),
116 0 : transitionBuilder: (child, animation) => FadeTransition(
117 : opacity: animation,
118 : child: child,
119 : ),
120 0 : child: Column(
121 0 : key: ValueKey<int>(provider.index),
122 : mainAxisAlignment: MainAxisAlignment.spaceBetween,
123 0 : children: [
124 0 : Container(
125 0 : width: constraints.maxWidth * 0.85,
126 0 : height: constraints.maxHeight * 0.2,
127 0 : decoration: BoxDecoration(
128 0 : color: Colors.grey.withOpacity(0.1),
129 0 : border: Border.all(
130 : width: 0.3,
131 0 : color: Colors.grey.shade500,
132 : ),
133 : borderRadius:
134 0 : BorderRadius.circular(smallBorderRadius)),
135 0 : child: Image(
136 0 : image: AssetImage(
137 0 : provider.lessonPageImage[provider.index])),
138 : ),
139 : const SizedBox(height: 50),
140 0 : Container(
141 : padding: const EdgeInsets.all(smallPadding),
142 0 : width: constraints.maxWidth * 0.85,
143 0 : height: constraints.maxHeight * 0.3,
144 0 : decoration: BoxDecoration(
145 0 : color: Colors.grey.withOpacity(0.1),
146 0 : border: Border.all(
147 : width: 0.3,
148 0 : color: Colors.grey.shade500,
149 : ),
150 : borderRadius:
151 0 : BorderRadius.circular(smallBorderRadius)),
152 0 : child: Column(
153 : crossAxisAlignment: CrossAxisAlignment.start,
154 : mainAxisAlignment: MainAxisAlignment.start,
155 0 : children: [
156 0 : Center(
157 0 : child: Text(
158 0 : provider.lessonPageTitle[provider.index],
159 : style: const TextStyle(
160 : fontSize: mediumTextSize,
161 : fontWeight: FontWeight.bold),
162 : )),
163 : const SizedBox(height: 10),
164 : const Divider(color: Colors.black),
165 : const SizedBox(height: 10),
166 0 : Expanded(
167 0 : child: SingleChildScrollView(
168 0 : child: Text(
169 : provider
170 0 : .lessonPageDescription[provider.index],
171 : style: const TextStyle(
172 : fontSize: smallTextSize),
173 : ),
174 : ),
175 : ),
176 : ],
177 : ),
178 : ),
179 : ],
180 : ),
181 : ),
182 : const Spacer(),
183 0 : Padding(
184 : padding:
185 : const EdgeInsets.symmetric(vertical: mediumPadding),
186 0 : child: Row(
187 : mainAxisAlignment: MainAxisAlignment.spaceAround,
188 0 : children: [
189 0 : PressableButton(
190 : body: const Center(
191 : child: Icon(
192 : Icons.arrow_circle_left,
193 : color: Colors.white,
194 : size: 35,
195 : )),
196 : height: 50,
197 0 : width: constraints.maxWidth * 0.4,
198 : shadowColor: Colors.white,
199 0 : buttonColor: Theme.of(context).colorScheme.primary,
200 0 : isEnable: !provider.isFirstPage(),
201 0 : onPressed: () => provider.index -=
202 0 : provider.isFirstPage() ? 0 : 1),
203 0 : PressableButton(
204 0 : body: Center(
205 0 : child: (provider.isLastPage())
206 : ? const Icon(
207 : Icons.check,
208 : color: Colors.white,
209 : size: 35,
210 : )
211 : : const Icon(
212 : Icons.arrow_circle_right,
213 : color: Colors.white,
214 : size: 35,
215 : )),
216 : height: 50,
217 0 : width: constraints.maxWidth * 0.4,
218 : shadowColor: Colors.white,
219 0 : buttonColor: provider.isLastPage()
220 : ? Colors.green
221 0 : : Theme.of(context).colorScheme.primary,
222 : isEnable: true,
223 0 : onPressed: () {
224 0 : setState(() {
225 0 : if (provider.isLastPage()) {
226 0 : quitLesson = true;
227 : return;
228 : }
229 : });
230 0 : provider.index += (provider.isLastPage()) ? 0 : 1;
231 : })
232 : ],
233 : ),
234 : )
235 : ],
236 : )
237 : : const Center(
238 : child: CircularProgressIndicator(),
239 : ),
240 : ),
241 : ));
242 : }
243 : }
|